Skip to content

Commit

Permalink
Merge pull request #5 from teknologi-umum/feat/better-dockerfile
Browse files Browse the repository at this point in the history
feat: better dockerfile
  • Loading branch information
elianiva authored Feb 3, 2024
2 parents 6cbbe6d + 48f6a28 commit 7c886ea
Showing 1 changed file with 6 additions and 32 deletions.
38 changes: 6 additions & 32 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:1.0.21 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
FROM oven/bun:1.0.25-debian
WORKDIR /app
RUN apt-get update && apt-get install -y curl wget
COPY . .

# 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/index.ts .
COPY --from=prerelease /usr/src/app/src src
COPY --from=prerelease /usr/src/app/package.json .

# run the app
USER bun
RUN bun install --frozen-lockfile --production
RUN bun build index.ts --compile --outfile=server
EXPOSE 3000/tcp
ENTRYPOINT [ "bun", "run", "index.ts" ]
ENTRYPOINT [ "bun", "run", "index.ts" ]

0 comments on commit 7c886ea

Please sign in to comment.