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

chore: backend to match QSOS #5

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 26 additions & 22 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
FROM node:20.11.0-bullseye-slim AS build
# Build static files
# Node Bullseye has npm
FROM node:20.11.0-bullseye-slim AS buildWithDevDeps

# Install packages, build and keep only prod packages
WORKDIR /app
COPY *.json ./
COPY ./src ./src
RUN npm ci --ignore-scripts && \
npm run build

RUN mkdir -p /app/sessions

FROM node:20.11.0-bullseye-slim AS dependencies
COPY ./prisma ./prisma
RUN npm ci --ignore-scripts --no-update-notifier
RUN npm run prisma-generate
FROM node:20.11.0-bullseye-slim AS build

# Install packages, build and keep only prod packages
WORKDIR /app
COPY *.json ./
RUN npm ci --omit=dev --ignore-scripts
COPY ./src ./src
COPY ./prisma ./prisma
RUN npm ci --ignore-scripts --no-update-notifier --omit=dev

# COPY over few dependencies from buildWithDevDeps
COPY --from=buildWithDevDeps /app/node_modules/@prisma ./node_modules/@prisma
COPY --from=buildWithDevDeps /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=buildWithDevDeps /app/node_modules/prisma ./node_modules/prisma

RUN npm run build

# Deployment container
# Deploy container
# Distroless has node, but not npm
FROM gcr.io/distroless/nodejs20-debian11:nonroot
ENV NODE_ENV production
# Copy over app.ts

# Copy over app
WORKDIR /app
COPY --from=dependencies /app/node_modules ./node_modules
COPY --from=build /app/node_modules/@prisma ./node_modules/@prisma
COPY --from=build /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=build /app/node_modules/prisma ./node_modules/prisma
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
COPY --from=build /app/sessions ./sessions

# Port and health check
# Ports, health check and non-root user
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost/:3000

# Non-privileged user
USER app
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost/:3000/api || exit 1
USER nonroot

# Start up command with 250MB of heap size, each application needs to determine what is the best value. DONT use default as it is 4GB.
CMD ["--max-old-space-size=250", "/app/dist/server"]
# Start up command with 50MB of heap size, each application needs to determine what is the best value. DONT use default as it is 4GB.
CMD ["--max-old-space-size=50", "/app/dist/main"]
4 changes: 4 additions & 0 deletions backend/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
Loading
Loading