diff --git a/.github/workflows/smoke-build.yaml b/.github/workflows/smoke-build.yaml index 3c6cae7..0170131 100644 --- a/.github/workflows/smoke-build.yaml +++ b/.github/workflows/smoke-build.yaml @@ -62,11 +62,13 @@ jobs: uses: ./build-product-image with: product-version: ${{ matrix.versions }} + sdp-version: 1.2.3 boil-config-file: smoke/container-image/boil.toml boil-version: latest registry-namespace: smoke extra-tag-data: pr-321 product-name: smoke/container-image + floating-tag: "true" - name: Publish Container Image on oci.stackable.tech uses: ./publish-image @@ -75,8 +77,8 @@ jobs: image-registry-username: robot$smoke+github-action-build image-registry-password: ${{ secrets.HARBOR_ROBOT_SMOKE_GITHUB_ACTION_BUILD_SECRET }} image-repository: smoke/container-image - image-manifest-tag: ${{ steps.build.outputs.image-manifest-tag }} - source-image-uri: localhost/smoke/smoke/container-image:${{ steps.build.outputs.image-manifest-tag }} + image-manifest-tag: ${{ steps.build.outputs.canonical-image-manifest-tag }} + source-image-uri: ${{ steps.build.outputs.canonical-image-manifest-uri }} publish-manifests: name: Build/Publish ${{ matrix.versions }} Index Manifest @@ -100,7 +102,7 @@ jobs: image-registry-username: robot$smoke+github-action-build image-registry-password: ${{ secrets.HARBOR_ROBOT_SMOKE_GITHUB_ACTION_BUILD_SECRET }} image-repository: smoke/container-image - image-index-manifest-tag: ${{ matrix.versions }}-stackable0.0.0-dev-pr-321 + image-index-manifest-tag: ${{ matrix.versions }}-stackable1.2.3-pr-321 publish-helm-chart: name: Package/Publish ${{ matrix.versions }} Helm Chart diff --git a/build-product-image/README.md b/build-product-image/README.md index bd43527..cb75ecc 100644 --- a/build-product-image/README.md +++ b/build-product-image/README.md @@ -43,9 +43,12 @@ localhost/kafka:3.4.1-stackable0.0.0-dev-amd64 ### Outputs -| Output | Example | Description | -| ------------------------------------ | -------------------------------- | ----------------------------------------------- | -| `image-manifest-tag` | `3.4.1-stackable0.0.0-dev-amd64` | The image manifest tag (including architecture) | -| `suggested-image-index-manifest-tag` | `3.4.1-stackable0.0.0-dev` | The suggested image index manifest tag | +| Output | Example | Description | +| ------------------------------------ | ----------------------------------------------------------------- | --------------------------------------- | +| `canonical-image-manifest-uri` | `oci.stackable.tech/sdp/tools:3.4.1-stackable0.0.0-dev-amd64` | The canonical image manifest uri | +| `canonical-image-manifest-tag` | `3.4.1-stackable0.0.0-dev-amd64` | The canonical image manifest tag | +| `other-image-manifest-uris` | `["oci.stackable.tech/sdp/tools:3.4.1-stackable0.0.0-dev-amd64"]` | Other image manifest uris (JSON string) | +| `other-image-manifest-tags` | `["3.4.1-stackable0.0.0-dev-amd64"]` | Other image manifest tags (JSON string) | +| `suggested-image-index-manifest-tag` | `3.4.1-stackable0.0.0-dev` | The suggested image index manifest tag | [build-product-image]: ./action.yaml diff --git a/build-product-image/action.yaml b/build-product-image/action.yaml index edcd0b7..576f811 100644 --- a/build-product-image/action.yaml +++ b/build-product-image/action.yaml @@ -24,12 +24,28 @@ inputs: registry-namespace: description: Path of the registry namespace, eg. `sdp` or `stackable` required: true + floating-tag: + description: Whether a floating tag should be added to the final image + default: "false" outputs: - image-manifest-tag: + canonical-image-manifest-uri: description: | - Human-readable tag (usually the version) with architecture information, - for example: `3.4.1-stackable0.0.0-dev-amd64` - value: ${{ steps.build.outputs.IMAGE_MANIFEST_TAG }} + Human-readable canonical manifest URI: `oci.stackable.tech/tools:3.4.1-stackable0.0.0-dev-amd64` + value: ${{ steps.build.outputs.CANONICAL_IMAGE_MANIFEST_URI }} + canonical-image-manifest-tag: + description: | + Human-readable canonical manifest tag: `3.4.1-stackable0.0.0-dev-amd64` + value: ${{ steps.build.outputs.CANONICAL_IMAGE_MANIFEST_TAG }} + other-image-manifest-uris: + description: | + A JSON string containing a list of other/additional manifest URIs. This list for example + includes the floating URI if requested and needed. + value: ${{ steps.build.outputs.OTHER_IMAGE_MANIFEST_URIS }} + other-image-manifest-tags: + description: | + A JSON string containing a list of other/additional manifest tags. This list for example + includes the floating tag if requested and needed. + value: ${{ steps.build.outputs.OTHER_IMAGE_MANIFEST_TAGS }} suggested-image-index-manifest-tag: description: | Human-readable tag (usually the version) without architecture information, @@ -38,6 +54,19 @@ outputs: runs: using: composite steps: + - name: Validate inputs + env: + FLOATING_TAG: ${{ inputs.floating-tag }} + shell: bash + run: | + set -euo pipefail + [ -n "${RUNNER_DEBUG+set}" ] && set -x + + if [ "$FLOATING_TAG" != 'true' ] && [ "$FLOATING_TAG" != 'false' ]; then + echo 'The floating-tag input must be either "true" or "false".' + exit 1 + fi + - name: Setup Docker Buildx uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0 @@ -55,6 +84,7 @@ runs: BOIL_CONFIG_FILE: ${{ inputs.boil-config-file }} IMAGE_REPOSITORY: ${{ inputs.product-name }} EXTRA_TAG_DATA: ${{ inputs.extra-tag-data }} + FLOATING_TAG: ${{ inputs.floating-tag }} SDP_VERSION: ${{ inputs.sdp-version }} shell: bash run: | @@ -77,23 +107,50 @@ runs: fi echo "::group::boil" - boil build \ - --image-version "$IMAGE_INDEX_MANIFEST_TAG" \ - --registry-namespace "$REGISTRY_NAMESPACE" \ - --target-platform "linux/${IMAGE_ARCH}" \ - --configuration "$BOIL_CONFIG_FILE" \ - --write-image-manifest-uris \ - --use-localhost-registry \ - "$IMAGE_REPOSITORY=$BOIL_PRODUCT_VERSION" \ - -- --load + # FIXME (@Techassi): We could get rid of this if block if we would support --floating-tag=true/false in boil + # See https://github.com/clap-rs/clap/issues/1649 + if [ "$FLOATING_TAG" == 'true' ]; then + boil build \ + --image-version "$IMAGE_INDEX_MANIFEST_TAG" \ + --registry-namespace "$REGISTRY_NAMESPACE" \ + --target-platform "linux/${IMAGE_ARCH}" \ + --configuration "$BOIL_CONFIG_FILE" \ + --write-image-manifest-uris \ + --use-localhost-registry \ + --floating-tag \ + "$IMAGE_REPOSITORY=$BOIL_PRODUCT_VERSION" \ + -- --load + else + boil build \ + --image-version "$IMAGE_INDEX_MANIFEST_TAG" \ + --registry-namespace "$REGISTRY_NAMESPACE" \ + --target-platform "linux/${IMAGE_ARCH}" \ + --configuration "$BOIL_CONFIG_FILE" \ + --write-image-manifest-uris \ + --use-localhost-registry \ + "$IMAGE_REPOSITORY=$BOIL_PRODUCT_VERSION" \ + -- --load + fi echo "::endgroup::" - echo "boil-target-tags: "$(< boil-target-tags) + echo "boil-target-tags: "$(< boil-target-tags.json) + + # Extract the image manifest tag from the boil-target-tags.json file + CANONICAL_IMAGE_MANIFEST_URI=$(jq --arg IMAGE_REPOSITORY "$IMAGE_REPOSITORY" --raw-output '.[$IMAGE_REPOSITORY].canonical' < boil-target-tags.json) + CANONICAL_IMAGE_MANIFEST_TAG=$(echo "$CANONICAL_IMAGE_MANIFEST_URI" | cut -d : -f 2) + + OTHER_IMAGE_MANIFEST_URIS=$(jq --arg IMAGE_REPOSITORY "$IMAGE_REPOSITORY" --raw-output --compact-output '.[$IMAGE_REPOSITORY].others' < boil-target-tags.json) + OTHER_IMAGE_MANIFEST_TAGS=$(echo "$OTHER_IMAGE_MANIFEST_URIS" | jq --raw-output --compact-output 'map(split(":")[1])') + + [[ -n "$CANONICAL_IMAGE_MANIFEST_URI" ]] + [[ -n "$CANONICAL_IMAGE_MANIFEST_TAG" ]] + [[ -n "$OTHER_IMAGE_MANIFEST_URIS" ]] + [[ -n "$OTHER_IMAGE_MANIFEST_TAGS" ]] - # Extract the image manifest tag from the boil-target-tags file - IMAGE_MANIFEST_TAG=$(cut -d : -f 2 < boil-target-tags) - [[ -n "$IMAGE_MANIFEST_TAG" ]] - echo "IMAGE_MANIFEST_TAG=$IMAGE_MANIFEST_TAG" | tee -a "$GITHUB_OUTPUT" + echo "CANONICAL_IMAGE_MANIFEST_URI=$CANONICAL_IMAGE_MANIFEST_URI" | tee -a "$GITHUB_OUTPUT" + echo "CANONICAL_IMAGE_MANIFEST_TAG=$CANONICAL_IMAGE_MANIFEST_TAG" | tee -a "$GITHUB_OUTPUT" + echo "OTHER_IMAGE_MANIFEST_URIS=$OTHER_IMAGE_MANIFEST_URIS" | tee -a "$GITHUB_OUTPUT" + echo "OTHER_IMAGE_MANIFEST_TAGS=$OTHER_IMAGE_MANIFEST_TAGS" | tee -a "$GITHUB_OUTPUT" - name: Print out Disk Usage if: always() diff --git a/smoke/container-image/boil.toml b/smoke/container-image/boil.toml index 5a74845..1b44ed0 100644 --- a/smoke/container-image/boil.toml +++ b/smoke/container-image/boil.toml @@ -2,6 +2,7 @@ documentation = "https://docs.stackable.tech/home/stable/" source = "https://github.com/stackabletech/actions/" authors = "Stackable GmbH " +vendor-tag-prefix = "stackable" vendor = "Stackable GmbH" licenses = "Apache-2.0"