forked from zasdaym/pph21
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from teknologi-umum/feat/better-dockerfile
feat: better dockerfile
- Loading branch information
Showing
1 changed file
with
6 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] |