-
Notifications
You must be signed in to change notification settings - Fork 1
179 lines (172 loc) · 6.84 KB
/
main.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: Build and deploy Kafkarator
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
push:
paths-ignore:
- doc/**
- examples/**
- scripts/**
- dashboards/**
env:
GOOGLE_REGISTRY: europe-north1-docker.pkg.dev
IMAGE_REGISTRY: europe-north1-docker.pkg.dev/nais-io/nais/images/kafkarator
FEATURE_REGISTRY: europe-north1-docker.pkg.dev/nais-io/nais/feature
EARTHLY_USE_INLINE_CACHE: true
EARTHLY_SAVE_INLINE_CACHE: true
EARTHLY_VERBOSE: true
EARTHLY_FULL_TARGET: true
EARTHLY_OUTPUT: true
jobs:
version:
name: Set variables
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # ratchet:actions/checkout@v4
- name: "Set image version"
id: constants
run: |
export version="$(date +%Y%m%d%H%M%S)-$(git describe --always --dirty --exclude '*')"
echo "VERSION=${version}" >> ${GITHUB_OUTPUT}
outputs:
version: "${{ steps.constants.outputs.VERSION }}"
build:
name: Build and push
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
needs:
- version
strategy:
fail-fast: false
matrix:
target:
- kafkarator
- canary
- canary-deployer
env:
VERSION: "${{ needs.version.outputs.VERSION }}"
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # ratchet:actions/checkout@v4
- name: Install cosign
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da # ratchet:sigstore/[email protected]
with:
cosign-release: 'v2.2.3'
- name: Verify runner image
run: cosign verify --certificate-identity [email protected] --certificate-oidc-issuer https://accounts.google.com gcr.io/distroless/static-debian11
- id: "auth"
if: github.ref == 'refs/heads/master'
name: "Authenticate to Google Cloud"
uses: "google-github-actions/auth@6fc4af4b145ae7821d527454aa9bd537d1f2dc5f" # ratchet:google-github-actions/[email protected]
with:
workload_identity_provider: ${{ secrets.NAIS_IO_WORKLOAD_IDENTITY_PROVIDER }}
service_account: "[email protected]"
token_format: "access_token"
- name: Login to Google Artifact Registry
if: github.ref == 'refs/heads/master'
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # ratchet:docker/login-action@v2
with:
registry: ${{ env.GOOGLE_REGISTRY }}
username: "oauth2accesstoken"
password: "${{ steps.auth.outputs.access_token }}"
- name: Install earthly
uses: earthly/actions-setup@43211c7a0eae5344d6d79fb4aaf209c8f8866203 # ratchet:earthly/actions-setup@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build and possibly push ${{ matrix.target }}
env:
EARTHLY_PUSH: "${{ github.ref == 'refs/heads/master' }}"
run: |
earthly +docker-${{ matrix.target }} --VERSION=${VERSION} --REGISTRY=${IMAGE_REGISTRY}
- name: Retrieve image digest
id: imgdigest
if: github.ref == 'refs/heads/master'
run: |
export IMAGE=${{ env.IMAGE_REGISTRY }}/${{ matrix.target }}:${VERSION}
docker pull ${IMAGE}
echo "digest=$(docker inspect ${IMAGE} | jq -r '.[].RepoDigests[0]')" >> $GITHUB_OUTPUT
- name: Sign the container image
if: github.ref == 'refs/heads/master'
run: cosign sign --yes ${{ steps.imgdigest.outputs.digest }}
- name: Create SBOM
if: github.ref == 'refs/heads/master'
uses: aquasecurity/trivy-action@18f2510ee396bbf400402947b394f2dd8c87dbb0 # ratchet:aquasecurity/[email protected]
with:
scan-type: 'image'
format: 'cyclonedx'
output: 'cyclone.sbom.json'
image-ref: ${{ steps.imgdigest.outputs.digest }}
- name: Attest image
if: github.ref == 'refs/heads/master'
run: cosign attest --yes --predicate cyclone.sbom.json --type cyclonedx ${{ steps.imgdigest.outputs.digest }}
chart:
permissions:
contents: 'read'
id-token: 'write'
name: Build and push chart
runs-on: ubuntu-latest
needs:
- version
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # ratchet:actions/checkout@v4
- id: 'auth'
name: 'Authenticate to Google Cloud'
if: github.ref == 'refs/heads/master'
uses: 'google-github-actions/auth@6fc4af4b145ae7821d527454aa9bd537d1f2dc5f' # ratchet:google-github-actions/[email protected]
with:
workload_identity_provider: ${{ secrets.NAIS_IO_WORKLOAD_IDENTITY_PROVIDER }}
service_account: '[email protected]'
token_format: 'access_token'
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@6189d56e4096ee891640bb02ac264be376592d6a' # ratchet:google-github-actions/setup-gcloud@v1
- name: 'Log in to Google Artifact Registry'
if: github.ref == 'refs/heads/master'
run: |-
echo '${{ steps.auth.outputs.access_token }}' | docker login -u oauth2accesstoken --password-stdin https://${{ env.GOOGLE_REGISTRY }}
- uses: azure/setup-helm@fe7b79cd5ee1e45176fcad797de68ecaf3ca4814 # ratchet:azure/setup-helm@v3
name: 'Setup Helm'
with:
version: '3.8.0'
- name: Set versions
run: |-
for chart in charts/*; do
yq e '.version = "${{ needs.version.outputs.VERSION }}"' --inplace "${chart}/Chart.yaml"
yq e '.image.tag = "${{ needs.version.outputs.VERSION }}"' --inplace "${chart}/values.yaml"
yq e '.canary.image.tag = "${{ needs.version.outputs.VERSION }}"' --inplace "${chart}/values.yaml"
yq e '.deployer.image.tag = "${{ needs.version.outputs.VERSION }}"' --inplace "${chart}/values.yaml"
done
- name: Build Chart
run: |-
for chart in charts/*; do
helm package "$chart"
done
- name: Push Chart
if: github.ref == 'refs/heads/master'
run: |-
for chart in *.tgz; do
helm push "$chart" oci://${{ env.FEATURE_REGISTRY }}
done
rollout:
name: Rollout
if: github.actor != 'dependabot[bot]' && github.ref == 'refs/heads/master'
needs:
- version
- build
- chart
runs-on: fasit-deploy
permissions:
id-token: write
strategy:
fail-fast: false
matrix:
feature:
- kafkarator
- kafka-canary
- kafka-canary-alert
steps:
- uses: nais/fasit-deploy@v2 # ratchet:exclude
with:
chart: oci://${{ env.FEATURE_REGISTRY }}/${{ matrix.feature }}
version: ${{ needs.version.outputs.VERSION }}