forked from PowerDNS/pdns
-
Notifications
You must be signed in to change notification settings - Fork 0
254 lines (247 loc) · 11.6 KB
/
build-packages.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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
---
name: Build packages
on:
workflow_call:
inputs:
product:
required: true
description: Product to build
type: string
os:
required: false
description: OSes to build for, space separated
type: string
# please remember to update the pkghashes below when you
# update this list, as well as the one in builder-dispatch.yml
default: >-
el-7
el-8
el-9
debian-buster
debian-bullseye
debian-bookworm
ubuntu-focal
ubuntu-jammy
ubuntu-noble
ref:
description: git ref to checkout
type: string
default: master
required: false
is_release:
description: is this a release build?
type: string
required: false
default: 'NO'
secrets:
DOWNLOADS_AUTOBUILT_SECRET:
required: true
DOWNLOADS_AUTOBUILT_RSYNCTARGET:
required: true
DOWNLOADS_AUTOBUILT_HOSTKEY:
required: true
permissions: # least privileges, see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
contents: read
jobs:
prepare:
name: generate OS list
runs-on: ubuntu-22.04
outputs:
oslist: ${{ steps.get-oslist.outputs.oslist }}
steps:
# instead of jo, we could use jq here, which avoids running apt, and thus would be faster.
# but, as this whole workflow needs at least 30 minutes to run, I prefer spending a few seconds here
# so that the command remains readable, because jo is simpler to use.
- run: sudo apt-get update && sudo apt-get -y install jo
- id: get-oslist
run: echo "oslist=$(jo -a ${{ inputs.os }})" >> "$GITHUB_OUTPUT"
build:
needs: prepare
name: ${{ inputs.product }} (${{ inputs.ref }}) on ${{ matrix.runner-os }} for ${{ matrix.os }}
runs-on: ${{ matrix.runner-os }}
strategy:
matrix:
os: ${{fromJson(needs.prepare.outputs.oslist)}}
runner-os:
- ubuntu-22.04
- ubicloud-standard-2-arm
exclude:
- os: el-7
runner-os: ubicloud-standard-2-arm
fail-fast: false
outputs:
product-name: ${{ steps.normalize-name.outputs.normalized-package-name }}
version: ${{ steps.getversion.outputs.version }}
pkghashes-el-7-x86_64: ${{ steps.pkghashes.outputs.pkghashes-el-7-x86_64 }}
pkghashes-el-8-x86_64: ${{ steps.pkghashes.outputs.pkghashes-el-8-x86_64 }}
pkghashes-el-8-aarch64: ${{ steps.pkghashes.outputs.pkghashes-el-8-aarch64 }}
pkghashes-el-9-x86_64: ${{ steps.pkghashes.outputs.pkghashes-el-9-x86_64 }}
pkghashes-el-9-aarch64: ${{ steps.pkghashes.outputs.pkghashes-el-9-aarch64 }}
pkghashes-debian-buster-x86_64: ${{ steps.pkghashes.outputs.pkghashes-debian-buster-x86_64 }}
pkghashes-debian-buster-aarch64: ${{ steps.pkghashes.outputs.pkghashes-debian-buster-aarch64 }}
pkghashes-debian-bullseye-x86_64: ${{ steps.pkghashes.outputs.pkghashes-debian-bullseye-x86_64 }}
pkghashes-debian-bullseye-aarch64: ${{ steps.pkghashes.outputs.pkghashes-debian-bullseye-aarch64 }}
pkghashes-debian-bookworm-x86_64: ${{ steps.pkghashes.outputs.pkghashes-debian-bookworm-x86_64 }}
pkghashes-debian-bookworm-aarch64: ${{ steps.pkghashes.outputs.pkghashes-debian-bookworm-aarch64 }}
pkghashes-ubuntu-focal-x86_64: ${{ steps.pkghashes.outputs.pkghashes-ubuntu-focal-x86_64 }}
pkghashes-ubuntu-focal-aarch64: ${{ steps.pkghashes.outputs.pkghashes-ubuntu-focal-aarch64 }}
pkghashes-ubuntu-jammy-x86_64: ${{ steps.pkghashes.outputs.pkghashes-ubuntu-jammy-x86_64 }}
pkghashes-ubuntu-jammy-aarch64: ${{ steps.pkghashes.outputs.pkghashes-ubuntu-jammy-aarch64 }}
pkghashes-ubuntu-noble-x86_64: ${{ steps.pkghashes.outputs.pkghashes-ubuntu-noble-x86_64 }}
pkghashes-ubuntu-noble-aarch64: ${{ steps.pkghashes.outputs.pkghashes-ubuntu-noble-aarch64 }}
srchashes: ${{ steps.srchashes.outputs.srchashes }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # for correct version numbers
submodules: recursive
ref: ${{ inputs.ref }}
# this builds packages and runs our unit tests (make check)
- run: IS_RELEASE=${{ inputs.is_release}} builder/build.sh -v -m ${{ inputs.product }} ${{ matrix.os }}
- name: Get version number
run: |
echo "version=$(readlink builder/tmp/latest)" >> $GITHUB_OUTPUT
id: getversion
- name: Get target architecture
run: |
echo "target-arch=$(uname -m)" >> $GITHUB_OUTPUT
id: getarch
- name: Normalize package name
id: normalize-name
run: |
if [ "x${{ inputs.product }}" = "xauthoritative" ]; then
echo "normalized-package-name=pdns" >> $GITHUB_OUTPUT
elif [ "x${{ inputs.product }}" = "xrecursor" ]; then
echo "normalized-package-name=pdns-recursor" >> $GITHUB_OUTPUT
else
echo "normalized-package-name=${{ inputs.product }}" >> $GITHUB_OUTPUT
fi
- name: Include architecture in the packages compressed file name
run: for f in $(ls ./built_pkgs/*/*/*-${{ matrix.os }}.tar.bz2 | sed 's/\.tar.bz2$//'); do mv $f.tar.bz2 $f-${{ steps.getarch.outputs.target-arch }}.tar.bz2; done
- name: Upload packages as GH artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.product }}-${{ matrix.os }}-${{ steps.getversion.outputs.version }}-${{ steps.getarch.outputs.target-arch }}
path: built_pkgs/
retention-days: 7
- name: Extract packages from the tarball
# so we get provenance for individual packages (and the JSON package manifests from the builder)
id: extract
run: |
mkdir -m 700 -p ./packages/
tar xvf ./built_pkgs/*/*/${{ steps.normalize-name.outputs.normalized-package-name }}-${{ steps.getversion.outputs.version }}-${{ matrix.os }}-${{ steps.getarch.outputs.target-arch }}.tar.bz2 -C ./packages/ --transform='s/.*\///'
- name: Generate package hashes for provenance
shell: bash
id: pkghashes
run: |
echo "pkghashes-${{ matrix.os }}-${{ steps.getarch.outputs.target-arch }}=$(sha256sum ./packages/*.rpm ./packages/*.deb ./packages/*.json | base64 -w0)" >> $GITHUB_OUTPUT
- name: Generate source hash for provenance
shell: bash
id: srchashes
run: |
echo "srchashes=$(sha256sum ./built_pkgs/*/*/${{ steps.normalize-name.outputs.normalized-package-name }}-${{ steps.getversion.outputs.version }}.tar.bz2 | base64 -w0)" >> $GITHUB_OUTPUT
- name: Upload packages to downloads.powerdns.com
env:
SSHKEY: ${{ secrets.DOWNLOADS_AUTOBUILT_SECRET }}
RSYNCTARGET: ${{ secrets.DOWNLOADS_AUTOBUILT_RSYNCTARGET }}
HOSTKEY: ${{ secrets.DOWNLOADS_AUTOBUILT_HOSTKEY }}
if:
"${{ env.SSHKEY != '' }}"
run: |
mkdir -m 700 -p ~/.ssh
echo "$SSHKEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
echo "$HOSTKEY" > ~/.ssh/known_hosts
rsync -4rlptD built_pkgs/* "$RSYNCTARGET"
check-hashes:
needs: build
name: Check if hashes were created for all requested targets
runs-on: ubuntu-22.04
steps:
- name: Get list of outputs from build jobs
run: echo '${{ toJSON(needs.build.outputs) }}' | jq 'keys[]' | grep -vE 'version|product-name' | tee /tmp/build-outputs.txt
- name: Get list of OS inputs
run: |
for os in ${{ inputs.os }}; do
for architecture in x86_64 aarch64; do
[[ "$os" != "el-7" || "$architecture" != "aarch64" ]] && echo "\"pkghashes-$os-$architecture\"" | tee -a /tmp/os-inputs.txt
done
done
sort -o /tmp/os-inputs.txt /tmp/os-inputs.txt
echo "\"srchashes\"" | tee -a /tmp/os-inputs.txt
- name: Fail if there is a hash missing
run: if ! diff -q /tmp/build-outputs.txt /tmp/os-inputs.txt; then exit 1; fi
provenance-pkgs:
needs: [prepare, build]
name: Generate provenance for ${{ inputs.product }} (${{ inputs.ref }}) for ${{ matrix.os }}
strategy:
matrix:
os: ${{fromJson(needs.prepare.outputs.oslist)}}
architecture: ['x86_64', 'aarch64']
exclude:
- os: el-7
architecture: aarch64
permissions:
actions: read # To read the workflow path.
id-token: write # To sign the provenance.
contents: write # To be able to upload assets as release artifacts
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
base64-subjects: "${{ needs.build.outputs[format('pkghashes-{0}-{1}', matrix.os, matrix.architecture)] }}"
upload-assets: false
provenance-name: "${{ inputs.product }}-${{ needs.build.outputs.version }}-${{ matrix.os }}-${{ matrix.architecture }}.intoto.jsonl"
private-repository: true
provenance-src:
needs: build
name: Generate provenance for ${{ inputs.product }} (${{ inputs.ref }}) source tarball
permissions:
actions: read # To read the workflow path.
id-token: write # To sign the provenance.
contents: write # To be able to upload assets as release artifacts
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
base64-subjects: "${{ needs.build.outputs.srchashes }}"
upload-assets: false
provenance-name: "${{ inputs.product }}-${{ needs.build.outputs.version }}-src.intoto.jsonl"
private-repository: true
upload-provenance:
needs: [prepare, build, provenance-src, provenance-pkgs]
name: Upload the provenance artifacts to downloads.powerdns.com
runs-on: ubuntu-22.04
strategy:
matrix:
os: ${{fromJson(needs.prepare.outputs.oslist)}}
architecture: ['x86_64', 'aarch64']
exclude:
- os: el-7
architecture: aarch64
steps:
- name: Download source tarball provenance for ${{ inputs.product }} (${{ inputs.ref }})
id: download-src-provenance
uses: actions/download-artifact@v4 # be careful, this needs to match what https://github.com/slsa-framework/slsa-github-generator is using
with:
name: "${{ inputs.product }}-${{ needs.build.outputs.version }}-src.intoto.jsonl"
- name: Download provenance for ${{ inputs.product }} (${{ inputs.ref }}) for ${{ matrix.os }}
id: download-provenance
uses: actions/download-artifact@v4 # be careful, this needs to match what https://github.com/slsa-framework/slsa-github-generator is using
with:
name: "${{ inputs.product }}-${{ needs.build.outputs.version }}-${{ matrix.os }}-${{ matrix.architecture }}.intoto.jsonl"
- name: Upload provenance artifacts to downloads.powerdns.com
id: upload-provenance
env:
SSHKEY: ${{ secrets.DOWNLOADS_AUTOBUILT_SECRET }}
RSYNCTARGET: ${{ secrets.DOWNLOADS_AUTOBUILT_RSYNCTARGET }}
HOSTKEY: ${{ secrets.DOWNLOADS_AUTOBUILT_HOSTKEY }}
PRODUCT: ${{ needs.build.outputs.product-name }}
VERSION: ${{ needs.build.outputs.version }}
if:
"${{ env.SSHKEY != '' }}"
shell: bash
run: |
mkdir -m 700 -p ~/.ssh
echo "$SSHKEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
echo "$HOSTKEY" > ~/.ssh/known_hosts
mkdir -m 755 -p "slsa/${PRODUCT}/${VERSION}/"
mv ${{steps.download-provenance.outputs.download-path}}/*.jsonl "slsa/${PRODUCT}/${VERSION}"
rsync -4rlptD slsa/* "$RSYNCTARGET"