Compare commits

...

23 Commits
v0.0.1 ... main

Author SHA1 Message Date
77b8e9e368 output sqlite3 2024-09-26 03:13:40 +02:00
18eb34c1ea dont commit build 2024-09-26 02:58:49 +02:00
c683d5d254 add on commit build 2024-09-26 02:55:03 +02:00
1d9eb32901 remove comment 2024-09-26 02:52:36 +02:00
f3a6a16a7b use gitea token 2024-09-26 02:43:09 +02:00
af7ae54128 add release token 2024-09-26 02:35:51 +02:00
da214bf8f9 add go version 2024-09-26 02:34:00 +02:00
07aabc16fc use go 2024-09-26 02:32:41 +02:00
a9228fd09a use gitea releaser 2024-09-26 02:30:41 +02:00
5803981615 use v3 2024-09-26 02:27:02 +02:00
68f40fb0e5 use tag 2024-09-26 02:22:30 +02:00
2ab9e98751 don't specify version 2024-09-26 02:19:26 +02:00
d604f8d727 use double quotes 2024-09-26 02:17:24 +02:00
5d6af2aa21 specify version 2024-09-26 02:15:06 +02:00
d3387cbad1 use gitea action 2024-09-26 02:13:20 +02:00
42513e5f8b fix maybe 2024-09-26 02:04:04 +02:00
d2767ea436 add test ls 2024-09-26 01:54:55 +02:00
6b1a3546a9 add test ls 2024-09-26 01:53:57 +02:00
d1af6c4727 breathe 2024-09-26 01:47:06 +02:00
dd4210ae76 add service 2024-09-26 01:43:05 +02:00
551c6e5246 manual port + cache 2024-09-26 01:41:32 +02:00
14bfbc2d5c auto make db 2024-09-26 01:35:13 +02:00
6f3f68d0a4 add write permissions 2024-09-26 01:27:11 +02:00
5 changed files with 54 additions and 5 deletions

@ -6,15 +6,18 @@ on:
branches: main
jobs:
validate:
name: Validate
runs-on: ubuntu-latest
permissions:
contents: read # Needed to clone the repository
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Install Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Check
run: "deno task check"

@ -7,19 +7,31 @@ jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read # Needed to clone the repository
contents: write
steps:
- name: Clone
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '>=1.20.1'
- name: Compile
run: "deno task compile"
- name: Release
uses: ncipollo/release-action@v1
id: use-go-action
uses: "https://gitea.com/actions/release-action@main"
with:
artifacts: "bunker"
files: "bunker"
api_key: '${{secrets.GITEA_TOKEN}}'

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": {
"check": "deno check 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'"
}
}

23
main.ts

@ -1,7 +1,6 @@
import * as sqlite from "jsr:@db/sqlite@0.11";
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_worker from "https://deno.land/x/bcrypt@v0.4.1/src/worker.ts";
type User = {
id: number;
@ -22,6 +21,28 @@ interface Db {
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 {
private db = new sqlite.Database("bunker.db", { create: false });