Skip to content

Commit

Permalink
Merge pull request #15 from tminaorg/bun-docker-distroless
Browse files Browse the repository at this point in the history
fix: Node lts slim and switch to tini
  • Loading branch information
aleksasiriski authored Nov 2, 2023
2 parents 60815e3 + 6553c46 commit a85840d
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# use dumb-init to add graceful shutdown
FROM building5/dumb-init:1.2.1 as init
# use tini to add graceful shutdown
FROM debian:stable-slim as init
RUN apt-get -qq update \
&& apt-get -qq install -y tini

# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
Expand All @@ -9,33 +11,32 @@ WORKDIR /usr/src/app
# use the official Node image until Bun fixes bug for static assets
# install dependencies into temp directory
# this will cache them and speed up future builds
FROM node:20.9.0-slim AS install
FROM node:lts-slim AS install
WORKDIR /usr/src/app
RUN mkdir -p /temp
COPY package.json package-lock.json /temp/
RUN cd /temp && npm ci

# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM base AS prerelease
FROM base AS build
COPY --from=install /temp/node_modules node_modules
COPY . .

# build
ENV NODE_ENV=production
RUN bun run build
RUN [ "bun", "run", "build" ]

# copy production dependencies and source code into final image
FROM base AS release
COPY --from=init /dumb-init /usr/local/bin/
COPY --from=prerelease /usr/src/app/node_modules node_modules
COPY --from=prerelease /usr/src/app/build ./
COPY --from=prerelease /usr/src/app/package.json ./

# switch to nonroot user
USER bun
COPY --from=init /usr/bin/tini /usr/bin/
COPY --from=build /usr/src/app/node_modules node_modules/
COPY --from=build /usr/src/app/build ./
COPY --from=build /usr/src/app/package.json ./

EXPOSE 3000

# run the app
ENTRYPOINT [ "/usr/local/bin/dumb-init", "--" ]
ENTRYPOINT [ "tini", "--" ]
CMD [ "bun", "run", "start" ]

0 comments on commit a85840d

Please sign in to comment.