about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2024-04-04 17:16:47 +0200
committerAlan Pearce2024-04-04 17:16:47 +0200
commite4f8b2814a638d74faac47158c0e48a8760bc8b6 (patch)
tree75fff7b6edd0a902f8821303bae93c8a6d791af8
parent925cb99fafa4f457e799a871bf8878c841c1918d (diff)
downloadwebsite-e4f8b2814a638d74faac47158c0e48a8760bc8b6.tar.lz
website-e4f8b2814a638d74faac47158c0e48a8760bc8b6.tar.zst
website-e4f8b2814a638d74faac47158c0e48a8760bc8b6.zip
Docker: Follow bun best practices
-rw-r--r--Dockerfile28
1 files changed, 12 insertions, 16 deletions
diff --git a/Dockerfile b/Dockerfile
index 3ec8e2c..a56ca7b 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,26 +2,23 @@
 
 # Adjust BUN_VERSION as desired
 ARG BUN_VERSION=1.0.36
-FROM oven/bun:${BUN_VERSION} as base
+FROM docker.io/oven/bun:${BUN_VERSION} as base
 
 LABEL fly_launch_runtime="Bun"
 
-# Bun app lives here
 WORKDIR /app
 
-# Set production environment
-ENV NODE_ENV="production"
+FROM base as install
+RUN mkdir -p /temp/dev
+COPY --link bun.lockb package.json /temp/dev/
+RUN cd /temp/dev && bun install --frozen-lockfile
 
-# Throw-away build stage to reduce size of final image
-FROM base as build
-
-# # Install packages needed to build node modules
-# RUN apt-get update -qq && \
-#     apt-get install -y build-essential pkg-config python-is-python3
+RUN mkdir -p /temp/prod
+COPY --link bun.lockb package.json /temp/prod/
+RUN cd /temp/prod && bun install --frozen-lockfile --production
 
-# Install node modules
-COPY --link bun.lockb package.json ./
-RUN bun install --ci
+FROM base as build
+COPY --from=install /temp/dev/node_modules node_modules
 
 # Copy application code
 COPY --link config.toml config.toml
@@ -31,10 +28,8 @@ COPY --link content content
 COPY --link templates templates
 COPY --link static static
 
-RUN ./bin/build.ts && rm -r node_modules
-
 ENV NODE_ENV=production
-RUN [ "bun", "install", "--production", "--ci" ]
+RUN bun run bin/build.ts
 
 FROM alpine:20240329 as postprocess
 
@@ -56,6 +51,7 @@ FROM base
 
 # Copy built application
 COPY config.toml /app/
+COPY --from=install /temp/prod/node_modules node_modules
 COPY --from=build /app /app
 COPY --from=postprocess /app/public /app/