-
Notifications
You must be signed in to change notification settings - Fork 1
52 lines (41 loc) · 1.38 KB
/
backend-deploy.yml
File metadata and controls
52 lines (41 loc) · 1.38 KB
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
name: Backend Deploy to Cloud Run
run-name: "Cloud Deploy #${{ github.run_number }} by @${{ github.actor }}"
on:
workflow_dispatch:
env:
PROJECT_ID: job-tracker-pro-480917
REGION: asia-south1
REPO_NAME: my-repo
SERVICE_NAME: jobtracker-service
IMAGE_NAME: my-java-app
jobs:
deploy:
name: Deploy Backend
runs-on: ubuntu-latest
# Optional guard: deploy only from main
if: github.ref == 'refs/heads/main'
environment:
name: production
steps:
- uses: actions/checkout@v4
- name: Google Auth
uses: google-github-actions/auth@v2
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
- name: Docker Auth
run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
- name: Build and Push Image
run: |
TAG="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
docker build -t $TAG ./backend
docker push $TAG
echo "IMAGE_TAG=$TAG" >> $GITHUB_ENV
- name: Update Service YAML
run: |
sed -i "s|image: .*|image: ${{ env.IMAGE_TAG }}|g" backend/service.yaml
cat backend/service.yaml
- name: Deploy to Cloud Run
uses: google-github-actions/deploy-cloudrun@v2
with:
metadata: backend/service.yaml
region: ${{ env.REGION }}