Skip to content

Commit f346834

Browse files
authored
Merge pull request #631 from cornell-dti/bek76/pnpm-docker
Fix Docker flow to use `pnpm` (+ modernize Docker flow)
2 parents 6514c17 + ef50d26 commit f346834

13 files changed

Lines changed: 252 additions & 247 deletions

.dockerignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@
22
**/node_modules
33
build
44
*.log
5-
*.gz
5+
*.gz
6+
7+
**/.env
8+
9+
.dockerignore
10+
Dockerfile
11+
LICENSE
12+
13+
.github

.github/workflows/cd-workflow.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/workflows/ci-container.yml

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,62 @@
1-
name: CI Docker Build
1+
name: CI Docker Build / Push
22

3-
on: pull_request
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- 'master'
8+
tags:
9+
- 'v*'
10+
pull_request:
11+
12+
permissions:
13+
contents: read
14+
packages: write
415

516
jobs:
6-
build:
7-
uses: ./.github/workflows/docker-build-push.yml
8-
with:
9-
push: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
10-
tags: |
11-
ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:pr-${{ github.event.pull_request.number }}-latest
12-
ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:pr-${{ github.event.pull_request.number }}-${{ github.sha }}
13-
labels: |
14-
org.opencontainers.image.source=${{ github.event.pull_request.html_url }}
15-
org.opencontainers.image.title=PR-${{ github.event.pull_request.number }}
16-
org.opencontainers.image.description=${{ github.event.pull_request.title }}
17-
secrets: inherit
17+
build-push:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
- name: Log in to registry
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ghcr.io
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Docker meta
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ghcr.io/${{ github.repository }}
40+
tags: |
41+
type=schedule
42+
type=ref,event=branch
43+
type=ref,event=tag
44+
type=ref,event=pr
45+
type=sha
46+
47+
- name: Docker build and push
48+
uses: docker/build-push-action@v6
49+
with:
50+
push: true
51+
context: .
52+
tags: ${{ steps.meta.outputs.tags }}
53+
labels: ${{ steps.meta.outputs.labels }}
54+
cache-from: type=gha
55+
cache-to: type=gha,mode=max
56+
build-args: |
57+
REACT_APP_SERVER_URL=${{ secrets.REACT_APP_SERVER_URL }}
58+
REACT_APP_CLIENT_ID=${{ secrets.REACT_APP_CLIENT_ID }}
59+
REACT_APP_PUBLIC_VAPID_KEY=${{ secrets.REACT_APP_PUBLIC_VAPID_KEY }}
60+
REACT_APP_ENCRYPTION_KEY=${{ secrets.REACT_APP_ENCRYPTION_KEY }}
61+
REACT_APP_GOOGLE_MAPS_API_KEY=${{ secrets.REACT_APP_GOOGLE_MAPS_API_KEY }}
62+
REACT_APP_GOOGLE_MAPS_MAP_ID=${{ secrets.REACT_APP_GOOGLE_MAPS_MAP_ID }}

.github/workflows/docker-build-push.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.

Dockerfile

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
11
# Base image
2-
FROM node:16-alpine
3-
4-
# Create a directory for the app
2+
FROM node:24-alpine AS base
53
WORKDIR /app
64

5+
# pnpm setup
6+
ENV CI=true
7+
RUN corepack enable pnpm && \
8+
pnpm config set store-dir /pnpm/store && \
9+
pnpm config set package-import-method clone-or-copy
10+
11+
# Build stage
12+
FROM base AS fetch-deps
13+
COPY pnpm-lock.yaml pnpm-workspace.yaml ./
14+
RUN pnpm fetch --prod
15+
16+
FROM fetch-deps AS prod-deps
17+
COPY . .
18+
RUN pnpm install -r --offline --prod --filter server...
19+
20+
FROM fetch-deps AS build-base
21+
RUN pnpm fetch
22+
23+
# Build both frontend and server separately for caching
24+
FROM build-base AS build-server
25+
COPY . .
26+
RUN pnpm install -r --offline --filter server...
27+
# Build with CI=false to avoid treat warnings as errors
28+
RUN CI=false pnpm run -r --filter server... build
29+
30+
FROM build-base AS build-frontend
31+
COPY . .
32+
# TODO: filter only frontend dependencies. until we add a shared package, we need all dependencies
33+
RUN pnpm install -r --offline
34+
735
# Read build-time environment variables
836
ARG REACT_APP_SERVER_URL
937
ENV REACT_APP_SERVER_URL=${REACT_APP_SERVER_URL}
@@ -13,25 +41,23 @@ ARG REACT_APP_PUBLIC_VAPID_KEY
1341
ENV REACT_APP_PUBLIC_VAPID_KEY=${REACT_APP_PUBLIC_VAPID_KEY}
1442
ARG REACT_APP_ENCRYPTION_KEY
1543
ENV REACT_APP_ENCRYPTION_KEY=${REACT_APP_ENCRYPTION_KEY}
44+
ARG REACT_APP_GOOGLE_MAPS_API_KEY
45+
ENV REACT_APP_GOOGLE_MAPS_API_KEY=${REACT_APP_GOOGLE_MAPS_API_KEY}
46+
ARG REACT_APP_GOOGLE_MAPS_MAP_ID
47+
ENV REACT_APP_GOOGLE_MAPS_MAP_ID=${REACT_APP_GOOGLE_MAPS_MAP_ID}
1648

17-
# Copy package.jsons first to install
18-
COPY package.json package-lock.json /app/
19-
COPY frontend/package.json frontend/package-lock.json /app/frontend/
20-
COPY server/package.json server/package-lock.json /app/server/
21-
RUN npm install
49+
# Build with CI=false to avoid treat warnings as errors
50+
RUN CI=false pnpm run -r --filter frontend... build
2251

52+
FROM base AS prod
2353
# Copy the frontend and server directories to the app directory
24-
COPY frontend /app/frontend
25-
COPY server /app/server
26-
COPY . .
54+
COPY --from=prod-deps /app/node_modules /app/node_modules
55+
COPY --from=prod-deps /app/server/node_modules /app/server/node_modules
2756

28-
# Install dependencies for the frontend and build the app
29-
WORKDIR /app/frontend
30-
RUN npm run build
57+
COPY --from=build-frontend /app/frontend/build /app/frontend/build
3158

32-
# Install dependencies for the server
33-
WORKDIR /app/server
34-
RUN npm run build
59+
COPY --from=build-server /app/server/build /app/server/build
60+
COPY --from=build-server /app/server/package.json /app/server/package.json
3561

3662
# Set production environment after build
3763
ENV NODE_ENV=production
@@ -40,4 +66,5 @@ ENV NODE_ENV=production
4066
EXPOSE 3001
4167

4268
# Start the server
43-
CMD ["npm", "start"]
69+
WORKDIR /app/server
70+
CMD ["pnpm", "start"]

docker-compose.local.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
carriage:
3+
extends:
4+
file: ./docker-compose.yml
5+
service: carriage
6+
volumes:
7+
- './server/config/cornell-idp-test.crt:/app/server/config/cornell-idp-test.crt:ro'
8+
env_file:
9+
- ./server/.env

docker-compose.yml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
version: '3'
2-
31
services:
42
carriage:
3+
image: ghcr.io/cornell-dti/carriage-web:${IMAGE_TAG:-latest}
4+
restart: always
5+
ports:
6+
- '3001:3001'
7+
build:
8+
context: .
9+
args:
10+
- REACT_APP_SERVER_URL=${REACT_APP_SERVER_URL}
11+
- REACT_APP_CLIENT_ID=${REACT_APP_CLIENT_ID}
12+
- REACT_APP_PUBLIC_VAPID_KEY=${REACT_APP_PUBLIC_VAPID_KEY}
13+
- REACT_APP_ENCRYPTION_KEY=${REACT_APP_ENCRYPTION_KEY}
14+
- REACT_APP_GOOGLE_MAPS_API_KEY=${REACT_APP_GOOGLE_MAPS_API_KEY}
15+
- REACT_APP_GOOGLE_MAPS_MAP_ID=${REACT_APP_GOOGLE_MAPS_MAP_ID}
516
environment:
617
- NODE_ENV=production
718
- DEBUG=True
@@ -19,14 +30,17 @@ services:
1930
- DOMAIN=${DOMAIN}
2031
- OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID}
2132
- OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET}
22-
build:
23-
context: .
24-
args:
25-
- REACT_APP_SERVER_URL=${REACT_APP_SERVER_URL}
26-
- REACT_APP_CLIENT_ID=${REACT_APP_CLIENT_ID}
27-
- REACT_APP_PUBLIC_VAPID_KEY=${REACT_APP_PUBLIC_VAPID_KEY}
28-
- REACT_APP_ENCRYPTION_KEY=${REACT_APP_ENCRYPTION_KEY}
29-
ports:
30-
- '3001:3001'
31-
image: ghcr.io/cornell-dti/carriage-web:${IMAGE_TAG:-latest}
32-
restart: always
33+
# auth
34+
- SSO_ENABLED=${SSO_ENABLED}
35+
- FRONTEND_URL=${FRONTEND_URL}
36+
- SAML_ENTRY_POINT=${SAML_ENTRY_POINT}
37+
- SAML_CALLBACK_URL=${SAML_CALLBACK_URL}
38+
- SAML_ISSUER=${SAML_ISSUER}
39+
- SAML_IDP_CERT_PATH=${SAML_IDP_CERT_PATH}
40+
- SESSION_SECRET=${SESSION_SECRET}
41+
- SESSION_TTL=${SESSION_TTL}
42+
- SESSION_STORE_PATH=${SESSION_STORE_PATH}
43+
# cornell LDAP
44+
- LDAP_URL=${LDAP_URL}
45+
- LDAP_USER=${LDAP_USER}
46+
- LDAP_PASSWORD=${LDAP_PASSWORD}

frontend/.dockerignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)