Skip to content

Commit 9ce30b4

Browse files
authored
Merge pull request #23 from codeuniversity/feature-frontend-docker
Feature frontend docker
2 parents 4652c1c + 2a317ba commit 9ce30b4

File tree

2 files changed

+48
-12
lines changed

2 files changed

+48
-12
lines changed

.github/workflows/deploy.yml

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ jobs:
1111

1212
env:
1313
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GCP_SA_KEY }}
14-
IMAGE_NAME: europe-west3-docker.pkg.dev/thf-climate-cloud/thf-climate/thf-climate
14+
BACKEND_IMAGE_NAME: europe-west3-docker.pkg.dev/thf-climate-cloud/thf-climate/thf-climate
15+
FRONTEND_IMAGE_NAME: europe-west3-docker.pkg.dev/thf-climate-cloud/thf-climate-frontend/thf-climate-frontend
1516

1617
steps:
1718
# Step 1: Checkout the code
@@ -42,27 +43,44 @@ jobs:
4243
run: |
4344
gcloud auth configure-docker europe-west3-docker.pkg.dev
4445
45-
# Step 6: Docker Login using Access Token
46-
- name: Build Docker image
46+
# Step 6: Build and Deploy the backend
47+
- name: Build Docker image (backend)
4748
working-directory: ./backend
4849
run: |
49-
docker buildx build --platform linux/amd64 -t $IMAGE_NAME:latest .
50-
51-
# Step 7: Build Docker image
52-
- name: Push Docker image to Artifact Registry
50+
docker buildx build --platform linux/amd64 -t $BACKEND_IMAGE_NAME:latest .
51+
- name: Push Docker image to Artifact Registry (backend)
5352
working-directory: ./backend
5453
run: |
55-
docker push $IMAGE_NAME:latest
56-
57-
# Step 8: Push Docker image to Google Artifact Registry
58-
- name: Deploy to Cloud Run
54+
docker push $BACKEND_IMAGE_NAME:latest
55+
- name: Deploy to Cloud Run (backend)
5956
working-directory: ./backend
6057
run: |
6158
gcloud run deploy thf-climate-run \
62-
--image=$IMAGE_NAME:latest \
59+
--image=$BACKEND_IMAGE_NAME:latest \
6360
--port=8000 \
6461
--region=europe-west3 \
6562
--allow-unauthenticated \
6663
--platform=managed \
6764
--min-instances=1 \
6865
--max-instances=5
66+
67+
# Step 7: Build and Deploy the frontend
68+
- name: Build Docker image (frontend)
69+
working-directory: ./frontend
70+
run: |
71+
docker buildx build --platform linux/amd64 -t $FRONTEND_IMAGE_NAME:latest .
72+
- name: Push Docker image to Artifact Registry (frontend)
73+
working-directory: ./frontend
74+
run: |
75+
docker push $FRONTEND_IMAGE_NAME:latest
76+
- name: Deploy to Cloud Run (frontend)
77+
working-directory: ./frontend
78+
run: |
79+
gcloud run deploy thf-climate-frontend-run \
80+
--image=$FRONTEND_IMAGE_NAME:latest \
81+
--port=80 \
82+
--region=europe-west3 \
83+
--allow-unauthenticated \
84+
--platform=managed \
85+
--min-instances=1 \
86+
--max-instances=5

frontend/dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Basic setup
2+
FROM node:18-alpine AS build
3+
WORKDIR /app
4+
COPY . /app
5+
COPY package*.json ./
6+
7+
# Install dependencies and build the app
8+
RUN npm install
9+
COPY . .
10+
RUN npm run build
11+
12+
# Run using nginx
13+
FROM nginx:alpine
14+
COPY --from=build /app/dist /usr/share/nginx/html
15+
16+
# Start Nginx server
17+
EXPOSE 80
18+
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)