diff --git a/.github/scripts/determine-image-version.sh b/.github/scripts/determine-image-version.sh deleted file mode 100755 index 8d72fe2..0000000 --- a/.github/scripts/determine-image-version.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash - -IMAGE_REPOSITORY=${REGISTRY_URI}/${REGISTRY_REPOSITORY}/${IMAGE_NAME} - -# determine version -# if scheduled build then version is 'nightly' -# else if REF is a tag then version is tag -# else if REF is the default branch then version is 'edge' -# else if REF is pull request then version is pull request event number -VERSION=noop -if [ "${GITHUB_EVENT_NAME}" == "schedule" ]; then - VERSION=nightly -elif [[ ${GITHUB_REF} == refs/tags/* ]]; then - VERSION=${GITHUB_REF#refs/tags/} -elif [[ ${GITHUB_REF} == refs/heads/* ]]; then - VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') - if [ "${GITHUB_EVENT_REPOSITORY_DEFAULT_BRANCH}" = "$VERSION" ]; then - VERSION=edge - fi -elif [[ ${GITHUB_REF} == refs/pull/* ]]; then - VERSION=pr-${GITHUB_EVENT_NUMBER} -fi -VERSION="${VERSION}" -TAGS="${IMAGE_REPOSITORY}:${VERSION}" - -# if version is vMAJOR.MINOR.MICRO then also tag with vMAJOR and vMAJOR.MINOR -if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then - MINOR=${VERSION%.*} - MAJOR=${MINOR%.*} - TAGS="${TAGS} ${IMAGE_REPOSITORY}:${MINOR} ${IMAGE_REPOSITORY}:${MAJOR} ${IMAGE_REPOSITORY}:latest" -fi - -# add sha tag if not a pull request -if [[ ${GITHUB_REF} != refs/pull/* ]]; then - TAGS="${TAGS} ${IMAGE_REPOSITORY}:sha-${GITHUB_SHA::12}" -fi - -# if a flavor is provided then iterate each tag and add the flavor to it -# if IMAGE_IS_DEFAULT_FLAVOR is also true, then also use the unflavored tags -if [[ ${IMAGE_TAG_FLAVOR} ]] ; then - original_tags=$TAGS - TAGS="" - - for original_tag in $(echo $original_tags | sed "s/,/ /g") - do - if [[ ${IMAGE_IS_DEFAULT_FLAVOR} =~ true|True|t|T|yes|Yes|y|Y ]]; then - new_tags="${original_tag} ${original_tag}${IMAGE_TAG_FLAVOR}" - else - new_tags="${original_tag}${IMAGE_TAG_FLAVOR}" - fi - - if [[ ${TAGS} ]]; then - TAGS="${TAGS} ${new_tags}" - else - TAGS="${new_tags}" - fi - done -fi - -# set output for future github action steps -echo "version=${VERSION}${IMAGE_TAG_FLAVOR}" >> $GITHUB_OUTPUT -echo "tags=${TAGS}" >> $GITHUB_OUTPUT -echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index b1518b9..67a4079 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -8,9 +8,10 @@ on: branches: - main tags: - - 'v*.*.*' + - 'v*' pull_request: - branches: [ main ] + branches: + - main workflow_dispatch: concurrency: @@ -18,50 +19,128 @@ concurrency: cancel-in-progress: true env: - GITHUB_EVENT_REPOSITORY_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} - GITHUB_EVENT_NUMBER: ${{ github.event.number }} - REGISTRY_URI: ${{ vars.REGISTRY_URI }} - REGISTRY_REPOSITORY: ${{ vars.REGISTRY_REPOSITORY }} + IMAGE_PATH: ${{ vars.REGISTRY_URI }}/${{ vars.REGISTRY_REPOSITORY }}/ee-kustomzie-with-ocm-policygenerator-plugin-and-helm + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} +# Modified from: https://github.com/redhat-actions/buildah-build/issues/121#issuecomment-1683691170 jobs: - build-and-publish-ee: + build-ee: + name: Build EE runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm64 + steps: + - name: Checkout 🛎ī¸ + uses: actions/checkout@v4 - env: - IMAGE_NAME: ee-kustomzie-with-ocm-policygenerator-plugin-and-helm + - name: Install ansible-builder 🧰 + run: pip install ansible-builder - outputs: - version: ${{ steps.prep.outputs.version }} + - name: Crate Ansible EE container image context 🛠 + run: ansible-builder create -v3 - steps: - - name: Checkout 🛎ī¸ - uses: actions/checkout@v4.2.1 + - name: cache podman storage 🗃 + uses: actions/cache@v3 + with: + path: ~/.local/share/containers/storage + key: podman-storage-${{ matrix.platform }} - - name: Determine Image Version and Tags ⚙ī¸ - id: prep - run: ${GITHUB_WORKSPACE}/.github/scripts/determine-image-version.sh + - name: Extract architecture name from platform name 🔎 + run: | + echo "PODMAN_ARCH=${PLATFORM#*/}" >>${GITHUB_ENV} + env: + PLATFORM: ${{ matrix.platform }} - - name: Version 📌 - run: echo ${{ steps.prep.outputs.version }} + - name: Create container image build meta ℹī¸ + id: build-meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ env.IMAGE_PATH }} + tags: | + type=raw,value=build + flavor: | + suffix=-${{ env.PODMAN_ARCH }} - - name: Image Tags 🏷 - run: echo ${{ steps.prep.outputs.tags }} - - - name: Install ansible-builder 🧰 - run: pip install ansible-builder + - name: Set up QEMU 🧰 + uses: docker/setup-qemu-action@v3 + + - name: Build OCI Image 🛠ī¸ + id: build-image + uses: redhat-actions/buildah-build@v2 + with: + tags: ${{ steps.build-meta.outputs.tags }} + labels: ${{ steps.build-meta.outputs.labels }} + oci: true + context: ./context + containerfiles: | + ./context/Containerfile + platforms: ${{ matrix.platform }} + + - name: Export OCI archives 💾 + run: skopeo copy containers-storage:${{ env.IMAGE_PATH }}:build-${{ env.PODMAN_ARCH }} oci-archive:/tmp/${{ env.PODMAN_ARCH }}-oci.tar + + - name: Upload OCI archives đŸ”ē + uses: actions/upload-artifact@v4 + with: + name: build-${{ env.PODMAN_ARCH }} + path: /tmp/${{ env.PODMAN_ARCH }}-oci.tar + if-no-files-found: error + retention-days: 1 + + publish-ee: + name: Publish EE + runs-on: ubuntu-latest + needs: build-ee + steps: + - name: Download OCI archives đŸ”ģ + uses: actions/download-artifact@v4 + with: + pattern: build-* + path: oci-archives + merge-multiple: true + + - name: Create manifest 📒 + run: podman manifest create ${{ env.IMAGE_PATH }}:manifest - - name: Build Ansible EE container image 🛠 + - name: Add platform specific images to manifest ➕ run: | - ansible-builder build -v3 \ - --tag ${{ steps.prep.outputs.tags }} + for OCI_TAR in oci-archives/*-oci.tar; do + podman manifest add ${{ env.IMAGE_PATH }}:manifest oci-archive:${OCI_TAR} + done - - name: Publish images đŸ”ē + - name: Create container image build meta ℹī¸ + id: push-meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.IMAGE_PATH }} + tags: | + type=schedule,pattern=nightly + type=edge,branch=main + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + + - name: Tag multi platform manifest 🏷 + run: | + podman tag ${{ env.IMAGE_PATH }}:manifest $(echo "${{ steps.push-meta.outputs.tags }}" | tr '\n' ' ') + + - name: Publish images 📰 id: publish-images - uses: redhat-actions/push-to-registry@v2.8 + uses: redhat-actions/push-to-registry@v2 with: - tags: ${{ steps.prep.outputs.tags }} - username: ${{ secrets.REGISTRY_USERNAME }} - password: ${{ secrets.REGISTRY_PASSWORD }} + tags: ${{ steps.push-meta.outputs.tags }} + username: ${{ env.REGISTRY_USERNAME }} + password: ${{ env.REGISTRY_PASSWORD }} - name: Pushed Image Digest 🔖 run: echo ${{ steps.publish-images.outputs.digest }}