Skip to content

Instantly share code, notes, and snippets.

@K-Mistele
Created March 31, 2025 22:27
Show Gist options
  • Save K-Mistele/c51057c5ac6d857d37c169fa7091cd61 to your computer and use it in GitHub Desktop.
Save K-Mistele/c51057c5ac6d857d37c169fa7091cd61 to your computer and use it in GitHub Desktop.
Dockerfile for a single package/service in a bun monorepo
FROM oven/bun:latest AS base
WORKDIR /usr/src/app
# install dependencies into a temporary directory to cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY . /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile --filter ./services/agent-executor
# install with --production to exclude dev dependencies
RUN mkdir -p /temp/prod
COPY . /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production --filter ./services/agent-executor
# 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 . .
# variables; if we're running tests and build scripts it should be here
ENV NODE_ENV=production
# copy production dependencies and source code into the final image
FROM base AS release
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /usr/src/app .
COPY --from=prerelease /usr/src/app/package.json .
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && apt install -y curl && rm -rf /var/lib/apt/lists/*
# run the app
USER bun
ENV PORT=4042
EXPOSE $PORT/tcp
CMD ["bun", "run", "/usr/src/app/services/agent-executor/src/app.ts"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment