1
+ # syntax = docker/dockerfile:1
2
+
3
+ # Adjust BUN_VERSION as desired
4
+ ARG BUN_VERSION=1.1.20
5
+ FROM oven/bun:${BUN_VERSION}-slim as base
6
+
7
+ # Next.js app lives here
8
+ WORKDIR /app
9
+
10
+ # Set production environment
11
+ ENV NODE_ENV="production"
12
+
13
+ # Throw-away build stage to reduce size of final image
14
+ FROM base as build
15
+
16
+ # Install packages needed to build node modules
17
+ RUN apt-get update -qq && \
18
+ apt-get install --no-install-recommends -y build-essential pkg-config python-is-python3
19
+
20
+ # Mount the GH_NPM_TOKEN secret and use it to create bunfig.toml
21
+ RUN --mount=type=secret,id=GH_NPM_TOKEN \
22
+ echo '[install.scopes]' > bunfig.toml && \
23
+ echo 'neodyland = { token = "' $(cat /run/secrets/GH_NPM_TOKEN)'", url = "https://npm.pkg.github.com/" }' >> bunfig.toml
24
+
25
+ # Install node modules
26
+ COPY --link bun.lockb package.json ./
27
+ RUN bun install
28
+
29
+ # Copy application code
30
+ COPY --link . .
31
+
32
+ # Build application
33
+ RUN bun run build
34
+
35
+ # Remove development dependencies
36
+ RUN rm -rf node_modules && \
37
+ bun install --ci
38
+
39
+ # Remove bunfig.toml to avoid token leakage
40
+ RUN rm -f bunfig.toml
41
+
42
+ # Final stage for app image
43
+ FROM base
44
+
45
+ # Copy built application
46
+ COPY --from=build /app/.next/standalone /app
47
+ COPY --from=build /app/.next/static /app/.next/static
48
+ COPY --from=build /app/public /app/public
49
+
50
+ # Start the server by default, this can be overwritten at runtime
51
+ EXPOSE 3000
52
+ CMD [ "bun" , "server.js" ]
0 commit comments