From fc5b7f4a37b8bfc14c42abee9e1eee93373ecbab Mon Sep 17 00:00:00 2001 From: Enis Date: Thu, 3 Aug 2023 20:41:54 +0200 Subject: [PATCH] add github actions --- .github/workflows/docker.yml | 47 ++++++++++++++++++++++++++++++++++++ src/lib/server/fileUtil.ts | 13 +++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..3b39916 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,47 @@ +name: docker + +on: + push: + branches: + - 'main' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + docker: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - + name: Build and push + uses: docker/build-push-action@v4 + with: + context: "{{defaultContext}}" + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/src/lib/server/fileUtil.ts b/src/lib/server/fileUtil.ts index 585576d..d40069b 100644 --- a/src/lib/server/fileUtil.ts +++ b/src/lib/server/fileUtil.ts @@ -1,6 +1,12 @@ import { env } from "$env/dynamic/private"; import fs from "fs/promises"; +if(!(await fileExists(env.SECRET_DATA_PATH))) { + await fs.mkdir(env.SECRET_DATA_PATH, { + recursive: true, + }); +} + export async function storeObject(object: object, path: string) { await fs.writeFile(getDataFilePathFor(path), JSON.stringify(object, undefined, 2)); } @@ -12,7 +18,12 @@ export async function createEmptyJsonFileIfNotExists(path: string) { } export async function readJson(path: string) { - return JSON.parse((await fs.readFile(getDataFilePathFor(path))).toString()); + try { + return JSON.parse((await fs.readFile(getDataFilePathFor(path))).toString()); + } catch(e) { + console.warn(`${path} not found`); + return {}; + } } async function createEmptyJsonFile(path: string) {