Skip to content

Commit e431d81

Browse files
committed
Trigger a frontend GCP deployment
1 parent cdd7727 commit e431d81

5 files changed

Lines changed: 120 additions & 3 deletions

File tree

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
node_modules
22
npm-debug.log
33
Dockerfile
4+
Dockerfile.frontend
45
Dockerfile.jenkins
56
docker-compose*.yml
67
.git

.github/workflows/ci-docker.yml

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
run: |
3535
cd server
3636
npm test --if-present
37-
37+
# backend image
3838
docker-image:
3939
needs: build-test
4040
runs-on: ubuntu-latest
@@ -72,6 +72,45 @@ jobs:
7272
docker push $IMAGE_ID:$VERSION
7373
docker push $IMAGE_ID:latest
7474
75+
# frontend image
76+
frontend-docker-image:
77+
needs: build-test
78+
runs-on: ubuntu-latest
79+
80+
permissions:
81+
contents: read
82+
packages: write
83+
84+
env:
85+
IMAGE_NAME: mcp-frontend
86+
87+
steps:
88+
- name: Checkout repository
89+
uses: actions/checkout@v4
90+
91+
- name: Login to GitHub Container Registry
92+
uses: docker/login-action@v3
93+
with:
94+
registry: ghcr.io
95+
username: ${{ github.actor }}
96+
password: ${{ secrets.GITHUB_TOKEN }}
97+
98+
- name: Build frontend Docker image
99+
run: |
100+
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
101+
VERSION=${{ github.sha }}
102+
103+
echo "FRONTEND_IMAGE_ID=$IMAGE_ID" >> $GITHUB_ENV
104+
echo "FRONTEND_VERSION=$VERSION >> $GITHUB_ENV
105+
106+
docker build -f Dockerfile.frontend -t $IMAGE_ID:VERSION -t $IMAGE_ID:latest .
107+
108+
- name:
109+
run: |
110+
docker push $FRONTEND_IMAGE_ID:$FRONTEND_VERSION
111+
docker push $FRONTEND_IMAGE_ID:latest
112+
113+
# backend cloud deployment
75114
deploy-gcp:
76115
needs: docker-image
77116
runs-on: ubuntu-latest
@@ -121,3 +160,54 @@ jobs:
121160
--platform managed \
122161
--allow-unauthenticated \
123162
--port 3000
163+
164+
# frontend cloud deployment
165+
deploy-gcp-frontend:
166+
needs: frontend-docker-image
167+
runs-on: ubuntu-latest
168+
permissions:
169+
contents: read
170+
packages: read
171+
172+
steps:
173+
- name: Checkout repository
174+
uses: actions/checkout@v4
175+
176+
- name: Authenticate to Google Cloud
177+
uses: google-github-actions/auth@v2
178+
with:
179+
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
180+
181+
- name: Set up gcloud
182+
uses: google-github-actions/setup-gcloud@v2
183+
with:
184+
project_id: ${{ secrets.GCP_PROJECT_ID }}
185+
186+
- name: Configure Docker for Artifact Registry
187+
run: |
188+
gcloud auth configure-docker us-east1-docker.pkg.dev --quiet
189+
190+
- name: Pull frontend image from GHCR
191+
run: |
192+
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/mcp-frontend
193+
VERSION=${{ github.sha }}
194+
echo "FRONTEND_IMAGE_ID=$IMAGE_ID" >> $GITHUB_ENV
195+
echo "FRONTEND_VERSION=$VERSION" >> $GITHUB_ENV
196+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin
197+
docker pull $IMAGE_ID:$VERSION
198+
199+
- name: Tag & push frontend image to Artifact Registry
200+
run: |
201+
AR_FRONTEND_IMAGE=us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/mcp-frontend/mcp-frontend
202+
docker tag ghcr.io/${{ github.repository_owner }}/mcp-frontend:${{ github.sha }} $AR_FRONTEND_IMAGE:${{ github.sha }}
203+
docker push $AR_FRONTEND_IMAGE:${{ github.sha }}
204+
echo "AR_FRONTEND_IMAGE=$AR_FRONTEND_IMAGE" >> $GITHUB_ENV
205+
206+
- name: Deploy frontend to Cloud Run
207+
run: |
208+
gcloud run deploy mcp-frontend \
209+
--image $AR_FRONTEND_IMAGE:${{ github.sha }} \
210+
--region ${{ secrets.GCP_REGION }} \
211+
--platform managed \
212+
--allow-unauthenticated \
213+
--port 80

Dockerfile.frontend

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Stage 1: Build the frontend
2+
FROM node:20-alpine AS build
3+
4+
WORKDIR /app
5+
6+
# Copy only package manifests first for better caching
7+
COPY client/package*.json ./
8+
RUN npm ci
9+
10+
# Copy the rest of the frontend source
11+
COPY client ./
12+
13+
# Build the production static bundle (Vite/React default is "dist")
14+
RUN npm run build
15+
16+
# Stage 2: Serve with nginx
17+
FROM nginx:alpine
18+
19+
# Copy built assets from the previous stage
20+
COPY --from=build /app/dist /usr/share/nginx/html
21+
22+
# Expose HTTP port
23+
EXPOSE 80
24+
25+
# Start nginx in foreground
26+
CMD ["nginx", "-g", "daemon off;"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ Adding this line to test the workflows
198198
Another test2
199199
test3
200200
test 4
201-
201+
// "build": "tsc -b && vite build",
202202
203203
Test
204204
```

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
8-
"build": "tsc -b && vite build",
8+
"build": "vite build",
99
"lint": "eslint .",
1010
"preview": "vite preview"
1111
},

0 commit comments

Comments
 (0)