|
| 1 | +name: Sync manylinux image to GHCR |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + source_ref: |
| 7 | + description: Upstream manylinux image reference to mirror |
| 8 | + required: true |
| 9 | + default: quay.io/pypa/manylinux_2_28_x86_64:latest |
| 10 | + type: string |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + packages: write |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: sync-manylinux-image |
| 18 | + cancel-in-progress: false |
| 19 | + |
| 20 | +env: |
| 21 | + DEFAULT_SOURCE_REF: quay.io/pypa/manylinux_2_28_x86_64:latest |
| 22 | + DESTINATION_IMAGE: ghcr.io/shimat/opencvsharp-manylinux |
| 23 | + DESTINATION_TAG: manylinux_2_28_x86_64 |
| 24 | + |
| 25 | +jobs: |
| 26 | + sync: |
| 27 | + name: Mirror manylinux_2_28 x64 |
| 28 | + runs-on: ubuntu-24.04 |
| 29 | + timeout-minutes: 20 |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Pull upstream image with retries |
| 33 | + id: pull |
| 34 | + env: |
| 35 | + SOURCE_REF: ${{ inputs.source_ref || env.DEFAULT_SOURCE_REF }} |
| 36 | + run: | |
| 37 | + set -euo pipefail |
| 38 | +
|
| 39 | + for attempt in 1 2 3 4 5; do |
| 40 | + if docker pull "${SOURCE_REF}"; then |
| 41 | + break |
| 42 | + fi |
| 43 | +
|
| 44 | + if [ "${attempt}" -eq 5 ]; then |
| 45 | + echo "Failed to pull ${SOURCE_REF} after ${attempt} attempts." >&2 |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | +
|
| 49 | + delay=$((attempt * 15)) |
| 50 | + echo "Pull attempt ${attempt} failed; retrying in ${delay} seconds." >&2 |
| 51 | + sleep "${delay}" |
| 52 | + done |
| 53 | +
|
| 54 | + echo "source_ref=${SOURCE_REF}" >> "${GITHUB_OUTPUT}" |
| 55 | +
|
| 56 | + - name: Log in to GHCR |
| 57 | + env: |
| 58 | + GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + run: echo "${GHCR_TOKEN}" | docker login ghcr.io --username "${GITHUB_ACTOR}" --password-stdin |
| 60 | + |
| 61 | + - name: Push mirror and report digest |
| 62 | + id: push |
| 63 | + env: |
| 64 | + SOURCE_REF: ${{ steps.pull.outputs.source_ref }} |
| 65 | + run: | |
| 66 | + set -euo pipefail |
| 67 | +
|
| 68 | + destination_ref="${DESTINATION_IMAGE}:${DESTINATION_TAG}" |
| 69 | + push_log="${RUNNER_TEMP}/manylinux-push.log" |
| 70 | +
|
| 71 | + docker tag "${SOURCE_REF}" "${destination_ref}" |
| 72 | + docker push "${destination_ref}" | tee "${push_log}" |
| 73 | +
|
| 74 | + digest="$(sed -n 's/.*digest: \(sha256:[0-9a-f]\{64\}\).*/\1/p' "${push_log}" | tail -n 1)" |
| 75 | + if [ -z "${digest}" ]; then |
| 76 | + echo "Could not determine the pushed image digest." >&2 |
| 77 | + exit 1 |
| 78 | + fi |
| 79 | +
|
| 80 | + docker pull "${DESTINATION_IMAGE}@${digest}" |
| 81 | +
|
| 82 | + echo "digest=${digest}" >> "${GITHUB_OUTPUT}" |
| 83 | + { |
| 84 | + echo "### manylinux mirror" |
| 85 | + echo |
| 86 | + echo "- Source: \`${SOURCE_REF}\`" |
| 87 | + echo "- Destination: \`${destination_ref}\`" |
| 88 | + echo "- Pinned reference: \`${DESTINATION_IMAGE}@${digest}\`" |
| 89 | + } >> "${GITHUB_STEP_SUMMARY}" |
0 commit comments