Skip to content

Commit

Permalink
Use bun to build
Browse files Browse the repository at this point in the history
  • Loading branch information
artfuldev committed Oct 26, 2024
1 parent 4d97e45 commit ea6dce4
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
FROM node:20

# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:1 AS base
WORKDIR /usr/src/app
RUN npm install -g pnpm
COPY package.json pnpm-lock.yaml ./
RUN pnpm install

# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile

# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production

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

CMD ["pnpm", "--silent", "start"]
# [optional] tests & build
ENV NODE_ENV=production
RUN bun test
RUN bun build src/index.ts --target node --outdir dist

# copy production dependencies and source code into final image
FROM node:20 AS release
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /usr/src/app/dist dist
COPY --from=prerelease /usr/src/app/package.json .

# run the app
USER node
ENTRYPOINT [ "node", "dist/index.js" ]

0 comments on commit ea6dce4

Please sign in to comment.