-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (75 loc) · 2.78 KB
/
Copy pathbuild.yml
File metadata and controls
86 lines (75 loc) · 2.78 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
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
79
80
81
82
83
84
85
86
name: Build container
on:
workflow_run:
workflows: [ CI ]
types: [ completed ]
branches: [ main ]
workflow_dispatch:
jobs:
build:
if: >-
${{ github.event_name == 'workflow_dispatch' ||
github.event.workflow_run.conclusion == 'success' }}
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
REGION: europe-west1
IMAGE_NAME: feeds # change if you ever rename the image
AR_REPO: containers
COMMIT_SHA: ${{ github.event.workflow_run.head_sha || github.sha }}
outputs:
digest: ${{ steps.getdigest.outputs.digest }}
steps:
- name: Checkout
uses: actions/checkout@v7
with:
ref: ${{ env.COMMIT_SHA }}
- id: auth
name: Google Auth (WIF)
uses: google-github-actions/auth@v3
with:
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_ID_PROVIDER }}
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
create_credentials_file: true
- name: Setup gcloud
uses: google-github-actions/setup-gcloud@v3
- name: Configure gcloud
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.auth.outputs.credentials_file_path }}
CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE: ${{ steps.auth.outputs.credentials_file_path }}
run: |
gcloud config set project "${PROJECT_ID}"
gcloud config set run/region "${REGION}"
- name: Build & push (bin/build_container)
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.auth.outputs.credentials_file_path }}
CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE: ${{ steps.auth.outputs.credentials_file_path }}
PROJECT_ID: ${{ env.PROJECT_ID }}
REGION: ${{ env.REGION }}
IMAGE_NAME: ${{ env.IMAGE_NAME }}
AR_REPO: ${{ env.AR_REPO }}
TAG: ${{ env.COMMIT_SHA }} # deterministic tag for the tested commit
run: |
chmod +x bin/build_container
bin/build_container
echo "Built image: $(cat image_ref.txt)"
- id: getdigest
name: Get image digest (immutable)
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.auth.outputs.credentials_file_path }}
CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE: ${{ steps.auth.outputs.credentials_file_path }}
run: |
IMAGE_REF="$(cat image_ref.txt)"
DIGEST="$(gcloud artifacts docker images describe "$IMAGE_REF" \
--format='value(image_summary.digest)')"
echo "digest=$DIGEST" >> "$GITHUB_OUTPUT"
echo "Resolved digest: $DIGEST"
deploy:
needs: build
uses: ./.github/workflows/deploy.yml
with:
digest: ${{ needs.build.outputs.digest }}
secrets: inherit