Browse Source

Fix dev Dockerfile for build and add instructions to README

master
buttercat1791 1 year ago
parent
commit
22e66b7e0f
  1. 26
      Dockerfile.dev
  2. 16
      README.md

26
Dockerfile.dev

@ -2,20 +2,18 @@
# Based on the Bun Docker guide: https://bun.sh/guides/ecosystem/docker. # Based on the Bun Docker guide: https://bun.sh/guides/ecosystem/docker.
# Use the official Bun image # Use the official Bun image
FROM oven/bun:1 AS base FROM oven/bun:1.2-alpine AS base
WORKDIR /usr/src/app 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. # This will cache them and speed up future builds.
FROM base AS install FROM base AS install
RUN mkdir -p /temp/dev RUN mkdir -p /temp/dev
COPY package.json bun.lock /temp/dev/ COPY package.json /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile RUN cd /temp/dev && bun install
# 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. # Copy node_modules from temp directory.
# Then copy all (non-ignored) project files into the image. # 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 --from=install /temp/dev/node_modules node_modules
COPY . . COPY . .
# [Optional] Tests & build. # Run tests and build.
ENV NODE_ENV=development ENV NODE_ENV=development
ENV ALEX_HOST=127.0.0.1 ENV ALEX_HOST=127.0.0.1
ENV ALEX_PORT=3040 ENV ALEX_PORT=3040
ENV ALEX_ORIGIN=https://next-alexandria.gitcitadel.eu ENV ALEX_ORIGIN=https://next-alexandria.gitcitadel.eu
RUN bun test # RUN bun test # Uncomment when tests are ready.
RUN bun run build RUN bun run build
# Copy production dependencies and source code into final image. # Copy production dependencies and source code into final image.
FROM base AS release FROM base AS release
COPY --from=install /temp/prod/node_modules node_modules COPY --from=prerelease /usr/src/app/build .
COPY --from=prerelease /usr/src/app/index.ts .
COPY --from=prerelease /usr/src/app/package.json .
# Run the app. # Run the app.
USER bun USER bun
EXPOSE 3040/tcp EXPOSE 3040/tcp
ENTRYPOINT [ "bun", "run", "index.ts" ] ENTRYPOINT [ "bun", "run", "start" ]

16
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 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
```
<!-- TODO: Add a production build and deployment. -->
## Testing ## Testing
*These tests are under development, but will run. They will later be added to the container.* *These tests are under development, but will run. They will later be added to the container.*

Loading…
Cancel
Save