Skip to content

Commit

Permalink
chore(ci): fix version inspection handling and add retry (#126)
Browse files Browse the repository at this point in the history
Fixed a bug with the skopeo version inspection and ensure that it will now fail jobs if the result is invalid.
Added retry logic to version inspection, pulling base image, pushing to ghcr.
  • Loading branch information
bsherman authored Mar 14, 2024
1 parent 9dd0b20 commit 9a4f1e3
Showing 1 changed file with 87 additions and 26 deletions.
113 changes: 87 additions & 26 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
required: true
type: string
env:
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}

jobs:
workflow_info:
Expand All @@ -34,20 +34,37 @@ jobs:
name: Get Stream Info
runs-on: ubuntu-latest
outputs:
linux: ${{ steps.fetch.outputs.linux }}
version: ${{ steps.fetch.outputs.version }}
linux: ${{ fromJSON(steps.fetch.outputs.outputs).linux }}
version: ${{ fromJSON(steps.fetch.outputs.outputs).version }}
steps:
- name: Fetch CoreOS stream versions
id: fetch
run: |
skopeo inspect docker://quay.io/fedora/fedora-coreos:${{ inputs.coreos_version }} > inspect.json
linux=$(jq -r '.["Labels"]["ostree.linux"]' inspect.json)
echo "linux=$linux" >> $GITHUB_OUTPUT
version=$(jq -r '.["Labels"]["version"]' inspect.json)
echo "version=$version" >> $GITHUB_OUTPUT
uses: Wandalen/[email protected]
with:
attempt_limit: 3
attempt_delay: 15000
command: |
set -eo pipefail
skopeo inspect docker://quay.io/fedora/fedora-coreos:${{ inputs.coreos_version }} > inspect.json
linux=$(jq -r '.["Labels"]["ostree.linux"]' inspect.json)
if [ -z "$linux" ] || [ "null" = "$linux" ]; then
echo "inspected linux version must not be empty or null"
exit 1
fi
version=$(jq -r '.["Labels"]["org.opencontainers.image.version"]' inspect.json)
if [ -z "$version" ] || [ "null" = "$version" ]; then
echo "inspected image version must not be empty or null"
exit 1
fi
echo "linux=$linux" >> $GITHUB_OUTPUT
echo "version=$version" >> $GITHUB_OUTPUT
- name: Echo outputs
run: |
echo "${{ toJSON(steps.fetch.outputs) }}"
echo "${{ steps.fetch.outputs.outputs }}"
build_fcos:
name: fedora-coreos
Expand Down Expand Up @@ -79,6 +96,14 @@ jobs:
- name: Checkout Push to Registry action
uses: actions/checkout@v4

- name: Verify version
shell: bash
run: |
if [ -z "${{ matrix.image_version }}" ] || [ "null" = "${{ matrix.image_version }}" ]; then
echo "matrix.image_version must not be empty or null"
exit 1
fi
- name: Generate tags
id: generate-tags
shell: bash
Expand Down Expand Up @@ -129,6 +154,16 @@ jobs:
org.opencontainers.image.title=${{ matrix.image_name }}
org.opencontainers.image.version=${{ matrix.image_version }}
- name: Pull base image
uses: Wandalen/[email protected]
with:
attempt_limit: 3
attempt_delay: 15000
command: |
# pull the base image used for FROM in containerfile so
# we can retry on that unfortunately common failure case
podman pull quay.io/fedora/fedora-coreos:${{ inputs.coreos_version }}
# Build image using Buildah action
- name: Build Image
id: build_image
Expand Down Expand Up @@ -158,20 +193,24 @@ jobs:

# Push the image to GHCR (Image Registry)
- name: Push To GHCR
uses: redhat-actions/push-to-registry@v2
uses: Wandalen/[email protected]
id: push
if: github.event_name != 'pull_request'
env:
REGISTRY_USER: ${{ github.actor }}
REGISTRY_PASSWORD: ${{ github.token }}
with:
image: ${{ steps.build_image.outputs.image }}
tags: ${{ steps.build_image.outputs.tags }}
registry: ${{ steps.registry_case.outputs.lowercase }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
extra-args: |
--disable-content-trust
action: redhat-actions/push-to-registry@v2
attempt_limit: 3
attempt_delay: 15000
with: |
image: ${{ steps.build_image.outputs.image }}
tags: ${{ steps.build_image.outputs.tags }}
registry: ${{ steps.registry_case.outputs.lowercase }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
extra-args: |
--disable-content-trust
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
Expand Down Expand Up @@ -237,6 +276,14 @@ jobs:
- name: Checkout Push to Registry action
uses: actions/checkout@v4

- name: Verify version
shell: bash
run: |
if [ -z "${{ matrix.image_version }}" ] || [ "null" = "${{ matrix.image_version }}" ]; then
echo "matrix.image_version must not be empty or null"
exit 1
fi
- name: Generate tags
id: generate-tags
shell: bash
Expand Down Expand Up @@ -291,6 +338,16 @@ jobs:
org.opencontainers.image.title=${{ matrix.image_base }}${{ matrix.image_suffix }}
org.opencontainers.image.version=${{ matrix.image_version }}
- name: Pull base image
uses: Wandalen/[email protected]
with:
attempt_limit: 3
attempt_delay: 15000
command: |
# pull the base image used for FROM in containerfile so
# we can retry on that unfortunately common failure case
podman pull quay.io/fedora/fedora-coreos:${{ inputs.coreos_version }}
# Build image using Buildah action
- name: Build Image
id: build_image
Expand Down Expand Up @@ -322,20 +379,24 @@ jobs:

# Push the image to GHCR (Image Registry)
- name: Push To GHCR
uses: redhat-actions/push-to-registry@v2
uses: Wandalen/[email protected]
id: push
if: github.event_name != 'pull_request'
env:
REGISTRY_USER: ${{ github.actor }}
REGISTRY_PASSWORD: ${{ github.token }}
with:
image: ${{ steps.build_image.outputs.image }}
tags: ${{ steps.build_image.outputs.tags }}
registry: ${{ steps.registry_case.outputs.lowercase }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
extra-args: |
--disable-content-trust
action: redhat-actions/push-to-registry@v2
attempt_limit: 3
attempt_delay: 15000
with: |
image: ${{ steps.build_image.outputs.image }}
tags: ${{ steps.build_image.outputs.tags }}
registry: ${{ steps.registry_case.outputs.lowercase }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
extra-args: |
--disable-content-trust
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
Expand Down

0 comments on commit 9a4f1e3

Please sign in to comment.