From d0da7cead5732346d95aa11443d861ce83f108b4 Mon Sep 17 00:00:00 2001 From: Emnaghz Date: Fri, 27 Sep 2024 11:22:18 +0100 Subject: [PATCH] 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 9323e6e6b..6eb1defee 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 7e90a7a47..a8a9f5446 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 98c7912e8..2bad0cf58 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