Skip to content

Commit 54ba320

Browse files
committed
fix: correct Docker build workflow and API image configuration
1 parent 4b5bf24 commit 54ba320

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

.github/workflows/docker-build.yml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99

1010
env:
1111
REGISTRY: tpsappscriptingacr.azurecr.io
12+
IMAGE_EDITOR: app-scripting-editor
1213
IMAGE_API: app-scripting-editor-api
1314

1415
jobs:
@@ -36,20 +37,33 @@ jobs:
3637
- name: Set up Docker Buildx
3738
uses: docker/setup-buildx-action@v3
3839

39-
# ---- Build API (Node/Express) image ----
40-
# NOTE: Your API Dockerfile copies the SPA from ${REGISTRY}/app-scripting-editor:latest.
41-
# Make sure that image exists in ACR, or switch to the "self-contained" Dockerfile approach below.
42-
- name: Build & push API image (Node/Express + SPA)
40+
# ---- Step 1: Build Frontend (Editor) image first ----
41+
- name: Build & push Editor image (Frontend/nginx)
4342
uses: docker/build-push-action@v6
4443
with:
4544
context: .
46-
file: ./Dockerfile # change if your API Dockerfile lives elsewhere
45+
file: ./Dockerfile
4746
push: true
4847
build-args: |
49-
REGISTRY=${{ env.REGISTRY }}
5048
VITE_APP_VERSION=1.0.0
5149
VITE_APP_BUILD_TIME=${{ github.event.head_commit.timestamp }}
5250
VITE_APP_COMMIT_SHA=${{ github.sha }}
51+
tags: |
52+
${{ env.REGISTRY }}/${{ env.IMAGE_EDITOR }}:latest
53+
${{ env.REGISTRY }}/${{ env.IMAGE_EDITOR }}:${{ github.sha }}
54+
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_EDITOR }}:buildcache
55+
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_EDITOR }}:buildcache,mode=max
56+
57+
# ---- Step 2: Build API (Node/Express + Frontend) image ----
58+
# This uses the editor image we just built above
59+
- name: Build & push API image (Node/Express + SPA)
60+
uses: docker/build-push-action@v6
61+
with:
62+
context: .
63+
file: ./server/Dockerfile
64+
push: true
65+
build-args: |
66+
REGISTRY=${{ env.REGISTRY }}
5367
tags: |
5468
${{ env.REGISTRY }}/${{ env.IMAGE_API }}:latest
5569
${{ env.REGISTRY }}/${{ env.IMAGE_API }}:${{ github.sha }}

server/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@
22

33
# 1) Use previously built editor image (pushed to registry) as web-build
44
# This avoids requiring the 'editor/' directory in the Docker build context.
5-
ARG REGISTRY
5+
ARG REGISTRY=tpsappscriptingacr.azurecr.io
66
FROM ${REGISTRY}/app-scripting-editor:latest AS web-build
77

88
# 2) Build server
99
FROM node:18-alpine AS server-build
1010
WORKDIR /srv
1111
COPY server/package.json server/package-lock.json* ./
1212
RUN if [ -f package-lock.json ]; then npm ci --production=false; else npm install --production=false; fi
13-
COPY server/ ./server
14-
WORKDIR /srv/server
13+
COPY server/ ./
1514
RUN npm run build
1615

1716
# 3) Final image
1817
FROM node:18-alpine
1918
WORKDIR /app
2019
# Install production deps for server
21-
COPY server/package.json ./
20+
COPY server/package.json server/package-lock.json* ./
2221
RUN if [ -f package-lock.json ]; then npm ci --production; else npm install --production; fi
2322

2423
# Copy built server
25-
COPY --from=server-build /srv/server/dist ./dist
24+
COPY --from=server-build /srv/dist ./dist
2625

2726
# Copy built frontend from the editor image (nginx html location) so the server can serve it
2827
# The editor image places the built site at /usr/share/nginx/html

0 commit comments

Comments
 (0)