-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] |