From d900afbac200ec82c7f9d8068e9c2f9b013d0411 Mon Sep 17 00:00:00 2001 From: Robert Goniszewski Date: Fri, 20 Sep 2024 22:41:07 +0200 Subject: [PATCH] fix(docker): resolve issue with initiating the DB Signed-off-by: Robert Goniszewski --- Dockerfile | 55 +++++++++++++++++++++++++++++------------- src/lib/database/db.ts | 2 +- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index ff3c961..46f0b0a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,41 +1,62 @@ FROM oven/bun AS base + +LABEL maintainer="Grimoire Developers " +LABEL version="0.4.0" +LABEL description="Bookmark manager for the wizards" +LABEL org.opencontainers.image.source="https://github.com/goniszewski/grimoire" + RUN apt-get update && apt-get install -y python3 python3-pip wget build-essential && rm -rf /var/lib/apt/lists/* RUN bun i -g svelte-kit@latest + +RUN adduser --disabled-password --gecos '' grimoire +USER root +RUN mkdir -p /app/data && chown -R grimoire:grimoire /app/data && chmod 755 /app/data +USER grimoire WORKDIR /app FROM base AS install +USER grimoire WORKDIR /temp/dev -COPY package.json bun.lockb ./ +COPY --chown=grimoire:grimoire package.json bun.lockb ./ RUN bun install --frozen-lockfile WORKDIR /temp/prod -COPY package.json bun.lockb ./ +USER grimoire +COPY --chown=grimoire:grimoire package.json bun.lockb ./ RUN bun install --frozen-lockfile --production FROM base AS prerelease -COPY --from=install /temp/dev/node_modules node_modules -COPY . . +USER root +COPY --from=install --chown=grimoire:grimoire /temp/dev/node_modules node_modules +COPY --chown=grimoire:grimoire . . + +RUN chown -R grimoire:grimoire /app +USER grimoire + +RUN bun run svelte-kit sync ARG PUBLIC_ORIGIN="http://localhost:5173" ARG PORT=5173 ARG PUBLIC_HTTPS_ONLY="false" ARG PUBLIC_SIGNUP_DISABLED="false" ARG BODY_SIZE_LIMIT="5000000" -ENV NODE_ENV=production -ENV NODE_OPTIONS=--max-old-space-size=8192 +ENV NODE_ENV=production \ + NODE_OPTIONS="--max-old-space-size=4096" RUN bun --bun run build -ENV PUBLIC_ORIGIN=$PUBLIC_ORIGIN -ENV ORIGIN=$PUBLIC_ORIGIN -ENV PORT=$PORT -ENV PUBLIC_HTTPS_ONLY=$PUBLIC_HTTPS_ONLY -ENV PUBLIC_SIGNUP_DISABLED=$PUBLIC_SIGNUP_DISABLED -ENV BODY_SIZE_LIMIT=$BODY_SIZE_LIMIT +ENV PUBLIC_ORIGIN=${PUBLIC_ORIGIN:-http://localhost:5173} \ + ORIGIN=${PUBLIC_ORIGIN:-http://localhost:5173} \ + PORT=${PORT:-5173} \ + PUBLIC_HTTPS_ONLY={$PUBLIC_HTTPS_ONLY:-false} \ + PUBLIC_SIGNUP_DISABLED=${PUBLIC_SIGNUP_DISABLED:-false} \ + BODY_SIZE_LIMIT=${BODY_SIZE_LIMIT:-5000000} FROM base AS release -COPY --from=install /temp/prod/node_modules node_modules -COPY --from=prerelease /app . -RUN bun --bun run run-migrations +USER grimoire +COPY --from=install --chown=grimoire:grimoire /temp/prod/node_modules node_modules +COPY --from=prerelease --chown=grimoire:grimoire /app . ENV NODE_ENV=production -EXPOSE $PORT -ENTRYPOINT [ "bun","./build/index.js" ] \ No newline at end of file + +EXPOSE ${PORT} +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD wget --no-verbose --tries=1 --spider http://localhost:$PORT/api/health || exit 1 +ENTRYPOINT ["sh", "-c", "bun --bun run run-migrations && bun ./build/index.js"] \ No newline at end of file diff --git a/src/lib/database/db.ts b/src/lib/database/db.ts index 319a1b4..22591d1 100644 --- a/src/lib/database/db.ts +++ b/src/lib/database/db.ts @@ -11,7 +11,7 @@ class DbConnection { private db: Database; private constructor() { - this.db = new Database('data/db.sqlite', { create: true }); + this.db = new Database('/app/data/db.sqlite', { create: true }); this.db.exec('PRAGMA journal_mode = WAL;'); }