Skip to content

Commit

Permalink
ci(server): fix Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
sripwoud committed Oct 7, 2024
1 parent 80c4254 commit 23b0b2c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 29 deletions.
48 changes: 21 additions & 27 deletions apps/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
FROM oven/bun:1 AS base
# FIXME: remapping of ts aliases does not work with bun + nestjs
FROM node:20-alpine as base
WORKDIR /app
COPY package.json .
COPY apps/server/package.json apps/server/
RUN apk update &&\
apk upgrade &&\
apk add --no-cache bash dumb-init &&\
apk cache clean && set -x

FROM base as install
RUN mkdir -p /temp/dev && mkdir /temp/prod

COPY *.json /temp/dev/
COPY apps/server/*.json /temp/dev/apps/server/

COPY *.json /temp/prod/
COPY apps/server/*.json /temp/prod/apps/server/

RUN cd /temp/dev &&\
bun i &&\
cd /temp/prod &&\
bun i --production
COPY package.json yarn.lock ./
COPY apps/server/package.json apps/server/
RUN yarn install --ignore-scripts --frozen-lockfile --production=false

FROM base as prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY --from=install /temp/dev/apps/server/node_modules apps/server/node_modules
FROM install as prerelease
COPY tsconfig.json .
COPY apps/server/tsconfig.* apps/server/
COPY apps/server/tsconfig* apps/server/nest-cli.json apps/server/
COPY apps/server/src apps/server/src

ENV NODE_ENV=production
RUN bun --filter server build
RUN yarn workspace server build &&\
find -type d -name node_modules -exec rm -fr {} + &&\
yarn install --frozen-lockfile --production=true

FROM base as release
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /app/apps/server/dist apps/server/dist

USER bun
COPY --from=prerelease /app/apps/server/node_modules node_modules
COPY --from=prerelease /app/apps/server/dist dist
ENV NODE_ENV production
USER node
EXPOSE 3001
ENTRYPOINT ["bun", "--filter", "server", "start"]
RUN set -x && pwd && cat dist/index.js
ENTRYPOINT ["dumb-init", "--"]
CMD ["node", "dist"]
2 changes: 1 addition & 1 deletion apps/server/nest-cli.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"entryFile": "index",
"compilerOptions": {
"deleteOutDir": true
}
Expand Down
3 changes: 2 additions & 1 deletion apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
"typescript": "^5.1.3",
"webpack": "^5.0.0"
}
}
File renamed without changes.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"private": true,
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"barrelsby": "^2.8.1",
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4704,6 +4704,7 @@ serve-static@1.16.2:
ts-node "^10.9.1"
tsconfig-paths "^4.2.0"
typescript "^5.1.3"
webpack "^5.0.0"
dependencies:
"@nestjs/common" "^10.0.0"
"@nestjs/core" "^10.0.0"
Expand Down

0 comments on commit 23b0b2c

Please sign in to comment.