|
1 | 1 | ---
|
2 | 2 | name: Build Base Images
|
3 | 3 | 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 |
6 | 5 | 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." |
10 | 6 | rebuilt_images:
|
11 |
| - value: ${{ env.BUILD_IMAGES }} |
12 |
| - description: "The images that were rebuilt or empty" |
| 7 | + value: ${{ steps.rebuild_needed.outputs.build }} |
| 8 | + description: "true/false if the base images were rebuilt" |
13 | 9 |
|
14 | 10 | runs:
|
15 | 11 | using: "composite"
|
16 | 12 | steps:
|
17 | 13 | - uses: actions/checkout@v4
|
18 | 14 |
|
19 | 15 | - name: Calculate base images hash
|
20 |
| - id: hash_key |
21 | 16 | run: |
|
22 | 17 | hash=${{ hashFiles('images/Containerfile.core.base', 'images/pulp_ci_centos/Containerfile', 'images/assets/**', 'images/s6_assets/**') }}
|
23 | 18 | echo "base image hash is ${hash}"
|
24 |
| - echo "base_cache_key=${hash}" >> $GITHUB_OUTPUT |
| 19 | + echo "HASH=${hash}" >> $GITHUB_ENV |
25 | 20 | shell: bash
|
26 | 21 |
|
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 |
| 22 | + - name: Set up oras |
| 23 | + uses: oras-project/setup-oras@v1 |
33 | 24 |
|
34 |
| - - name: Extract images if cached |
35 |
| - if: steps.cache.outputs.cache-hit == 'true' |
| 25 | + - name: Check for updates on base images |
| 26 | + id: rebuild_needed |
36 | 27 | 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}") |
| 28 | + branch=${{ github.base_ref || github.ref_name }} |
| 29 | + config=$(oras manifest fetch-config --platform linux/amd64 ghcr.io/pulp/pulp-ci-centos9:${branch} | jq -r '.config.Labels') |
| 30 | + latest_hash=$(echo "${config}" | jq -r '."org.pulp.basefiles-hash"') |
| 31 | + build=true |
| 32 | + if [[ "${latest_hash}" == "${HASH}" ]]; then |
| 33 | + if podman run ghcr.io/pulp/pulp-ci-centos9:${branch} bash -c "dnf check-upgrade"; then |
| 34 | + echo "No base images rebuild needed :)" |
| 35 | + build=false |
55 | 36 | fi
|
56 |
| - done |
57 |
| - if [ ${#IMAGES[@]} -eq 0 ]; then |
58 |
| - echo "No rebuilds needed :)" |
59 |
| - else |
60 |
| - echo "BUILD_IMAGES=[$(echo ${IMAGES[@]@Q} | sed 's/ /, /g')]" >> $GITHUB_ENV |
61 | 37 | fi
|
| 38 | + echo "build=${build}" >> "$GITHUB_OUTPUT" |
| 39 | + echo "Going to rebuild: ${build}" |
62 | 40 | shell: bash
|
63 | 41 |
|
64 |
| - - name: Set images to build on cache miss |
65 |
| - if: steps.cache.outputs.cache-hit != 'true' |
| 42 | + - name: Download base images if no rebuild needed |
| 43 | + if: steps.rebuild_needed.outputs.build == 'false' |
66 | 44 | 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 |
| 45 | + echo "Downloading base images" |
| 46 | + branch=${{ github.base_ref || github.ref_name }} |
| 47 | + podman pull ghcr.io/pulp/base:${branch} |
| 48 | + podman pull ghcr.io/pulp/pulp-ci-centos9:${branch} |
| 49 | + podman tag ghcr.io/pulp/base:${branch} pulp/base:ci |
| 50 | + podman tag ghcr.io/pulp/pulp-ci-centos9:${branch} pulp/pulp-ci-centos9:ci |
69 | 51 | shell: bash
|
70 | 52 |
|
71 | 53 | - name: Build images
|
72 |
| - if: env.BUILD_IMAGES |
| 54 | + if: steps.rebuild_needed.outputs.build == 'true' |
73 | 55 | run: |
|
74 |
| - IMAGES=(${{ join(fromJSON(env.BUILD_IMAGES), ' ') }}) |
75 |
| - echo "Going to build images: ${IMAGES[@]}" |
76 | 56 | podman version
|
77 | 57 | 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 |
90 |
| - 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 |
| 58 | + podman build --format docker --file images/Containerfile.core.base --tag "pulp/base:ci" --label "org.pulp.basefiles-hash=${HASH}" . |
| 59 | + podman build --format docker --file images/pulp_ci_centos/Containerfile --tag "pulp/pulp-ci-centos9:ci" --build-arg FROM_TAG="ci" . |
102 | 60 | 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 |
0 commit comments