Skip to content

Commit

Permalink
fix(docker): resolve issue with initiating the DB
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Goniszewski <robertgoniszewski@outlook.com>
  • Loading branch information
goniszewski committed Sep 20, 2024
1 parent 2dc34ff commit d900afb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
55 changes: 38 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,62 @@
FROM oven/bun AS base

LABEL maintainer="Grimoire Developers <contact@grimoire.pro>"
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" ]

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"]
2 changes: 1 addition & 1 deletion src/lib/database/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;');
}

Expand Down

0 comments on commit d900afb

Please sign in to comment.