Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
77b8e9e368 | |||
18eb34c1ea | |||
c683d5d254 | |||
1d9eb32901 | |||
f3a6a16a7b | |||
af7ae54128 | |||
da214bf8f9 | |||
07aabc16fc | |||
a9228fd09a | |||
5803981615 | |||
68f40fb0e5 | |||
2ab9e98751 | |||
d604f8d727 | |||
5d6af2aa21 | |||
d3387cbad1 | |||
42513e5f8b | |||
d2767ea436 | |||
6b1a3546a9 | |||
d1af6c4727 | |||
dd4210ae76 | |||
551c6e5246 | |||
14bfbc2d5c | |||
6f3f68d0a4 |
@ -6,15 +6,18 @@ on:
|
|||||||
branches: main
|
branches: main
|
||||||
jobs:
|
jobs:
|
||||||
validate:
|
validate:
|
||||||
|
name: Validate
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: read # Needed to clone the repository
|
contents: read # Needed to clone the repository
|
||||||
steps:
|
steps:
|
||||||
- name: Clone repository
|
- name: Clone repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install Deno
|
- name: Install Deno
|
||||||
uses: denoland/setup-deno@v1
|
uses: denoland/setup-deno@v1
|
||||||
with:
|
with:
|
||||||
deno-version: v1.x
|
deno-version: v1.x
|
||||||
|
|
||||||
- name: Check
|
- name: Check
|
||||||
run: "deno task check"
|
run: "deno task check"
|
||||||
|
@ -7,19 +7,31 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: read # Needed to clone the repository
|
contents: write
|
||||||
steps:
|
steps:
|
||||||
- name: Clone
|
- name: Clone
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Install Deno
|
- name: Install Deno
|
||||||
uses: denoland/setup-deno@v1
|
uses: denoland/setup-deno@v1
|
||||||
with:
|
with:
|
||||||
deno-version: v1.x
|
deno-version: v1.x
|
||||||
|
|
||||||
|
- name: Install Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: '>=1.20.1'
|
||||||
|
|
||||||
- name: Compile
|
- name: Compile
|
||||||
run: "deno task compile"
|
run: "deno task compile"
|
||||||
|
|
||||||
- name: Release
|
- name: Release
|
||||||
uses: ncipollo/release-action@v1
|
id: use-go-action
|
||||||
|
uses: "https://gitea.com/actions/release-action@main"
|
||||||
with:
|
with:
|
||||||
artifacts: "bunker"
|
files: "bunker"
|
||||||
|
api_key: '${{secrets.GITEA_TOKEN}}'
|
||||||
|
|
||||||
|
|
||||||
|
13
bunker.service
Normal file
13
bunker.service
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Bunker webservice
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=simone
|
||||||
|
ExecStart=/home/simone/bunker/bunker
|
||||||
|
WorkingDirectory=/home/simone/bunker/
|
||||||
|
Restart=on-failure
|
||||||
|
Environment="PORT=8200"
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
@ -6,7 +6,7 @@
|
|||||||
"tasks": {
|
"tasks": {
|
||||||
"check": "deno check main.ts",
|
"check": "deno check main.ts",
|
||||||
"dev": "deno run -A --unstable-ffi --env main.ts",
|
"dev": "deno run -A --unstable-ffi --env main.ts",
|
||||||
"compile": "deno compile --allow-net --allow-read --allow-env --allow-write --allow-ffi --allow-run --unstable-ffi --env main.ts",
|
"compile": "deno compile --allow-net --allow-read --allow-env --allow-write --allow-ffi --allow-run --unstable-ffi --output bunker --include 'https://deno.land/x/bcrypt@v0.4.1/src/worker.ts' main.ts",
|
||||||
"reset-db": "rm -rf bunker.db && sqlite3 bunker.db '.read database.sql'"
|
"reset-db": "rm -rf bunker.db && sqlite3 bunker.db '.read database.sql'"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
23
main.ts
23
main.ts
@ -1,7 +1,6 @@
|
|||||||
import * as sqlite from "jsr:@db/sqlite@0.11";
|
import * as sqlite from "jsr:@db/sqlite@0.11";
|
||||||
import * as oak from "jsr:@oak/oak@14";
|
import * as oak from "jsr:@oak/oak@14";
|
||||||
import * as bcrypt from "https://deno.land/x/bcrypt@v0.4.1/mod.ts";
|
import * as bcrypt from "https://deno.land/x/bcrypt@v0.4.1/mod.ts";
|
||||||
import * as _bcrypt_worker from "https://deno.land/x/bcrypt@v0.4.1/src/worker.ts";
|
|
||||||
|
|
||||||
type User = {
|
type User = {
|
||||||
id: number;
|
id: number;
|
||||||
@ -22,6 +21,28 @@ interface Db {
|
|||||||
createSession(init: Omit<Session, "id">): Promise<Session>;
|
createSession(init: Omit<Session, "id">): Promise<Session>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await Deno.lstat("bunker.db");
|
||||||
|
} catch (error) {
|
||||||
|
if (!(error instanceof Deno.errors.NotFound)) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
console.log("'bunker.db' not found, creating...");
|
||||||
|
const cmd = new Deno.Command("sqlite3", {
|
||||||
|
args: ["bunker.db", ".read database.sql"],
|
||||||
|
stdout: "piped",
|
||||||
|
stderr: "piped",
|
||||||
|
});
|
||||||
|
const cmdChild = cmd.spawn();
|
||||||
|
cmdChild.stdout.pipeTo(Deno.stdout.writable);
|
||||||
|
cmdChild.stderr.pipeTo(Deno.stderr.writable);
|
||||||
|
const status = await cmdChild.status;
|
||||||
|
if (!status.success) {
|
||||||
|
console.log("failed creating 'bunker.db', exiting...");
|
||||||
|
Deno.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class SqliteDb implements Db {
|
class SqliteDb implements Db {
|
||||||
private db = new sqlite.Database("bunker.db", { create: false });
|
private db = new sqlite.Database("bunker.db", { create: false });
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user