|
1 | 1 | name: Deploy to Google Cloud Run (from GHCR image) |
2 | 2 |
|
3 | 3 | on: |
4 | | - workflow_dispatch: {} |
| 4 | + workflow_dispatch: {} # manual trigger via GitHub Actions tab |
5 | 5 |
|
6 | 6 | env: |
7 | 7 | GCP_PROJECT_ID: clear-rock-477020-a0 |
|
14 | 14 | jobs: |
15 | 15 | deploy: |
16 | 16 | runs-on: ubuntu-22.04 |
17 | | - permissions: |
18 | | - contents: read |
19 | 17 | steps: |
20 | | - - name: Checkout |
21 | | - uses: actions/checkout@v4 |
| 18 | + - uses: actions/checkout@v4 |
22 | 19 |
|
23 | | - # Auth to GCP with SA JSON in secret |
24 | | - - name: Set up gcloud |
| 20 | + # 1) Authenticate with your JSON secret (GCP_CREDENTIALS) |
| 21 | + - name: Auth to Google Cloud |
| 22 | + uses: google-github-actions/auth@v2 |
| 23 | + with: |
| 24 | + credentials_json: ${{ secrets.GCP_CREDENTIALS }} |
| 25 | + |
| 26 | + # 2) Install/initialize gcloud (no key here — auth already done) |
| 27 | + - name: Setup gcloud |
25 | 28 | uses: google-github-actions/setup-gcloud@v2 |
26 | 29 | with: |
27 | | - project_id: ${{ env.GCP_PROJECT_ID }} |
28 | | - service_account_key: ${{ secrets.GCP_CREDENTIALS }} |
| 30 | + project_id: clear-rock-477020-a0 |
29 | 31 | export_default_credentials: true |
30 | 32 |
|
31 | | - # Configure Docker cred helper for Artifact Registry |
32 | | - - name: Enable Artifact Registry docker auth |
33 | | - run: gcloud auth configure-docker $GCP_REGION-docker.pkg.dev --quiet |
| 33 | + # (diagnostic – optional) |
| 34 | + - run: | |
| 35 | + gcloud config list account |
| 36 | + gcloud auth list |
| 37 | +
|
| 38 | + # 3) Configure Docker auth for Artifact Registry |
| 39 | + - name: Enable AR docker auth |
| 40 | + run: gcloud auth configure-docker europe-west6-docker.pkg.dev --quiet |
34 | 41 |
|
35 | | - # (Belt & suspenders) Explicit docker login to AR with OAuth token |
| 42 | + # 4) Explicit docker login (now the token exists) |
36 | 43 | - name: Docker login to Artifact Registry |
37 | 44 | run: | |
38 | | - gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://$GCP_REGION-docker.pkg.dev |
| 45 | + gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://europe-west6-docker.pkg.dev |
39 | 46 |
|
40 | | - # Copy ONLY the amd64 variant from GHCR -> Artifact Registry |
| 47 | + # 5) Copy ONLY amd64 from GHCR → Artifact Registry |
41 | 48 | - name: Setup crane |
42 | 49 | uses: imjasonh/setup-crane@v0.4 |
43 | 50 |
|
44 | 51 | - name: Copy GHCR → AR (amd64) |
45 | 52 | run: | |
46 | 53 | SRC=ghcr.io/chhex/spring-boot-react-crud-revisited2:latest |
47 | | - DST=$GCP_REGION-docker.pkg.dev/$GCP_PROJECT_ID/$GAR_REPOSITORY/$IMAGE_NAME:latest |
| 54 | + DST=europe-west6-docker.pkg.dev/clear-rock-477020-a0/app/spring-react-crud:latest |
48 | 55 | crane cp --platform=linux/amd64 "$SRC" "$DST" |
49 | 56 |
|
50 | | - # Deploy to Cloud Run |
| 57 | + # 6) Deploy to Cloud Run |
51 | 58 | - name: Deploy to Cloud Run |
52 | 59 | uses: google-github-actions/deploy-cloudrun@v2 |
53 | 60 | with: |
54 | | - service: ${{ env.SERVICE_NAME }} |
55 | | - region: ${{ env.GCP_REGION }} |
56 | | - image: ${{ env.GCP_REGION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE_NAME }}:latest |
| 61 | + service: spring-react-crud |
| 62 | + region: europe-west6 |
| 63 | + image: europe-west6-docker.pkg.dev/clear-rock-477020-a0/app/spring-react-crud:latest |
57 | 64 | flags: | |
58 | 65 | --port=8080 |
59 | 66 | --allow-unauthenticated |
60 | 67 | --memory=512Mi |
61 | 68 | --max-instances=1 |
62 | | - --set-env-vars=SPRING_PROFILES_ACTIVE=${{ env.SPRING_PROFILES_ACTIVE }} |
| 69 | + --set-env-vars=SPRING_PROFILES_ACTIVE=demo |
63 | 70 |
|
64 | 71 | - name: Display Cloud Run URL |
65 | 72 | run: | |
|
0 commit comments