-
-
Notifications
You must be signed in to change notification settings - Fork 11
133 lines (117 loc) · 4.46 KB
/
CD.yml
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: CD
on:
release:
types: [ created ]
schedule:
- cron: '0 6 * * *'
workflow_dispatch:
env:
service_name: todo
concurrency:
group: "cd"
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
pages: write
id-token: write
attestations: write
env:
GRADLE_OPTS: -Dorg.gradle.caching=true
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Get latest release
id: setup-version
uses: hfhbd/actions/setup-version@main
with:
token: ${{ github.token }}
- uses: actions/checkout@v4
with:
ref: ${{ steps.setup-version.outputs.ref }}
- name: Login to GitHub Container Registry
run: echo "${{ github.token }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- id: auth
uses: google-github-actions/auth@v2
with:
workload_identity_provider: projects/963273362268/locations/global/workloadIdentityPools/github-deployment/providers/github
service_account: github-todo@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
token_format: access_token
- name: Login to Google Container Registry
uses: docker/login-action@v3
with:
registry: europe-west4-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
- uses: actions/configure-pages@v5
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21
- uses: gradle/actions/setup-gradle@v4
- name: Push Docker Image to GitHub
run: ./gradlew :backend:jib -PjibImage=ghcr.io/hfhbd/composetodo:${{ steps.setup-version.outputs.version }} --no-configuration-cache
- name: Read GitHub Docker Digest
id: githubDockerDigest
run: echo "digest=$(cat backend/build/jib-image.digest)" >> "$GITHUB_OUTPUT"
- name: Attest
uses: actions/attest-build-provenance@v1
id: attestGitHub
with:
subject-name: ghcr.io/hfhbd/composetodo
subject-digest: ${{ steps.githubDockerDigest.outputs.digest }}
push-to-registry: true
- name: Push Docker Image to Google Container Registry
run: ./gradlew :backend:jib -PjibImage=europe-west4-docker.pkg.dev/${{ secrets.PROJECT_ID }}/composetodo-repo/${{ env.service_name }}:${{ steps.setup-version.outputs.version }} --no-configuration-cache
- name: Read Google Docker Digest
id: googleDockerDigest
run: echo "digest=$(cat backend/build/jib-image.digest)" >> "$GITHUB_OUTPUT"
# - name: Attest
# uses: actions/attest-build-provenance@v1
# id: attestGoogle
# with:
# subject-name: europe-west4-docker.pkg.dev/${{ secrets.PROJECT_ID }}/composetodo-repo/${{ env.service_name }}
# subject-digest: ${{ steps.googleDockerDigest.outputs.digest }}
# push-to-registry: true
- name: Assemble with Gradle
run: ./gradlew :web:jsBrowserDistribution
- uses: actions/upload-pages-artifact@v3
with:
path: web/build/dist/js/productionExecutable
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
googleRun:
needs: build
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Get latest release
id: setup-version
uses: hfhbd/actions/setup-version@main
with:
token: ${{ github.token }}
- uses: actions/checkout@v4
with:
ref: ${{ steps.setup-version.outputs.full-tag }}
- id: auth
uses: google-github-actions/auth@v2
with:
project_id: ${{ secrets.PROJECT_ID }}
workload_identity_provider: projects/963273362268/locations/global/workloadIdentityPools/github-deployment/providers/github
service_account: github-todo@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v2
with:
service: ${{ env.service_name }}
region: europe-west4
image: europe-west4-docker.pkg.dev/${{ secrets.PROJECT_ID }}/composetodo-repo/${{ env.service_name }}:${{ steps.setup-version.outputs.version }}
env_vars: |-
keyID=${{ secrets.CK_KEYID }}
privateKey=${{ secrets.CK_KEY }}