From ea1ba60770d3104f140ab532b814a4e52fcdf247 Mon Sep 17 00:00:00 2001 From: buttercat1791 Date: Wed, 26 Feb 2025 09:32:05 -0600 Subject: [PATCH] Add dev Dockerfile and move env vars into Docker containers --- .env | 3 --- .env.development | 4 ---- .env.local | 3 --- .gitignore | 2 ++ Dockerfile.dev | 43 +++++++++++++++++++++++++++++++++++++++++++ Dockerfile.prod | 3 +++ 6 files changed, 48 insertions(+), 10 deletions(-) delete mode 100644 .env delete mode 100644 .env.development delete mode 100644 .env.local create mode 100644 Dockerfile.dev diff --git a/.env b/.env deleted file mode 100644 index 26c86f1..0000000 --- a/.env +++ /dev/null @@ -1,3 +0,0 @@ -ALEX_HOST=127.0.0.1 -ALEX_PORT=3040 -ALEX_ORIGIN=https://alexandria.gitcitadel.eu \ No newline at end of file diff --git a/.env.development b/.env.development deleted file mode 100644 index 8475b6e..0000000 --- a/.env.development +++ /dev/null @@ -1,4 +0,0 @@ -ALEX_HOST=127.0.0.1 -ALEX_PORT=3040 -ALEX_ORIGIN=https://next-alexandria.gitcitadel.eu - diff --git a/.env.local b/.env.local deleted file mode 100644 index 49d16d5..0000000 --- a/.env.local +++ /dev/null @@ -1,3 +0,0 @@ -ALEX_HOST=127.0.0.1 -ALEX_PORT=3040 -ALEX_ORIGIN=http://localhost:3040 \ No newline at end of file diff --git a/.gitignore b/.gitignore index bbef319..5da1c08 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ node_modules /build /.svelte-kit /package +.env +.env.* !.env.example vite.config.js.timestamp-* vite.config.ts.timestamp-* diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..4acd1ee --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,43 @@ +# Dockerfile for production deployments of Alexandria. +# Based on the Bun Docker guide: https://bun.sh/guides/ecosystem/docker. + +# Use the official Bun image +FROM oven/bun:1 AS base +WORKDIR /usr/src/app + +# Install dependencies into temp directory. +# This will cache them and speed up future builds. +FROM base AS install +RUN mkdir -p /temp/dev +COPY package.json bun.lock /temp/dev/ +RUN cd /temp/dev && bun install --frozen-lockfile + +# Install with --production (exclude devDependencies) +RUN mkdir -p /temp/prod +COPY package.json bun.lock /temp/prod/ +RUN cd /temp/prod && bun install --frozen-lockfile --production + +# Copy node_modules from temp directory. +# Then copy all (non-ignored) project files into the image. +FROM base AS prerelease +COPY --from=install /temp/dev/node_modules node_modules +COPY . . + +# [Optional] Tests & build. +ENV NODE_ENV=development +ENV ALEX_HOST=127.0.0.1 +ENV ALEX_PORT=3040 +ENV ALEX_ORIGIN=https://next-alexandria.gitcitadel.eu +RUN bun test +RUN bun run build + +# Copy production dependencies and source code into final image. +FROM base AS release +COPY --from=install /temp/prod/node_modules node_modules +COPY --from=prerelease /usr/src/app/index.ts . +COPY --from=prerelease /usr/src/app/package.json . + +# Run the app. +USER bun +EXPOSE 3040/tcp +ENTRYPOINT [ "bun", "run", "index.ts" ] diff --git a/Dockerfile.prod b/Dockerfile.prod index 78d7642..cbfc639 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -25,6 +25,9 @@ COPY . . # [Optional] Tests & build. ENV NODE_ENV=production +ENV ALEX_HOST=127.0.0.1 +ENV ALEX_PORT=3040 +ENV ALEX_ORIGIN=https://alexandria.gitcitadel.eu RUN bun test RUN bun run build