-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (61 loc) · 2.52 KB
/
ci-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Application CI/CD
on:
push:
branches: [ "master" ]
jobs:
tests-n-cs:
uses: ./.github/workflows/tests-n-cs.yml
docker-image-ar:
runs-on: ubuntu-latest
needs: tests-n-cs
steps:
- name: Check out the repository
uses: actions/checkout@v4
- name: Set up Google Cloud authentication
uses: google-github-actions/auth@v4
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up gcloud CLI
uses: google-github-actions/setup-gcloud@v4
with:
project_id: ${{ vars.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true
- name: Configure Docker to use Artifact Registry
run: gcloud auth configure-docker ${{ vars.GCP_REGION }}-docker.pkg.dev
- name: Build Docker image (Octane)
run: docker build . --file Dockerfile.app --tag octane:latest
- name: Build Docker image (Nginx)
run: docker build . --file Dockerfile.nginx --tag nginx:latest
- name: Tag Docker images
run: |
docker tag octane:latest ${{ vars.GCP_AR_REPOSITORY }}/octane:latest
docker tag nginx:latest ${{ vars.GCP_AR_REPOSITORY }}/nginx:latest
- name: Push Docker images to Artifact Registry
run: |
docker push ${{ vars.GCP_AR_REPOSITORY }}/octane:latest
docker push ${{ vars.GCP_AR_REPOSITORY }}/nginx:latest
cr-service-deploy:
runs-on: ubuntu-latest
needs: docker-image-ar
steps:
- name: Check out the repository
uses: actions/checkout@v4
- name: Update Cloud Run Service definition
run: |
sed -i 's|<GCP_PROJECT_ID>|${{ vars.GCP_PROJECT_ID }}|' ./gcp/cloud-run/service.yaml
sed -i 's|<GCP_CLOUD_RUN_SERVICE>|${{ vars.GCP_CLOUD_RUN_SERVICE }}|' ./gcp/cloud-run/service.yaml
sed -i 's|<DOCKER_IMAGE_OCTANE>|${{ vars.GCP_AR_REPOSITORY }}/octane:latest|' ./gcp/cloud-run/service.yaml
sed -i 's|<DOCKER_IMAGE_NGINX>|${{ vars.GCP_AR_REPOSITORY }}/nginx:latest|' ./gcp/cloud-run/service.yaml
- name: Set up Google Cloud authentication
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up gcloud CLI
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ vars.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true
- name: Deploy to Cloud Run
run: gcloud run services replace ./gcp/cloud-run/service.yaml --region ${{ vars.GCP_REGION }}