Skip to content

Commit f698fc3

Browse files
authored
Adding multi-arch multi-images implementation (#33)
* adding the ubi9 builder and moving all of them under the buildsers directory * Adding builders.json file to use on the workflows * refactor: fixing the push image workflow to iterate over the builders * feat: adding a publish.sh script publishing builder easier * refactor: Updating create release workflow to iterate over the builders * fix: moving options.json to the right location * fix: smoke.sh tests * fix: create-release workflow * fix: chaging permissions for the publish.sh script fix: updating publish.sh script * fix: relase notes fix: release notes path * fix: setting the correct url for uploading artifacts * fix: create release workflow * fix: push image workflow fix: installing crane on push image workflow * fix: push image workflow * fix: ceate relase workflow * doc: Updating readme file with the ubi 9 builder * fix: update-builder workflow * fix: adding files on .syncignore of the scripts * fix: lint failures
1 parent 5a21fe2 commit f698fc3

51 files changed

Lines changed: 3386 additions & 113 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/create-release.yml

Lines changed: 169 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,94 @@ on:
77

88
concurrency: release
99

10+
env:
11+
BUILDERS_FILEPATH: "builders.json"
12+
1013
jobs:
14+
preparation:
15+
name: Preparation
16+
runs-on: ubuntu-24.04
17+
outputs:
18+
builders: ${{ steps.get-builders.outputs.builders }}
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Get Builders
24+
id: get-builders
25+
run: |
26+
builders=$(jq -n -c '[]')
27+
28+
if [ -f ${{ env.BUILDERS_FILEPATH }} ]; then
29+
builders=$(jq -c '.builders' ${{ env.BUILDERS_FILEPATH }})
30+
else
31+
# Strip off the Github org prefix from repo name
32+
# paketo-buildpacks/builder-with-some-name --> builder-with-some-name
33+
registry_repo=$(echo "${{ github.repository }}" | sed 's/^.*\///')
34+
builders=$(jq -n -c '[
35+
{
36+
"name": "default",
37+
"path": ".",
38+
"container_repository": "'"${registry_repo}"'"
39+
}
40+
]')
41+
fi
42+
43+
# Filter only the necessary fields
44+
builders=$(echo "$builders" | jq 'map({
45+
name,
46+
path,
47+
container_repository
48+
})')
49+
50+
builders=$(jq -c <<< "$builders")
51+
echo "builders=$builders"
52+
echo "builders=$builders" >> "$GITHUB_OUTPUT"
53+
54+
builder_files_changed:
55+
name: Builder Files Changed
56+
runs-on: ubuntu-24.04
57+
needs: preparation
58+
outputs:
59+
builders_changed: ${{ steps.compare_previous_release.outputs.builders_changed }}
60+
steps:
61+
- name: Checkout
62+
uses: actions/checkout@v4
63+
with:
64+
fetch-depth: 0 # gets full history
65+
66+
- name: Compare previous releases
67+
id: compare_previous_release
68+
run: |
69+
builders=$(echo '${{ needs.preparation.outputs.builders }}' | jq -c '.[]')
70+
for builder in $builders; do
71+
builder_path=$(echo "$builder" | jq -r '.path')
72+
73+
changed=$(git diff --name-only $(git describe --tags --abbrev=0) -- $builder_path/builder.toml)
74+
if [ -z "${changed}" ]
75+
then
76+
# We do not write on the github output because this step runs multiple times
77+
# and it might overwrite any true value written by the else statement.
78+
echo "No changes for $builder_path/builder.toml"
79+
else
80+
echo "Changes detected for $builder_path/builder.toml"
81+
echo "builders_changed=true" >> $GITHUB_OUTPUT
82+
fi
83+
done
84+
1185
smoke:
1286
name: Smoke Test
1387
runs-on: ubuntu-24.04
88+
needs: [preparation, builder_files_changed]
89+
if: ${{ needs.builder_files_changed.outputs.builders_changed == 'true' }}
90+
strategy:
91+
matrix:
92+
builders: ${{ fromJSON(needs.preparation.outputs.builders) }}
93+
services:
94+
registry:
95+
image: registry:2
96+
ports:
97+
- 5000:5000
1498
outputs:
1599
release_notes: ${{ steps.notes.outputs.body }}
16100
steps:
@@ -34,43 +118,91 @@ jobs:
34118
pack-version: ${{ steps.pack-version.outputs.version }}
35119

36120
- name: Run Smoke Tests
37-
run: ./scripts/smoke.sh --name builder
121+
run: |
122+
./scripts/smoke.sh --builder-dir "${{ matrix.builders.path }}"
38123
39-
- name: Generate Release Notes
124+
- name: Generate builder information
40125
id: notes
41126
run: |
42-
notes="$(pack inspect-builder builder | grep -v 'Inspecting builder' \
127+
registry_builder_name=localhost:5000/${{ matrix.builders.name }}
128+
129+
./scripts/publish.sh --builder-toml-path "${{ matrix.builders.path }}/builder.toml" \
130+
--builder-image-ref "${registry_builder_name}"
131+
132+
pack inspect-builder $registry_builder_name | grep -v 'Inspecting builder' \
43133
| grep -v 'REMOTE:' \
44134
| grep -v 'LOCAL:' \
45135
| grep -v '\(not present\)' \
46-
| grep -v 'Warning' \
47-
| sed -e '/./,$!d' \
48-
| awk -F, '{printf "%s\\n", $0}')"
49-
echo "body=${notes}" >> "$GITHUB_OUTPUT"
136+
| grep -v 'Warning' > "${{ matrix.builders.name }}-information.md"
137+
138+
- name: Upload information for ${{ matrix.builders.name }}
139+
uses: actions/upload-artifact@v4
140+
with:
141+
name: "${{ matrix.builders.name }}-information.md"
142+
path: "${{ matrix.builders.name }}-information.md"
50143

51144
release:
52145
name: Release
53146
runs-on: ubuntu-24.04
54-
needs: smoke
147+
needs: [smoke, preparation]
55148
steps:
56149
- name: Checkout With History
57150
uses: actions/checkout@v4
58151
with:
59152
fetch-depth: 0 # gets full history
60153

61-
- name: Compare With Previous Release
62-
id: compare_previous_release
154+
- name: Download Release Note File(s)
155+
uses: actions/download-artifact@v4
156+
with:
157+
path: information
158+
pattern: "*information.md"
159+
merge-multiple: true
160+
161+
- name: Generate Release Notes and Assets
162+
id: generate_release_notes_and_assets
63163
run: |
64-
if [ -z "$(git diff $(git describe --tags --abbrev=0) -- builder-buildpackless.toml)" ]
65-
then
66-
echo "builder_changes=false" >> "$GITHUB_OUTPUT"
67-
else
68-
echo "builder_changes=true" >> "$GITHUB_OUTPUT"
69-
fi
164+
set -euo pipefail
165+
shopt -s inherit_errexit
166+
167+
builders=$(echo '${{ needs.preparation.outputs.builders }}' | jq -c '.[]')
168+
release_notes_dir="information"
169+
170+
# Start with an empty array
171+
assets=$(jq -n -c '[]')
172+
173+
# Generate release assets
174+
for builder in $builders; do
175+
builder_name=$(echo "$builder" | jq -r '.name')
176+
177+
assets="$(jq -c \
178+
--arg release_notes_dir "${release_notes_dir}" \
179+
--arg builder_name "${builder_name}" \
180+
'. += [
181+
{
182+
"path": ($release_notes_dir + "/" + $builder_name + "-" + "information.md"),
183+
"name": ($builder_name + "-" + "information.md"),
184+
"content_type": "text/markdown"
185+
}
186+
]' <<<"${assets}")"
187+
done
188+
189+
echo "assets=${assets}" >> "$GITHUB_OUTPUT"
190+
191+
# translates 'paketo-buildpacks' to 'paketobuildpacks'
192+
DOCKERHUB_ORG="${GITHUB_REPOSITORY_OWNER/-/}"
193+
194+
# Generate release notes
195+
release_body=""
196+
for builder in $builders; do
197+
container_repository=$(echo "$builder" | jq -r '.container_repository')
198+
release_body+="Builder: \`${DOCKERHUB_ORG}/${container_repository}\`\n"
199+
done
200+
201+
payload="{\"body\" : \"\n${release_body}\"}"
202+
echo "release_body=${payload}" >> "$GITHUB_OUTPUT"
70203
71204
- name: Publish Release
72205
id: publish
73-
if: ${{ steps.compare_previous_release.outputs.builder_changes == 'true' }}
74206
uses: release-drafter/release-drafter@v6
75207
with:
76208
config-name: release-drafter-config.yml
@@ -79,22 +211,38 @@ jobs:
79211
GITHUB_TOKEN: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
80212

81213
- name: Update Release Notes
82-
if: ${{ steps.compare_previous_release.outputs.builder_changes == 'true' }}
83214
run: |
84215
set -euo pipefail
85216
shopt -s inherit_errexit
86217
87-
payload="{\"body\" : \"\`\`\`\n${RELEASE_BODY}\n\`\`\`\"}"
88-
218+
payload='${{ steps.generate_release_notes_and_assets.outputs.release_body }}'
89219
curl --fail \
90220
-X PATCH \
91221
-H "Accept: application/vnd.github.v3+json" \
92222
-H "Authorization: token ${GITHUB_TOKEN}" \
93223
"https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}" \
94224
-d "${payload}"
225+
226+
assets='${{ steps.generate_release_notes_and_assets.outputs.assets }}'
227+
228+
# Update release assets
229+
for row in $(echo "${assets}" | jq -c '.[]'); do
230+
path=$(echo "$row" | jq -r '.path')
231+
name=$(echo "$row" | jq -r '.name')
232+
content_type=$(echo "$row" | jq -r '.content_type')
233+
234+
echo "Uploading asset: ${name} from path: ${path}"
235+
236+
curl -L \
237+
-X POST \
238+
-H "Accept: application/vnd.github.v3+json" \
239+
-H "Authorization: token ${GITHUB_TOKEN}" \
240+
-H "Content-Type: ${content_type}" \
241+
"https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=${name}" \
242+
--data-binary "@${path}"
243+
done
95244
env:
96245
RELEASE_ID: ${{ steps.publish.outputs.id }}
97-
RELEASE_BODY: ${{ needs.smoke.outputs.release_notes }}
98246
GITHUB_TOKEN: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
99247

100248
failure:

.github/workflows/push-image.yml

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,90 @@ on:
55
types:
66
- published
77

8+
env:
9+
BUILDERS_FILEPATH: "builders.json"
10+
811
jobs:
9-
push:
10-
name: Push
12+
preparation:
13+
name: Preparation
1114
runs-on: ubuntu-24.04
15+
outputs:
16+
builders: ${{ steps.get-builders.outputs.builders }}
17+
tag: ${{ steps.event.outputs.tag }}
18+
pack_version: ${{ steps.pack-version.outputs.version }}
1219
steps:
13-
14-
- name: Parse Event
15-
id: event
16-
run: |
17-
echo "tag=$(jq -r '.release.tag_name' "${GITHUB_EVENT_PATH}" | sed s/^v//)" >> "$GITHUB_OUTPUT"
18-
1920
- name: Checkout
2021
uses: actions/checkout@v4
2122

22-
- name: Get pack version
23-
id: pack-version
23+
# TODO: Add the image re on the buiders.json default
24+
- name: Get Builders
25+
id: get-builders
2426
run: |
25-
version=$(jq -r .pack "scripts/.util/tools.json")
26-
echo "version=${version#v}" >> "$GITHUB_OUTPUT"
27+
builders=$(jq -n -c '[]')
2728
28-
- name: Install Global Pack
29-
uses: buildpacks/github-actions/setup-pack@main
30-
with:
31-
pack-version: ${{ steps.pack-version.outputs.version }}
29+
if [ -f ${{ env.BUILDERS_FILEPATH }} ]; then
30+
builders=$(jq -c '.builders' ${{ env.BUILDERS_FILEPATH }})
31+
else
32+
# Strip off the Github org prefix from repo name
33+
# paketo-buildpacks/builder-with-some-name --> builder-with-some-name
34+
registry_repo=$(echo "${{ github.repository }}" | sed 's/^.*\///')
35+
builders=$(jq -n -c '[
36+
{
37+
"name": "default",
38+
"path": ".",
39+
"container_repository": "'"${registry_repo}"'"
40+
}
41+
]')
42+
fi
3243
44+
# Filter only the necessary fields
45+
builders=$(echo "$builders" | jq 'map({
46+
name,
47+
path,
48+
container_repository
49+
})')
3350
34-
- name: Install crane
51+
builders=$(jq -c <<< "$builders")
52+
echo "builders=$builders"
53+
echo "builders=$builders" >> "$GITHUB_OUTPUT"
54+
55+
- name: Parse Event
56+
id: event
3557
run: |
36-
VERSION=$(curl -s "https://api.github.com/repos/google/go-containerregistry/releases/latest" | jq -r '.tag_name')
37-
OS=Linux
38-
ARCH=x86_64
39-
curl -sL "https://github.com/google/go-containerregistry/releases/download/${VERSION}/go-containerregistry_${OS}_${ARCH}.tar.gz" > go-containerregistry.tar.gz
58+
echo "tag=$(jq -r '.release.tag_name' "${GITHUB_EVENT_PATH}" | sed s/^v//)" >> "$GITHUB_OUTPUT"
4059
41-
tar -zxvf go-containerregistry.tar.gz -C "${HOME}/bin" crane
42-
chmod +x "${HOME}/bin/crane"
60+
push:
61+
name: Push
62+
needs: preparation
63+
runs-on: ubuntu-24.04
64+
strategy:
65+
matrix:
66+
builders: ${{ fromJSON(needs.preparation.outputs.builders) }}
67+
steps:
4368

44-
- name: Enable Experimental Pack Features
45-
run: |
46-
if [ -f "scripts/options.json" ] && jq -e -r .pack_config_enable_experimental "scripts/options.json" > /dev/null; then
47-
pack config experimental true
48-
fi
69+
- name: Checkout
70+
uses: actions/checkout@v4
4971

5072
- name: Create Builder Image and Push To Dockerhub
5173
env:
5274
PAKETO_BUILDPACKS_DOCKERHUB_USERNAME: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_USERNAME }}
5375
PAKETO_BUILDPACKS_DOCKERHUB_PASSWORD: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_PASSWORD }}
5476
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
5577
run: |
78+
# shellcheck source=./scripts/.util/tools.sh
79+
source "./scripts/.util/tools.sh"
80+
81+
util::tools::crane::install --directory "./.bin"
82+
5683
DOCKERHUB_ORG="${GITHUB_REPOSITORY_OWNER/-/}" # translates 'paketo-buildpacks' to 'paketobuildpacks'
57-
registry_repo="ubi-9-builder-buildpackless"
84+
container_repository=${{ matrix.builders.container_repository }}
5885
5986
echo "${PAKETO_BUILDPACKS_DOCKERHUB_PASSWORD}" | docker login --username "${PAKETO_BUILDPACKS_DOCKERHUB_USERNAME}" --password-stdin
60-
pack builder create "${DOCKERHUB_ORG}/${registry_repo}:${{ steps.event.outputs.tag }}" --config builder-buildpackless.toml --publish
61-
crane copy "${DOCKERHUB_ORG}/${registry_repo}:${{ steps.event.outputs.tag }}" "${DOCKERHUB_ORG}/${registry_repo}:latest"
87+
88+
./scripts/publish.sh --builder-toml-path "${{ matrix.builders.path }}/builder.toml" \
89+
--builder-image-ref "${DOCKERHUB_ORG}/${container_repository}:${{ needs.preparation.outputs.tag }}"
90+
91+
./.bin/crane copy "${DOCKERHUB_ORG}/${container_repository}:${{ needs.preparation.outputs.tag }}" "${DOCKERHUB_ORG}/${container_repository}:latest"
6292
6393
failure:
6494
name: Alert on Failure

0 commit comments

Comments
 (0)