Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated dockerfile for nest-forms-backend to new version #1400

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ca01d35
updated dockerfile to new version
skifahrer Sep 16, 2024
c848e99
Merge branch 'master' into updated-docker-image-on-forms-backend
skifahrer Sep 16, 2024
d462c72
Merge branch 'master' into updated-docker-image-on-forms-backend
skifahrer Sep 17, 2024
6b79107
updates to dockerfile with some fixses
skifahrer Sep 17, 2024
96d3427
Merge remote-tracking branch 'origin/updated-docker-image-on-forms-ba…
skifahrer Sep 17, 2024
38e9ddb
added start:migrate:prod script
skifahrer Sep 17, 2024
5400b7b
Merge branch 'master' into updated-docker-image-on-forms-backend
skifahrer Sep 17, 2024
c5f54f5
added forms-shared to prod version
skifahrer Sep 17, 2024
cfc3e76
Merge remote-tracking branch 'origin/updated-docker-image-on-forms-ba…
skifahrer Sep 17, 2024
4704b47
added forms shared to prod
skifahrer Sep 18, 2024
1a1a1b5
Merge branch 'master' into updated-docker-image-on-forms-backend
skifahrer Sep 18, 2024
caf0b78
Merge branch 'master' into updated-docker-image-on-forms-backend
skifahrer Sep 19, 2024
fff2d05
updates and testing changes
skifahrer Sep 19, 2024
99266dc
updates and testing changes
skifahrer Sep 23, 2024
780fc8b
testing dist
skifahrer Sep 23, 2024
539ddc4
removed dist as it needs node_modules
skifahrer Sep 23, 2024
d4b3722
Merge branch 'master' into updated-docker-image-on-forms-backend
skifahrer Sep 24, 2024
f7c0001
added latest tag
skifahrer Sep 24, 2024
60ee4f8
Merge remote-tracking branch 'origin/updated-docker-image-on-forms-ba…
skifahrer Sep 24, 2024
e47b403
testing playwright in app-base
skifahrer Sep 24, 2024
8448248
added user
skifahrer Sep 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 46 additions & 53 deletions nest-forms-backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,65 +1,58 @@
# If FORMS_SHARED_TAG is not specified, use general "latest"
ARG FORMS_SHARED_TAG=latest
FROM harbor.bratislava.sk/standalone/forms-shared:${FORMS_SHARED_TAG} as shared
FROM node:20.9 AS base

RUN npx playwright install-deps chromium

# build
FROM base AS build
WORKDIR /root/forms-shared
COPY --from=shared /app/ ./

WORKDIR /root/nest-forms-backend
COPY package*.json ./

RUN npm ci

COPY . ./

RUN npx prisma generate --schema=./prisma/schema.prisma

RUN npx prisma migrate

RUN npm run build
FROM harbor.bratislava.sk/standalone/forms-shared:${FORMS_SHARED_TAG} AS shared

FROM node:20.10 AS base
ENV NODE_ENV=production

# Used as app-base in production and development image
FROM base AS app-base
RUN apt-get update \
&& apt-get install -y tini \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /home/node/app \
&& chown -R node:node /home/node/app
USER node
WORKDIR /home/node/app
ENTRYPOINT [ "/usr/bin/tini", "--" ]

# development
FROM base AS dev
FROM base AS build-base
COPY --from=shared /app/ /forms-shared/

WORKDIR /home/node/nest-forms-backend
COPY package*.json ./
WORKDIR /build
COPY package.json package-lock.json prisma ./

RUN npm install
COPY . ./
RUN npm ci --include=dev --frozen-lockfile \
&& npx prisma generate

RUN npx prisma generate
FROM build-base AS build
COPY --chown=node:node . ./
RUN npm run build \
&& npm prune --production

FROM app-base AS dev
ENV NODE_ENV=development
# Used **only** for development and local directory should be mounted
CMD [ "npm", "run", "start:debug" ]

# Production
FROM app-base AS prod

# production
FROM base AS prod

USER root
# Install Playwright dependencies
RUN npx playwright install-deps chromium
USER node

# When copying from build, it copies symlink in node_modules to ../../forms-shared and expects the original directory
# to be present.
# TODO: Find a way how to use --install-links flag in npm install to avoid this.
RUN mkdir -p /home/node/forms-shared && chown -R node:node /home/node/forms-shared
WORKDIR /home/node/forms-shared
COPY --chown=node:node --from=shared /app/ ./

RUN mkdir -p /home/node/app && chown -R node:node /home/node/app
WORKDIR /home/node/app

COPY --chown=node:node --from=build /root/nest-forms-backend/package*.json ./
COPY --chown=node:node --from=build /root/nest-forms-backend/node_modules ./node_modules
# Playwright must be installed after node_modules are copied (installs the same version as in package.json)
RUN npx playwright install chromium
RUN npm prune --production

COPY --chown=node:node --from=build /root/nest-forms-backend/dist ./dist
COPY --chown=node:node --from=build /root/nest-forms-backend/res ./res
COPY --chown=node:node --from=build /root/nest-forms-backend/prisma ./prisma
COPY --chown=node:node --from=shared /app/ /home/node/forms-shared/
COPY --chown=node:node --from=build /build/package.json /build/package-lock.json ./
COPY --chown=node:node --from=build /build/node_modules ./node_modules
COPY --chown=node:node --from=build /build/dist ./dist
COPY --chown=node:node --from=build /build/prisma ./prisma
COPY --chown=node:node nest-cli.json ./nest-cli.json

ENTRYPOINT npx prisma migrate deploy && npm run start:prod
EXPOSE 3000
ARG GIT_COMMIT="undefined"
ENV GIT_COMMIT=$GIT_COMMIT
LABEL org.opencontainers.image.revision="${GIT_COMMIT}" \
org.opencontainers.image.source="https://github.com/bratislava/konto.bratislava.sk/tree/master/nest-forms-backend" \
org.opencontainers.image.licenses="EUPL-1.2"
CMD [ "npm", "run", "start:migrate:prod" ]
1 change: 1 addition & 0 deletions nest-forms-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/src/main",
"start:migrate:prod": "prisma migrate deploy && npm run start:prod",
"seed:prod": "node dist/prisma/seed.js",
"lint": "eslint \"{src,apps,libs,test}/**/*.{ts,js}\"",
"lint:report": "eslint -f json -o eslint-report.json \"{src,apps,libs,test}/**/*.{ts,js}\"",
Expand Down
Loading