From d0da7cead5732346d95aa11443d861ce83f108b4 Mon Sep 17 00:00:00 2001 From: Emnaghz Date: Fri, 27 Sep 2024 11:22:18 +0100 Subject: [PATCH 1/3] fix: add production target to api --- .github/workflows/docker.yml | 1 + api/Dockerfile | 38 ++++++++++++++++++++++++----------- docker/docker-compose.dev.yml | 1 + 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 9323e6e6..6eb1defe 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -65,6 +65,7 @@ jobs: uses: docker/build-push-action@v6 with: context: ./api/ + target: production file: ./api/Dockerfile platforms: linux/amd64,linux/arm64 push: true diff --git a/api/Dockerfile b/api/Dockerfile index 7e90a7a4..a8a9f544 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -4,32 +4,46 @@ WORKDIR /app COPY . . -FROM node:18-alpine AS installer +RUN npm update -g npm + +RUN npm config set registry https://registry.npmjs.com/ + +RUN npm run preinstall + +RUN npm i --verbose --maxsockets 6 + +RUN npm run build + + +FROM node:18-alpine AS production WORKDIR /app COPY --from=builder /app/package*.json ./ +COPY --from=builder /app/ . +COPY --from=builder /app/node_modules ./node_modules -COPY --from=builder /app/merge-extensions-deps.js ./ - -COPY --from=builder /app/src/extensions ./src/extensions +ENV NODE_ENV=production -COPY --from=builder /app/patches ./patches +# Run npm prune to remove dev dependencies +RUN npm prune --production -RUN npm update -g npm +EXPOSE 3000 -RUN npm config set registry https://registry.npmjs.com/ +CMD ["npm", "run", "start:prod"] -RUN npm i --verbose --maxsockets 6 -FROM node:18-alpine AS runner +FROM node:18-alpine AS development WORKDIR /app -COPY --from=installer /app/ . +COPY --from=builder /app/package*.json ./ +COPY --from=builder /app/ . + +ENV NODE_ENV=development -COPY . . +RUN npm install EXPOSE 3000 -CMD [ "npm", "run" , "start:dev" ] +CMD ["npm", "run", "start:dev"] diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml index 98c7912e..2bad0cf5 100644 --- a/docker/docker-compose.dev.yml +++ b/docker/docker-compose.dev.yml @@ -13,6 +13,7 @@ services: api: build: context: ../api + target: development pull_policy: build ports: - ${API_PORT}:3000 From 823a2f5332b5ee84e9da631b5014a447819290f2 Mon Sep 17 00:00:00 2001 From: Emnaghz Date: Fri, 27 Sep 2024 23:57:15 +0100 Subject: [PATCH 2/3] fix: add few changes --- api/Dockerfile | 20 ++++++++++---------- docker/docker-compose.dev.yml | 1 - 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/api/Dockerfile b/api/Dockerfile index a8a9f544..ba71e9f5 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -15,35 +15,35 @@ RUN npm i --verbose --maxsockets 6 RUN npm run build -FROM node:18-alpine AS production +FROM node:18-alpine AS development WORKDIR /app COPY --from=builder /app/package*.json ./ COPY --from=builder /app/ . -COPY --from=builder /app/node_modules ./node_modules -ENV NODE_ENV=production +ENV NODE_ENV=development -# Run npm prune to remove dev dependencies -RUN npm prune --production +RUN npm install EXPOSE 3000 -CMD ["npm", "run", "start:prod"] +CMD ["npm", "run", "start:debug"] -FROM node:18-alpine AS development +FROM node:18-alpine AS production WORKDIR /app COPY --from=builder /app/package*.json ./ COPY --from=builder /app/ . +COPY --from=builder /app/node_modules ./node_modules -ENV NODE_ENV=development +ENV NODE_ENV=production -RUN npm install +# Run npm prune to remove dev dependencies +RUN npm prune --production EXPOSE 3000 -CMD ["npm", "run", "start:dev"] +CMD ["npm", "run", "start:prod"] diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml index 2bad0cf5..679dfd1b 100644 --- a/docker/docker-compose.dev.yml +++ b/docker/docker-compose.dev.yml @@ -22,7 +22,6 @@ services: - ../api/src:/app/src - ../api/migrations:/app/migrations #- ../api/node_modules:/app/node_modules - command: ["npm", "run", "start:debug"] mongo-express: container_name: mongoUi From 253375e56e2e8975a614c5919ac22bd249a2e536 Mon Sep 17 00:00:00 2001 From: Emnaghz Date: Sun, 29 Sep 2024 11:34:14 +0100 Subject: [PATCH 3/3] fix: add requested changes --- api/Dockerfile | 4 ---- docker/docker-compose.dev.yml | 1 + 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/api/Dockerfile b/api/Dockerfile index ba71e9f5..4054c65f 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -6,10 +6,6 @@ COPY . . RUN npm update -g npm -RUN npm config set registry https://registry.npmjs.com/ - -RUN npm run preinstall - RUN npm i --verbose --maxsockets 6 RUN npm run build diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml index 679dfd1b..4a86a2f2 100644 --- a/docker/docker-compose.dev.yml +++ b/docker/docker-compose.dev.yml @@ -4,6 +4,7 @@ services: database-init: build: context: ../api + target: development pull_policy: build volumes: - ../api/src:/app/src