-
Notifications
You must be signed in to change notification settings - Fork 24
233 lines (206 loc) · 8.56 KB
/
Build-Rock.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
224
225
226
227
228
229
230
231
232
233
name: Build rock
on:
workflow_call:
inputs:
# build parameters
oci-archive-name:
description: "Final filename of the rock OCI archive."
type: string
required: true
build-id:
description: "Optional string for identifying workflow jobs in GitHub UI"
type: string
# source parameters
rock-repo:
description: "Public Git repo where to build the rock from."
type: string
required: true
rock-repo-commit:
description: "Git ref from where to build the rock from."
type: string
required: true
rockfile-directory:
description: "Directory in repository where to find the rockcraft.yaml file."
type: string
required: true
# parameters for multi-arch builds
arch-map:
description: "JSON string mapping target architecture to runners."
type: string
default: '{"amd64": ["linux", "X64"], "arm64": ["linux", "ARM64"]}'
lpci-fallback:
description: "Enable fallback to Launchpad build when runners for target arch are not available."
type: boolean
default: false
env:
ROCK_REPO_DIR: rock-repo # path where the image repo is cloned into
ROCK_CI_FOLDER: ci-rocks # path of uploaded/downloaded artifacts
jobs:
configure-build:
# configure-build reads the rockcraft.yaml, creating one or more *-build job runs
# depending on the target architecture.
runs-on: ubuntu-22.04
outputs:
runner-build-matrix: ${{ steps.configure.outputs.runner-build-matrix }}
lpci-build-matrix: ${{ steps.configure.outputs.lpci-build-matrix }}
oci-factory-ref: ${{ steps.workflow-version.outputs.sha }}
name: "configure-build ${{ inputs.build-id != '' && format('| {0}', inputs.build-id) || ' '}}"
steps:
- name: Get Workflow Version
# Note: we may need to pass a github token when working with private repositories.
# https://github.com/canonical/get-workflow-version-action
id: workflow-version
uses: canonical/get-workflow-version-action@v1
with:
repository-name: canonical/oci-factory
file-name: Build-Rock.yaml
- name: Cloning OCI Factory
uses: actions/checkout@v4
with:
repository: canonical/oci-factory
ref: ${{ steps.workflow-version.outputs.sha }}
fetch-depth: 1
- name: Cloning Target Repo
uses: ./.github/actions/checkout
with:
repository: ${{ inputs.rock-repo }}
path: ${{ env.ROCK_REPO_DIR }}
ref: ${{ inputs.rock-repo-commit }}
submodules: "recursive"
- name: Installing Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Installing Python requirements
run: pip install -r src/build_rock/configure/requirements.txt
# Configure matrices for each *-build job
- name: Configuring Jobs
id: configure
run: |
python3 -m src.build_rock.configure.generate_build_matrix \
--rockfile-directory "${{ env.ROCK_REPO_DIR }}/${{ inputs.rockfile-directory }}" \
--lpci-fallback "${{ toJSON(inputs.lpci-fallback) }}" \
--config ${{ toJSON(inputs.arch-map) }} # important: do not use quotes here
runner-build:
# runner-build builds rocks per target architecture using pre configured runner images.
needs: [configure-build]
if: fromJSON(needs.configure-build.outputs.runner-build-matrix).include[0] != ''
strategy:
fail-fast: true
matrix: ${{ fromJSON(needs.configure-build.outputs.runner-build-matrix) }}
runs-on: ${{ github.event_name == 'pull_request' && 'ubuntu-22.04' || matrix.runner }}
name: "runner-build | ${{ matrix.architecture }} ${{ inputs.build-id != '' && format('| {0}', inputs.build-id) || ' '}}"
steps:
- name: Cloning OCI Factory
uses: actions/checkout@v4
with:
repository: canonical/oci-factory
ref: ${{ needs.configure-build.outputs.oci-factory-ref }}
fetch-depth: 1
- name: Cloning Target Repo
uses: ./.github/actions/checkout
with:
repository: ${{ inputs.rock-repo }}
path: ${{ env.ROCK_REPO_DIR }}
ref: ${{ inputs.rock-repo-commit }}
submodules: "recursive"
- name: Building Target
id: rockcraft
uses: canonical/craft-actions/rockcraft-pack@main
with:
path: "${{ env.ROCK_REPO_DIR }}/${{ inputs.rockfile-directory }}"
verbosity: debug
- name: Collecting Artifacts
id: collect-artifacts
run: |
mkdir -p ${{ env.ROCK_CI_FOLDER }} && cp ${{ steps.rockcraft.outputs.rock }} "$_"
echo "filename=$(basename ${{ steps.rockcraft.outputs.rock }})" >> $GITHUB_OUTPUT
- name: Uploading Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.oci-archive-name }}-${{ steps.collect-artifacts.outputs.filename }}
path: ${{ env.ROCK_CI_FOLDER }}
if-no-files-found: error
lpci-build:
# lpci-build is a fallback for building rocks if no suitable runners are
# configured for the required architecture. Builds in this job will be
# outsourced to Launchpad for completion.
# Note the Secret
needs: [configure-build]
if: fromJSON(needs.configure-build.outputs.lpci-build-matrix).include[0] != ''
strategy:
fail-fast: true
matrix: ${{ fromJSON(needs.configure-build.outputs.lpci-build-matrix) }}
runs-on: ubuntu-22.04
name: "lpci-build | ${{ matrix.architecture }} ${{ inputs.build-id != '' && format('| {0}', inputs.build-id) || ' '}}"
steps:
- name: Cloning OCI Factory
uses: actions/checkout@v4
with:
repository: canonical/oci-factory
ref: ${{ needs.configure-build.outputs.oci-factory-ref }}
fetch-depth: 1
- name: Cloning Target Repo
uses: ./.github/actions/checkout
with:
repository: ${{ inputs.rock-repo }}
path: ${{ env.ROCK_REPO_DIR }}
ref: ${{ inputs.rock-repo-commit }}
submodules: "recursive"
- name: Building Target
# TODO: Replace this retry action with bash equivalent for better testing
uses: nick-fields/[email protected]
with:
timeout_minutes: 180
max_attempts: 4
polling_interval_seconds: 5
retry_wait_seconds: 30
command: |
src/build_rock/lpci_build/lpci_build.sh \
-c "${{ secrets.LP_CREDENTIALS_B64 }}" \
-d "${{ env.ROCK_REPO_DIR }}/${{ inputs.rockfile-directory }}"
- name: Collecting Artifacts
id: collect-artifacts
run: |
mkdir -p ${{ env.ROCK_CI_FOLDER }} && cp ${{ env.ROCK_REPO_DIR }}/${{ inputs.rockfile-directory }}/*.rock "$_"
echo "filename=${{ matrix.rock-name }}_${{ matrix.architecture }}" >> $GITHUB_OUTPUT
- name: Uploading Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.oci-archive-name }}-${{ steps.collect-artifacts.outputs.filename }}
path: ${{ env.ROCK_CI_FOLDER }}
if-no-files-found: error
assemble-rock:
# Assemble individual single-arch rocks into multi-arch rocks
needs: [runner-build, lpci-build, configure-build]
runs-on: ubuntu-22.04
# Always run even if one of the *-build jobs are skipped
# Nice example from benjamin-bergia/github-workflow-patterns...
if: ${{ always() && contains(needs.*.result, 'success') && !(contains(needs.*.result, 'failure')) }}
name: "assemble-rock ${{ inputs.build-id != '' && format('| {0}', inputs.build-id) || ' '}}"
steps:
# Job Setup
- name: Cloning OCI Factory
uses: actions/checkout@v4
with:
repository: canonical/oci-factory
ref: ${{ needs.configure-build.outputs.oci-factory-ref }}
fetch-depth: 1
- run: src/build_rock/assemble_rock/requirements.sh
- name: Downloading Single Arch rocks
uses: actions/download-artifact@v4
id: download
with:
path: ${{ env.ROCK_CI_FOLDER }}
pattern: ${{ inputs.oci-archive-name }}-*
- name: Assembling Multi Arch rock
run: |
src/build_rock/assemble_rock/assemble.sh \
-n "${{ inputs.oci-archive-name }}" \
-d "${{ env.ROCK_CI_FOLDER }}"
- name: Uploading Multi Arch rock
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.oci-archive-name }}
path: ${{ inputs.oci-archive-name }}
if-no-files-found: error