40 lines
1.2 KiB
Docker
40 lines
1.2 KiB
Docker
# 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/app
|
|
|
|
# install dependencies into temp directory
|
|
# this will cache them and speed up future builds
|
|
FROM base AS install
|
|
RUN mkdir -p /tmp/dev
|
|
COPY package.json bun.lockb /tmp/dev/
|
|
RUN cd /tmp/dev && bun install --frozen-lockfile
|
|
|
|
# install with --production (exclude devDependencies)
|
|
RUN mkdir -p /tmp/prod
|
|
COPY package.json bun.lockb /tmp/prod/
|
|
RUN cd /tmp/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 /tmp/dev/node_modules node_modules
|
|
COPY . .
|
|
|
|
# [optional] tests & build
|
|
ENV NODE_ENV=production
|
|
RUN bun test
|
|
RUN bun build --compile src/index.ts --outfile=aniplay
|
|
|
|
# copy production dependencies and source code into final image
|
|
FROM base AS release
|
|
COPY --from=install /tmp/prod/node_modules node_modules
|
|
COPY --from=prerelease /usr/app/src ./src
|
|
COPY --from=prerelease /usr/app/package.json .
|
|
COPY --from=prerelease /usr/app/tsconfig.json .
|
|
COPY --from=prerelease /usr/app/drizzle.config.ts .
|
|
|
|
# run the app
|
|
USER bun
|
|
EXPOSE 3000
|
|
ENTRYPOINT [ "bun", "run", "prod:server" ] |