From 22e66b7e0ff919e1e821495a367c903c1debb9d2 Mon Sep 17 00:00:00 2001 From: buttercat1791 Date: Thu, 27 Feb 2025 09:11:28 -0600 Subject: [PATCH] Fix dev Dockerfile for build and add instructions to README --- Dockerfile.dev | 26 +++++++++++--------------- README.md | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index 4acd1ee..dd5e013 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -2,20 +2,18 @@ # Based on the Bun Docker guide: https://bun.sh/guides/ecosystem/docker. # Use the official Bun image -FROM oven/bun:1 AS base +FROM oven/bun:1.2-alpine AS base WORKDIR /usr/src/app -# Install dependencies into temp directory. +# TODO: This expects the lockfile to already exist. +# It doesn't, so build it, and ensure it gets cached. + +# Install dependencies into a 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 package.json /temp/dev/ +RUN cd /temp/dev && bun install # Copy node_modules from temp directory. # Then copy all (non-ignored) project files into the image. @@ -23,21 +21,19 @@ FROM base AS prerelease COPY --from=install /temp/dev/node_modules node_modules COPY . . -# [Optional] Tests & build. +# Run tests and 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 test # Uncomment when tests are ready. 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 . +COPY --from=prerelease /usr/src/app/build . # Run the app. USER bun EXPOSE 3040/tcp -ENTRYPOINT [ "bun", "run", "index.ts" ] +ENTRYPOINT [ "bun", "run", "start" ] diff --git a/README.md b/README.md index 8a4e713..0d312cf 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,22 @@ CONTAINER ID IMAGE COMMAND CREATED STATUS 1d83d736322f gc-alexandria "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 0.0.0.0:4174->80/tcp, [::]:4174->80/tcp gc-alexandria ``` +## Docker + Bun + +This application is configured to use the Bun runtime. A Docker container is provided to handle builds and deployments. + +To build the app for development: +```bash +docker build -t next-alexandria -f Dockerfile.dev . +``` + +To run the development build: +```bash +docker run -d -p 3040:3040 next-alexandria +``` + + + ## Testing *These tests are under development, but will run. They will later be added to the container.*