|
| 1 | +# use the official Bun image |
| 2 | +# see all versions at https://hub.docker.com/r/oven/bun/tags |
| 3 | +# TODO: use alpine layer |
| 4 | +FROM oven/bun:1 as base |
| 5 | +WORKDIR /usr/src/app |
| 6 | + |
| 7 | +# 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? |
| 8 | +RUN apt-get update && apt-get install -y curl |
| 9 | + |
| 10 | +# install dependencies into temp directory |
| 11 | +# this will cache them and speed up future builds |
| 12 | +FROM base AS install |
| 13 | +RUN mkdir -p /temp/dev |
| 14 | +# COPY package.json bun.lockb /temp/dev/ # TODO: add bun.lockb back in |
| 15 | +COPY package.json /temp/dev/ |
| 16 | +COPY tsconfig.json /temp/dev/ |
| 17 | +COPY core/ /temp/dev/core/ |
| 18 | + |
| 19 | +RUN cd /temp/dev && bun install |
| 20 | + |
| 21 | +# install with --production (exclude devDependencies) |
| 22 | +RUN mkdir -p /temp/prod |
| 23 | +# COPY package.json bun.lockb /temp/prod/ |
| 24 | +COPY package.json /temp/prod/ |
| 25 | +COPY tsconfig.json /temp/prod/ |
| 26 | +COPY core/ /temp/prod/core/ |
| 27 | +RUN cd /temp/prod && bun install |
| 28 | +# RUN cd /temp/prod && bun install --production --frozen-lockfile |
| 29 | + |
| 30 | +# copy node_modules from temp directory |
| 31 | +# then copy all (non-ignored) project files into the image |
| 32 | +FROM base AS prerelease |
| 33 | +COPY --from=install /temp/dev/node_modules ./node_modules |
| 34 | +COPY . . |
| 35 | + |
| 36 | +# [optional] tests & build |
| 37 | +# ENV NODE_ENV=production |
| 38 | +# RUN bun test |
| 39 | +# RUN bun run build |
| 40 | + |
| 41 | +# copy production dependencies and source code into final image |
| 42 | +FROM base AS release |
| 43 | +COPY --from=install /temp/prod/node_modules ./node_modules |
| 44 | +COPY --from=prerelease /usr/src/app/app ./app |
| 45 | +COPY --from=prerelease /usr/src/app/config ./config |
| 46 | +COPY --from=prerelease /usr/src/app/core ./core |
| 47 | +COPY --from=prerelease /usr/src/app/docs ./docs |
| 48 | +COPY --from=prerelease /usr/src/app/routes ./routes |
| 49 | +COPY --from=prerelease /usr/src/app/storage ./storage |
| 50 | +COPY --from=prerelease /usr/src/app/index.ts ./index.ts |
| 51 | +COPY --from=prerelease /usr/src/app/tsconfig.json ./tsconfig.json |
| 52 | +COPY --from=prerelease /usr/src/app/package.json ./package.json |
| 53 | + |
| 54 | +# run the app |
| 55 | +USER bun |
| 56 | +EXPOSE 3000/tcp |
| 57 | +ENTRYPOINT [ "bun", "run", "index.ts" ] |
0 commit comments