Skip to content

Instantly share code, notes, and snippets.

@yaikohi
Created January 30, 2024 11:48
Show Gist options
  • Save yaikohi/1d1f94a343d71857e0f73ef4a23dd071 to your computer and use it in GitHub Desktop.
Save yaikohi/1d1f94a343d71857e0f73ef4a23dd071 to your computer and use it in GitHub Desktop.
Dockerfile template - Solidstart / Vinxi on Bun
# 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
# 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 . .
# [optional] tests & build
ENV NODE_ENV=production
ENV SERVER_PRESET=bun
RUN bun test
RUN bun run build
# copy production dependencies and source code into final image
FROM base AS release
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /usr/src/app/bun.lockb .
COPY --from=prerelease /usr/src/app/package.json .
COPY --from=prerelease /usr/src/app/.vinxi .vinxi
COPY --from=prerelease /usr/src/app/.output .output
# run the app
USER bun
EXPOSE 3000/tcp
ENTRYPOINT [ "bun", "run", "start" ]
@yaikohi
Copy link
Author

yaikohi commented Jan 30, 2024

Mainly taken from the bun documentation site. I just debugged the files required in the production build. Feedback is more than welcome.

Sources

  1. bun docs - Containerize a Bun application with Docker
  2. solidstart docs - vinxi start
  3. vinxi docs - deployment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment