···1+FROM oven/bun:1 AS base
2+WORKDIR /usr/src/app
3+4+# install dependencies into temp directory
5+# this will cache them and speed up future builds
6+FROM base AS install
7+RUN mkdir -p /temp/dev
8+COPY package.json bun.lock /temp/dev/
9+RUN cd /temp/dev && bun install --frozen-lockfile
10+11+# install with --production (exclude devDependencies)
12+RUN mkdir -p /temp/prod
13+COPY package.json bun.lock /temp/prod/
14+RUN cd /temp/prod && bun install --frozen-lockfile --production
15+16+# copy node_modules from temp directory
17+# then copy all (non-ignored) project files into the image
18+FROM base AS prerelease
19+COPY --from=install /temp/dev/node_modules node_modules
20+COPY . .
21+22+# copy production dependencies and source code into final image
23+FROM base AS release
24+COPY --from=install /temp/prod/node_modules node_modules
25+COPY --from=prerelease /usr/src/app/package.json .
26+COPY --from=prerelease /usr/src/app .
27+28+# run the app
29+USER bun
30+EXPOSE 4300/tcp
31+ENTRYPOINT [ "bun", "run", "prod" ]