-
Notifications
You must be signed in to change notification settings - Fork 0
56 lines (50 loc) · 2.03 KB
/
ci-cd-prod.yaml
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
name: CI/CD Development
on:
workflow_dispatch:
push:
branches:
- main
jobs:
build-and-deploy:
env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
SERVICE: ${{ secrets.GCP_SERVICE }}
REGION: ${{ secrets.GCP_REGION }}
TAG: latest
runs-on: ubuntu-latest
environment: development
steps:
# checkout the repo
- name: "Checkout GitHub Action"
uses: actions/checkout@master
# Authenticate to Google Cloud
- name: Google Auth
id: auth
uses: "google-github-actions/auth@v2"
with:
credentials_json: "${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}"
# Authenticate Docker to Google Cloud Artifact Registry
- name: Docker Auth
id: docker-auth
uses: "docker/login-action@v3"
with:
username: _json_key
password: "${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}"
registry: "${{ env.REGION }}-docker.pkg.dev"
# Build and push the Docker image
- name: Build and Push Container
run: |-
docker build \
-f Dockerfile \
-t "${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ env.TAG }}" .
docker push "${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ env.TAG }}"
# Deploy to Cloud Run
- name: Deploy to Cloud Run
run: |
gcloud run deploy ${{ env.SERVICE }} \
--platform=managed \
--port=3000 \
--region=${{ env.REGION }} \
--image="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ env.TAG }}" \
--min-instances=0 \
--max-instances=1