diff --git a/backend/Dockerfile b/backend/Dockerfile index 89203db..d4be773 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,15 +1,15 @@ -FROM node:18-bullseye-slim AS build +FROM node:18-slim AS build # Install WORKDIR /app COPY *.json ./ COPY ./src /app/src -RUN npm ci --ignore-scripts -RUN npm run build +RUN npm ci --ignore-scripts && \ + npm run build # Deployment container FROM gcr.io/distroless/nodejs:18 -ENV NODE_ENV production +ENV NODE_ENV=production # Copy over app WORKDIR /app @@ -21,7 +21,7 @@ EXPOSE 3000 HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost:3000/api || exit 1 # Non-privileged user -USER app +USER 1001 # 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"] diff --git a/docker-compose.yml b/docker-compose.yml index 9cd0b17..2ff808d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,23 @@ ---- -version: "3.8" +# Reusable config +x-common: &common + container_name: backend + ports: ["3000:3000"] + healthcheck: + test: [ "CMD", "curl", "-f", "http://localhost:3000/api" ] + working_dir: "/app" services: - backend: + # Local dev - docker compose up dev + dev: + profiles: ["dev"] + entrypoint: ["sh", "-c", "npm i && npm run start"] + image: node:18 + volumes: ["./backend:/app:z", "/app/node_modules"] + <<: *common + + # Container/deploy - docker compose up deploy + deploy: + profiles: ["deploy"] build: context: backend - container_name: backend - entrypoint: - - "sh" - - "-c" - - "npm i && npm run start" - hostname: backend - image: node:18 - ports: - - "3000:3000" - volumes: - - ./backend:/app:z - - /app/node_modules - healthcheck: - test: [ "CMD", "curl", "-f", "http://localhost:3000/api" ] - working_dir: "/app" + <<: *common