-
Notifications
You must be signed in to change notification settings - Fork 3
223 lines (188 loc) · 7.83 KB
/
go-base.yaml
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
name: go-base
env :
image_tag: v1
on:
push:
jobs:
prepare-go-dev:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run Prepare Action
uses: buildsafedev/multiarch-build--action/prepare-action@main
with:
oci_registry_username: ${{ secrets.DOCKER_USERNAME }}
oci_registry_password: ${{ secrets.DOCKER_PASSWORD }}
image_name: holiodin01/go-base-dev
ociBlock: go-dev
tag: ${{ env.image_tag }}
prepare-go-runtime:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run Prepare Action
uses: buildsafedev/multiarch-build--action/prepare-action@main
with:
oci_registry_username: ${{ secrets.DOCKER_USERNAME }}
oci_registry_password: ${{ secrets.DOCKER_PASSWORD }}
image_name: holiodin01/go-base-runtime
ociBlock: go-runtime
tag: ${{ env.image_tag }}
# Build the oci images for dev and runtime
build:
needs : [prepare-go-dev, prepare-go-runtime]
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, linux-arm64]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run Build Action
uses: buildsafedev/multiarch-build--action/build-action@main
with:
oci_registry_username: ${{ secrets.DOCKER_USERNAME }}
oci_registry_password: ${{ secrets.DOCKER_PASSWORD }}
ociBlocks: go-dev go-runtime
directory: 'go-server-example'
# This pirticular job is used to merge the development image of arm64 and amd64
merge-dev:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run Merge Action
uses: buildsafedev/multiarch-build--action/merge-action@main
with:
oci_registry_username: ${{ secrets.DOCKER_USERNAME }}
oci_registry_password: ${{ secrets.DOCKER_PASSWORD }}
image_name: holiodin01/go-base-dev
ociBlock: go-dev
tag: ${{ env.image_tag }}
merge-runtime:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run Merge Action
uses: buildsafedev/multiarch-build--action/merge-action@main
with:
oci_registry_username: ${{ secrets.DOCKER_USERNAME }}
oci_registry_password: ${{ secrets.DOCKER_PASSWORD }}
image_name: holiodin01/go-base-runtime
ociBlock: go-runtime
tag: ${{ env.image_tag }}
sign-the-image:
needs: [merge-dev, merge-runtime]
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Install Cosign
uses: sigstore/cosign-installer@v3.7.0
with:
cosign-release: 'v2.4.1'
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Sign and push image
env:
COSIGN_EXPERIMENTAL: "true"
run: |
base_img_digest=$(docker manifest inspect holiodin01/go-base-dev:${image_tag} | jq -r '.manifests[] | select(.platform.architecture == "amd64") | .digest')
runtime_img_digest=$(docker manifest inspect holiodin01/go-base-runtime:${image_tag} | jq -r '.manifests[] | select(.platform.architecture == "amd64") | .digest')
cosign sign --yes holiodin01/go-base-dev@${base_img_digest}
cosign verify \
--certificate-identity "https://github.com/buildsafedev/examples/.github/workflows/go-base.yaml@refs/heads/multiarch-builds" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
holiodin01/go-base-dev@${base_img_digest}
cosign triangulate holiodin01/go-base-dev@${base_img_digest}
# Sign and verify the runtime image
cosign sign --yes holiodin01/go-base-runtime@${runtime_img_digest}
cosign verify \
--certificate-identity "https://github.com/buildsafedev/examples/.github/workflows/go-base.yaml@refs/heads/multiarch-builds" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
holiodin01/go-base-runtime@${runtime_img_digest}
cosign triangulate holiodin01/go-base-runtime@${runtime_img_digest}
hermetic_builds:
needs: [merge-dev, merge-runtime]
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name : Build hermetic image
working-directory: go-server-example
run: |
# Use command substitution to assign the digests
base_img_digest=$(docker manifest inspect holiodin01/go-base-dev:${{ env.image_tag }} | jq -r '.manifests[] | select(.platform.architecture == "amd64") | .digest')
runtime_img_digest=$(docker manifest inspect holiodin01/go-base-runtime:${{ env.image_tag }} | jq -r '.manifests[] | select(.platform.architecture == "amd64") | .digest')
docker buildx create --name mybuilder --use --driver docker-container
docker buildx build \
--build-arg BASE_IMAGE=holiodin01/go-base-dev@${base_img_digest} \
--build-arg RUNTIME_IMAGE=holiodin01/go-base-runtime@${runtime_img_digest} \
--no-cache \
--tag holiodin01/go-final:${{ env.image_tag }} \
--network=none \
--attest type=provenance,mode=min \
--platform=linux/amd64 \
--push \
--output type=oci \
https://github.com/buildsafedev/examples.git\#multiarch-builds:go-server-example
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
# Setup Nix development environment make sure to use ./ before the path otherwise nix takes it as a https url
- name: Setup Nix development environment
uses: nicknovitski/nix-develop@v1
with:
arguments: ./go-server-example/bsf/.#devShell
- name: Is hermetic build
run: |
docker buildx imagetools inspect holiodin01/go-final:${{ env.image_tag }} --format "{{ json .Provenance.SLSA }}" > slsa.json
cat slsa.json
if grep -q "https://mobyproject.org/buildkit@v1#hermetic\": true" slsa.json; then
echo "Hermetic build"
else
echo "Not a hermetic build"
fi
# Check for vulnerabilities :)
- name: Check for vulnerabilities
run: grype holiodin01/go-final:${{ env.image_tag }} --only-fixed --fail-on high
sign-final-image:
needs: hermetic_builds
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Install Cosign
uses: sigstore/cosign-installer@v3.7.0
with:
cosign-release: 'v2.4.1'
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Sign and push image
env:
COSIGN_EXPERIMENTAL: "true"
run: |
cosign sign --yes holiodin01/go-final:${{ env.image_tag }}
cosign verify \
--certificate-identity "https://github.com/buildsafedev/examples/.github/workflows/go-base.yaml@refs/heads/multiarch-builds" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
holiodin01/go-final:${{ env.image_tag }}
cosign triangulate holiodin01/go-final:${{ env.image_tag }}