Skip to content

Commit 8b3ad8d

Browse files
committed
Use native arm runner for github CI
1 parent f7fb382 commit 8b3ad8d

File tree

6 files changed

+288
-260
lines changed

6 files changed

+288
-260
lines changed
Lines changed: 38 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,69 @@
11
---
22
name: Build Base Images
33
description: Build the base images (pulp/base & pulp/pulp-ci-centos9) if needed
4-
# Both ARM64 & x86-64 versions of each are built
5-
# Use hashFiles(base_image_files, pulp-ci_image_files) as the key to the cache
4+
# Use hashFiles(base_image_files, pulp-ci_image_files) for rebuild check
5+
inputs:
6+
image_variants:
7+
description: "Whether build is nightly or stable, nightly never rebuilds"
8+
default: "stable"
9+
required: true
610
outputs:
7-
base_cache_key:
8-
value: ${{ steps.hash_key.outputs.base_cache_key }}
9-
description: "The cache key the built images were uploaded to."
1011
rebuilt_images:
11-
value: ${{ env.BUILD_IMAGES }}
12-
description: "The images that were rebuilt or empty"
12+
value: ${{ steps.rebuild_needed.outputs.build }}
13+
description: "true/false if the base images were rebuilt"
1314

1415
runs:
1516
using: "composite"
1617
steps:
1718
- uses: actions/checkout@v4
1819

1920
- name: Calculate base images hash
20-
id: hash_key
2121
run: |
2222
hash=${{ hashFiles('images/Containerfile.core.base', 'images/pulp_ci_centos/Containerfile', 'images/assets/**', 'images/s6_assets/**') }}
2323
echo "base image hash is ${hash}"
24-
echo "base_cache_key=${hash}" >> $GITHUB_OUTPUT
24+
echo "HASH=${hash}" >> $GITHUB_ENV
2525
shell: bash
2626

27-
- name: Restore previously cached images
28-
id: cache
29-
uses: actions/cache/restore@v3
30-
with:
31-
key: base-images=${{ steps.hash_key.outputs.base_cache_key }}
32-
path: base-images.tar.gz
27+
- name: Set up oras
28+
uses: oras-project/setup-oras@v1
3329

34-
- name: Extract images if cached
35-
if: steps.cache.outputs.cache-hit == 'true'
30+
- name: Check for updates on base images
31+
id: rebuild_needed
3632
run: |
37-
echo "Base Images were in cache"
38-
podman load -i base-images.tar.gz
39-
shell: bash
40-
41-
- name: Check for updates on cached images
42-
if: steps.cache.outputs.cache-hit == 'true'
43-
run: |
44-
# Enable running/building ARM64 images: https://github.com/multiarch/qemu-user-static
45-
sudo podman run --rm --privileged multiarch/qemu-user-static --reset -p yes
46-
IMAGES=()
47-
for ARCH in arm64 amd64; do
48-
echo "Checking if rebuild needed for base:${ARCH} & pulp-ci-centos9:${ARCH}"
49-
if ! podman run --pull=never pulp/base:ci-${ARCH} bash -c "dnf check-upgrade"; then
50-
echo "Rebuild needed for base:${ARCH} & pulp-ci-centos9:${ARCH}"
51-
IMAGES+=("base:${ARCH}" "pulp-ci-centos9:${ARCH}")
52-
elif ! podman run --pull=never pulp/pulp-ci-centos9:ci-${ARCH} bash -c "dnf check-upgrade"; then
53-
echo "Rebuild needed for just pulp-ci-centos9:${ARCH}"
54-
IMAGES+=("pulp-ci-centos9:${ARCH}")
55-
fi
56-
done
57-
if [ ${#IMAGES[@]} -eq 0 ]; then
58-
echo "No rebuilds needed :)"
33+
if [[ "${{ inputs.image_variants }}" == "nightly" ]]; then
34+
build=false
5935
else
60-
echo "BUILD_IMAGES=[$(echo ${IMAGES[@]@Q} | sed 's/ /, /g')]" >> $GITHUB_ENV
36+
branch=${{ github.base_ref || github.ref_name }}
37+
config=$(oras manifest fetch-config --platform linux/amd64 ghcr.io/pulp/pulp-ci-centos9:${branch} | jq -r '.config.Labels')
38+
latest_hash=$(echo "${config}" | jq -r '."org.pulp.basefiles-hash"')
39+
build=true
40+
if [[ "${latest_hash}" == "${HASH}" ]]; then
41+
if podman run ghcr.io/pulp/pulp-ci-centos9:${branch} bash -c "dnf check-upgrade"; then
42+
echo "No base images rebuild needed :)"
43+
build=false
44+
fi
45+
fi
6146
fi
47+
echo "build=${build}" >> "$GITHUB_OUTPUT"
48+
echo "Going to rebuild: ${build}"
6249
shell: bash
6350

64-
- name: Set images to build on cache miss
65-
if: steps.cache.outputs.cache-hit != 'true'
51+
- name: Download base images if no rebuild needed
52+
if: steps.rebuild_needed.outputs.build == 'false'
6653
run: |
67-
echo "BUILD_IMAGES=['base:arm64', 'base:amd64', 'pulp-ci-centos9:arm64', 'pulp-ci-centos9:amd64']" >> $GITHUB_ENV
68-
sudo podman run --rm --privileged multiarch/qemu-user-static --reset -p yes
54+
echo "Downloading base images"
55+
branch=${{ github.base_ref || github.ref_name }}
56+
podman pull ghcr.io/pulp/base:${branch}
57+
podman pull ghcr.io/pulp/pulp-ci-centos9:${branch}
58+
podman tag ghcr.io/pulp/base:${branch} pulp/base:ci
59+
podman tag ghcr.io/pulp/pulp-ci-centos9:${branch} pulp/pulp-ci-centos9:ci
6960
shell: bash
7061

7162
- name: Build images
72-
if: env.BUILD_IMAGES
63+
if: steps.rebuild_needed.outputs.build == 'true'
7364
run: |
74-
IMAGES=(${{ join(fromJSON(env.BUILD_IMAGES), ' ') }})
75-
echo "Going to build images: ${IMAGES[@]}"
7665
podman version
7766
buildah version
78-
for IMAGE in "${IMAGES[@]}"; do
79-
echo "Building image ${IMAGE}"
80-
ARCH=${IMAGE##*:}
81-
case $IMAGE in
82-
base:*)
83-
podman build --platform "linux/${ARCH}" --format docker --file images/Containerfile.core.base --tag "pulp/base:ci-${ARCH}" .
84-
;;
85-
pulp-ci-centos9:*)
86-
podman build --platform "linux/${ARCH}" --format docker --file images/pulp_ci_centos/Containerfile --tag "pulp/pulp-ci-centos9:ci-${ARCH}" --build-arg FROM_TAG="ci-${ARCH}" .
87-
;;
88-
esac
89-
done
67+
podman build --format docker --file images/Containerfile.core.base --tag "pulp/base:ci" --label "org.pulp.basefiles-hash=${HASH}" .
68+
podman build --format docker --file images/pulp_ci_centos/Containerfile --tag "pulp/pulp-ci-centos9:ci" --build-arg FROM_TAG="ci" .
9069
shell: bash
91-
# we use the docker format (default), even though it may not be the fastest,
92-
# because it supports saving both images at once.
93-
# However, it seems to export the common layers twice.
94-
# We should look into whether its possible to export just pulp-ci-centos,
95-
# and tag the base image manually.
96-
- name: Save podman images to tarball
97-
if: env.BUILD_IMAGES
98-
run: |
99-
rm -f base-images.tar.gz
100-
podman save -m -o base-images.tar pulp/base:ci-arm64 pulp/base:ci-amd64 pulp/pulp-ci-centos9:ci-arm64 pulp/pulp-ci-centos9:ci-amd64
101-
gzip base-images.tar
102-
shell: bash
103-
104-
- name: Clear cache for next upload
105-
if: env.BUILD_IMAGES && steps.cache.outputs.cache-hit == 'true' && github.event_name != 'pull_request'
106-
run: |
107-
echo "Deleting existing cache for ${{ steps.hash_key.outputs.base_cache_key }}"
108-
gh cache delete "base-images=${{ steps.hash_key.outputs.base_cache_key }}" -R ${{ github.repository }}
109-
shell: bash
110-
111-
- name: Cache podman images
112-
if: env.BUILD_IMAGES
113-
uses: actions/cache/save@v3
114-
with:
115-
key: base-images=${{ steps.hash_key.outputs.base_cache_key }}
116-
path: base-images.tar.gz

.github/actions/build_image/action.yml

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@ inputs:
99
image_name:
1010
description: 'Name of the image to be built'
1111
required: true
12-
image_cache_key:
13-
description: 'The key value used to store the base images in the cache'
14-
required: true
1512
latest_ui:
1613
description: 'Use the latest pulp-ui when building the image'
1714
default: 'false'
1815
required: false
19-
built_base_images:
20-
description: 'A JSON list of the base-images that were freshly rebuilt prior'
16+
rebuilt_base_images:
17+
description: 'true/false if the base images were rebuilt prior'
2118
required: true
2219
outputs:
2320
app_version:
@@ -47,17 +44,6 @@ runs:
4744
- name: Set up oras
4845
uses: oras-project/setup-oras@v1
4946

50-
- name: Restore podman images from cache
51-
uses: actions/cache/restore@v4
52-
with:
53-
key: base-images=${{ inputs.image_cache_key }}
54-
path: base-images.tar.gz
55-
56-
- name: Load podman images from tarball
57-
run: |
58-
podman load -i base-images.tar.gz
59-
shell: bash
60-
6147
- name: Find latest ui version
6248
if: inputs.latest_ui != 'false'
6349
run: |
@@ -79,7 +65,7 @@ runs:
7965
# 2. Base images were rebuilt
8066
# 3. New pulp versions were released
8167
build=true
82-
if [[ "${{ github.event_name }}" != "pull_request" && "${{ inputs.image_variant }}" != "nightly" && -z "${{ inputs.built_base_images }}" ]]; then
68+
if [[ "${{ github.event_name }}" != "pull_request" && "${{ inputs.image_variant }}" != "nightly" && "${{ inputs.rebuilt_base_images }}" == "false" ]]; then
8369
# Fetch the latest plugin versions from the last published built image
8470
branch=${{ github.base_ref || github.ref_name }}
8571
config=$(oras manifest fetch-config --platform linux/amd64 ghcr.io/pulp/${{ inputs.image_name }}:${branch} | jq -r '.config.Labels')
@@ -99,25 +85,21 @@ runs:
9985
run: |
10086
podman version
10187
buildah version
102-
sudo podman run --rm --privileged multiarch/qemu-user-static --reset -p yes
103-
for ARCH in arm64 amd64
104-
do
105-
if [[ "${{ inputs.image_name }}" == "pulp-minimal" ]]; then
106-
base_image=$(echo ${{ inputs.image_name }} | cut -d '-' -f1)
107-
podman build --platform linux/${ARCH} --format docker --pull=false --file images/${{ inputs.image_name }}/${{ inputs.image_variant }}/Containerfile.core --tag pulp/${{ inputs.image_name }}:ci-${ARCH} --build-arg FROM_TAG=ci-${ARCH} .
108-
podman build --platform linux/${ARCH} --format docker --pull=false --file images/${{ inputs.image_name }}/${{ inputs.image_variant }}/Containerfile.webserver --tag pulp/${base_image}-web:ci-${ARCH} --build-arg FROM_TAG=ci-${ARCH} .
109-
else
110-
podman build --platform linux/${ARCH} --format docker --pull=false --file images/${{ inputs.image_name }}/${{ inputs.image_variant }}/Containerfile --tag pulp/${{ inputs.image_name }}:ci-${ARCH} --build-arg FROM_TAG=ci-${ARCH} ${{ env.BUILD_UI_ARG }} .
111-
fi
112-
done
88+
if [[ "${{ inputs.image_name }}" == "pulp-minimal" ]]; then
89+
base_image=$(echo ${{ inputs.image_name }} | cut -d '-' -f1)
90+
podman build --format docker --pull=false --file images/${{ inputs.image_name }}/${{ inputs.image_variant }}/Containerfile.core --tag pulp/${{ inputs.image_name }}:ci --build-arg FROM_TAG=ci .
91+
podman build --format docker --pull=false --file images/${{ inputs.image_name }}/${{ inputs.image_variant }}/Containerfile.webserver --tag pulp/${base_image}-web:ci --build-arg FROM_TAG=ci .
92+
else
93+
podman build --format docker --pull=false --file images/${{ inputs.image_name }}/${{ inputs.image_variant }}/Containerfile --tag pulp/${{ inputs.image_name }}:ci --build-arg FROM_TAG=ci ${{ env.BUILD_UI_ARG }} .
94+
fi
11395
podman images -a
11496
shell: bash
11597

11698
- name: Set version and branch image tags
11799
id: image_version_branch
118100
run: |
119101
if [[ "${{ steps.rebuild_needed.outputs.build }}" == "true" ]]; then
120-
app_version=$(podman run --pull=never pulp/${{ inputs.image_name }}:ci-amd64 bash -c "pip show pulpcore | sed -n -e 's/Version: //p'")
102+
app_version=$(podman run --pull=never pulp/${{ inputs.image_name }}:ci bash -c "pip show pulpcore | sed -n -e 's/Version: //p'")
121103
else
122104
app_version=$(grep pulpcore versions.freeze | sed -n -e 's/pulpcore==//p')
123105
fi
@@ -132,16 +114,13 @@ runs:
132114
- name: Label image with metadata
133115
if: steps.rebuild_needed.outputs.build == 'true'
134116
run: |
135-
packages=$(podman run --pull=never pulp/${{ inputs.image_name }}:ci-amd64 bash -c "pip list --format json")
117+
packages=$(podman run --pull=never pulp/${{ inputs.image_name }}:ci bash -c "pip list --format json")
136118
plugin_versions=$(echo $packages | jq -r '.[] | select(.name | contains("pulp")) | .name + "==" + .version')
137-
postgres=$(podman run --pull=never pulp/${{ inputs.image_name }}:ci-amd64 bash -c "postgres --version | sed -n -e 's/postgres (PostgreSQL) //p'")
138-
python_version=$(podman run --pull=never pulp/${{ inputs.image_name }}:ci-amd64 bash -c "python3 --version | sed -n -e 's/Python //p'")
119+
postgres=$(podman run --pull=never pulp/${{ inputs.image_name }}:ci bash -c "postgres --version | sed -n -e 's/postgres (PostgreSQL) //p'")
120+
python_version=$(podman run --pull=never pulp/${{ inputs.image_name }}:ci bash -c "python3 --version | sed -n -e 's/Python //p'")
139121
files_hash="${{ hashFiles(format('images/{0}/{1}/**', inputs.image_name, inputs.image_variant), 'images/Containerfile.core.base', 'images/pulp_ci_centos/Containerfile', 'images/assets/**', 'images/s6_assets/**') }}"
140122
141-
for ARCH in arm64 amd64
142-
do
143-
tag="pulp/${{ inputs.image_name }}:ci-${ARCH}"
144-
echo "FROM ${tag}" | podman build --pull=false --platform linux/${ARCH} --format docker --label "org.pulp.plugins=${plugin_versions}" --label "org.pulp.postgres-version=${postgres}" --label "org.pulp.python-version=${python_version}" --label "org.pulp.containerfiles-hash=${files_hash}" --tag ${tag} -
145-
done
146-
podman image inspect pulp/${{ inputs.image_name }}:ci-amd64 --format='{{ .Config.Labels }}'
123+
tag="pulp/${{ inputs.image_name }}:ci"
124+
echo "FROM ${tag}" | podman build --pull=false --format docker --label "org.pulp.plugins=${plugin_versions}" --label "org.pulp.postgres-version=${postgres}" --label "org.pulp.python-version=${python_version}" --label "org.pulp.containerfiles-hash=${files_hash}" --tag ${tag} -
125+
podman image inspect ${tag} --format='{{ .Config.Labels }}'
147126
shell: bash

.github/actions/test_image/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ runs:
2323
if: inputs.image_name == 'pulp'
2424
run: |
2525
# 3.73 has postgres 13 rather than 16
26-
images/s6_assets/test.sh "pulp/${{ inputs.image_name }}:ci-amd64" http "quay.io/pulp/pulp:3.73"
26+
images/s6_assets/test.sh "pulp/${{ inputs.image_name }}:ci" http "quay.io/pulp/pulp:3.73"
2727
podman stop pulp
2828
podman rm pulp
2929
shell: bash
@@ -32,5 +32,5 @@ runs:
3232
if: inputs.image_name == 'pulp-minimal'
3333
run: |
3434
base_image=$(echo ${{ inputs.image_name }} | cut -d '-' -f1)
35-
images/compose/test.sh "${{ inputs.image_name }}:ci-amd64" "${base_image}-web:ci-amd64" "compose.yml"
35+
images/compose/test.sh "${{ inputs.image_name }}:ci" "${base_image}-web:ci" "compose.yml"
3636
shell: bash

.github/workflows/ci.yml

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,48 +53,51 @@ jobs:
5353
done
5454
shell: bash
5555

56-
base-images:
57-
runs-on: ubuntu-latest
58-
outputs:
59-
base_cache_key: "${{ steps.build_base_images.outputs.base_cache_key }}"
60-
rebuilt_images: "${{ steps.build_base_images.outputs.rebuilt_images }}"
56+
build-and-test-images:
57+
strategy:
58+
fail-fast: false
59+
matrix:
60+
os:
61+
- ubuntu-24.04
62+
- ubuntu-24.04-arm
63+
64+
runs-on: ${{ matrix.os }}
6165
steps:
6266
- uses: actions/checkout@v4
6367

6468
- name: Build base images
6569
id: build_base_images
6670
uses: "./.github/actions/base_images"
6771

68-
app-images:
69-
needs: base-images
70-
runs-on: ubuntu-latest
71-
outputs:
72-
app_version: ${{ steps.build_image.outputs.app_version }}
73-
app_branch: ${{ steps.build_image.outputs.app_branch }}
74-
strategy:
75-
fail-fast: false
76-
matrix:
77-
image_name:
78-
- pulp-minimal
79-
- pulp
80-
steps:
81-
- uses: actions/checkout@v4
72+
- name: Build pulp-minimal image
73+
id: build_pulp_minimal_image
74+
uses: "./.github/actions/build_image"
75+
with:
76+
image_name: "pulp-minimal"
77+
image_variant: "stable"
78+
latest_ui: ${{ github.base_ref == 'latest' }}
79+
rebuilt_base_images: ${{ steps.build_base_images.outputs.rebuilt_images }}
8280

83-
- name: Build App Image
84-
id: build_image
81+
- name: Build pulp image
82+
id: build_pulp_image
8583
uses: "./.github/actions/build_image"
8684
with:
87-
image_name: ${{ matrix.image_name }}
85+
image_name: "pulp"
8886
image_variant: "stable"
89-
image_cache_key: ${{ needs.base-images.outputs.base_cache_key }}
9087
latest_ui: ${{ github.base_ref == 'latest' }}
91-
built_base_images: ${{ needs.base-images.outputs.rebuilt_images }}
88+
rebuilt_base_images: ${{ steps.build_base_images.outputs.rebuilt_images }}
89+
90+
- name: Test pulp-minimal image
91+
uses: "./.github/actions/test_image"
92+
with:
93+
image_name: "pulp-minimal"
94+
app_branch: ${{ steps.build_pulp_minimal_image.outputs.app_branch }}
9295

93-
- name: Test App Image
96+
- name: Test pulp image
9497
uses: "./.github/actions/test_image"
9598
with:
96-
image_name: ${{ matrix.image_name }}
97-
app_branch: ${{ steps.build_image.outputs.app_branch }}
99+
image_name: "pulp"
100+
app_branch: ${{ steps.build_pulp_image.outputs.app_branch }}
98101

99102
- name: Logs
100103
if: always()

0 commit comments

Comments
 (0)