Bashir Gulistani
commited on
Commit
•
ea0919c
1
Parent(s):
9e7c12e
Create main.yml
Browse files- .github/workflows/main.yml +47 -0
.github/workflows/main.yml
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Build and Deploy to GCP
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches:
|
6 |
+
- main # Trigger the workflow when changes are pushed to the main branch
|
7 |
+
|
8 |
+
jobs:
|
9 |
+
build-and-deploy:
|
10 |
+
runs-on: ubuntu-latest
|
11 |
+
|
12 |
+
steps:
|
13 |
+
# Step 1: Checkout the repository
|
14 |
+
- name: Checkout Code
|
15 |
+
uses: actions/checkout@v3
|
16 |
+
|
17 |
+
# Step 2: Set up Google Cloud SDK
|
18 |
+
- name: Set up gcloud
|
19 |
+
uses: google-github-actions/setup-gcloud@v1
|
20 |
+
with:
|
21 |
+
service_account_key: ${{ secrets.GCP_SA_KEY }}
|
22 |
+
project_id: ace-mile-379006
|
23 |
+
|
24 |
+
# Step 3: Authenticate Docker with GCP
|
25 |
+
- name: Authenticate Docker with GCP
|
26 |
+
run: gcloud auth configure-docker
|
27 |
+
|
28 |
+
# Step 4: Build the Docker image
|
29 |
+
- name: Build Docker Image
|
30 |
+
run: |
|
31 |
+
docker build -t gcr.io/ace-mile-379006/product1b:$GITHUB_SHA .
|
32 |
+
docker tag gcr.io/ace-mile-379006/product1b:$GITHUB_SHA gcr.io/ace-mile-379006/product1b:latest
|
33 |
+
|
34 |
+
# Step 5: Push the Docker image to Google Container Registry (GCR)
|
35 |
+
- name: Push Docker Image to GCR
|
36 |
+
run: |
|
37 |
+
docker push gcr.io/ace-mile-379006/product1b:$GITHUB_SHA
|
38 |
+
docker push gcr.io/ace-mile-379006/product1b:latest
|
39 |
+
|
40 |
+
# Step 6: Deploy to Cloud Run
|
41 |
+
- name: Deploy to Cloud Run
|
42 |
+
run: |
|
43 |
+
gcloud run deploy cs553p \
|
44 |
+
--image gcr.io/ace-mile-379006/product1b:latest \
|
45 |
+
--platform managed \
|
46 |
+
--region us-east1 \
|
47 |
+
--allow-unauthenticated
|