File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed
Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Deploy to Cloud Run
2+
3+ on :
4+ push :
5+ branches : [ "main" ]
6+
7+ env :
8+ PROJECT_ID : job-tracker-pro-480917
9+ REGION : asia-south1
10+ # if not exist, create it: gcloud artifacts repositories create my-repo --repository-format=docker --location=asia-south1
11+ REPO_NAME : my-repo
12+ SERVICE_NAME : jobtracker-service
13+ IMAGE_NAME : my-java-app
14+
15+ jobs :
16+ deploy :
17+ runs-on : ubuntu-latest
18+
19+ steps :
20+ - name : Checkout code
21+ uses : actions/checkout@v4
22+
23+ # 1. Authenticate to Google Cloud
24+ - name : Google Auth
25+ id : auth
26+ uses : google-github-actions/auth@v2
27+ with :
28+ credentials_json : ' ${{ secrets.GCP_CREDENTIALS }}'
29+
30+ # 2. Configure Docker to use gcloud command-line tool as a credential helper
31+ - name : Docker Auth
32+ run : |
33+ gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
34+
35+ # 3. Build and Push Container
36+ - name : Build and Push Container
37+ run : |
38+ TAG="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
39+ docker build -t $TAG .
40+ docker push $TAG
41+ echo "IMAGE_TAG=$TAG" >> $GITHUB_ENV
42+
43+ # 4. Update service.yaml with the new image tag
44+ - name : Update Service YAML
45+ run : |
46+ # Replace the hardcoded image line with the new dynamic tag
47+ sed -i "s|image: .*|image: ${{ env.IMAGE_TAG }}|g" service.yaml
48+ cat service.yaml # Optional: verify content in logs
49+
50+ # 5. Deploy to Cloud Run using the YAML
51+ - name : Deploy to Cloud Run
52+ uses : google-github-actions/deploy-cloudrun@v2
53+ with :
54+ metadata : service.yaml
55+ region : ${{ env.REGION }}
You can’t perform that action at this time.
0 commit comments