|
1 |
| -# use the official Bun image |
2 |
| -# see all versions at https://hub.docker.com/r/oven/bun/tags |
3 |
| -FROM oven/bun:1.1.26-debian AS base |
| 1 | +# Build stage |
| 2 | +FROM oven/bun:1.1.27-debian AS builder |
4 | 3 | WORKDIR /usr/src
|
5 | 4 |
|
6 |
| -# Install curl - I wonder if there is a better way to do this, because it is only needed for the healthcheck — is wget installed by default? |
| 5 | +# Install curl and build dependencies if needed |
7 | 6 | USER root
|
8 |
| -RUN apt-get update && apt-get install -y curl |
9 |
| -USER bun |
10 |
| - |
11 |
| -# RUN apt-get update && apt-get install -y curl |
12 |
| - |
13 |
| -# [optional] tests & build |
14 |
| -# ENV NODE_ENV=production |
15 |
| -# RUN bun test |
16 |
| -# RUN bun run build |
| 7 | +RUN apt-get update && apt-get install -y --no-install-recommends curl && apt-get clean && rm -rf /var/lib/apt/lists/* |
17 | 8 |
|
18 |
| -# copy production dependencies and source code into final image |
19 |
| -FROM base AS release |
| 9 | +# Copy source files |
20 | 10 | COPY ./app ./app
|
21 | 11 | COPY ./config ./config
|
22 | 12 | COPY ./docs ./docs
|
23 | 13 | COPY ./dist ./dist
|
24 | 14 | COPY ./tsconfig.docker.json ./tsconfig.json
|
25 | 15 |
|
26 |
| -# Combine COPY and chown for storage |
27 |
| -RUN mkdir -p ./storage && chown -R bun:bun ./storage |
| 16 | +# [optional] Run tests and build |
| 17 | +# ENV NODE_ENV=production |
| 18 | +# RUN bun test |
| 19 | +# RUN bun run build |
| 20 | + |
| 21 | +# Final stage |
| 22 | +FROM oven/bun:1.1.27-debian AS release |
| 23 | +WORKDIR /usr/src |
| 24 | + |
| 25 | +# Copy built files from builder stage |
| 26 | +COPY --from=builder /usr/src/app ./app |
| 27 | +COPY --from=builder /usr/src/config ./config |
| 28 | +COPY --from=builder /usr/src/docs ./docs |
| 29 | +COPY --from=builder /usr/src/dist ./dist |
| 30 | +COPY --from=builder /usr/src/tsconfig.json ./tsconfig.json |
| 31 | + |
| 32 | +# Set up storage directory |
| 33 | +USER root |
| 34 | +RUN mkdir -p ./storage && chown -R bun:bun ./storage && apt-get update && apt-get install -y --no-install-recommends curl && apt-get clean && rm -rf /var/lib/apt/lists/* |
| 35 | + |
28 | 36 | COPY --chown=bun:bun ./storage ./storage
|
29 | 37 |
|
30 | 38 | # Add storage volume for logs and other files
|
31 | 39 | VOLUME ["/usr/src/storage"]
|
32 | 40 |
|
33 |
| -# run the app |
| 41 | +# Switch to non-root user |
34 | 42 | USER bun
|
| 43 | + |
| 44 | +# Expose port and set entrypoint |
35 | 45 | EXPOSE 3000/tcp
|
36 |
| -ENTRYPOINT [ "bun", "run", "dist/index.js" ] |
| 46 | +ENTRYPOINT ["bun", "run", "dist/index.js"] |
0 commit comments