Skip to content

Commit

Permalink
ci: Dockerfile and Docker Compose updates (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekRoberts authored Nov 20, 2024
1 parent cd848b6 commit 9f11c8c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
10 changes: 5 additions & 5 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"]
37 changes: 19 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9f11c8c

Please sign in to comment.