|
| 1 | +--- |
| 2 | +name: Publish Product Image |
| 3 | +description: This action publishes a Docker image |
| 4 | +inputs: |
| 5 | + product: |
| 6 | + description: The name of the product to publish |
| 7 | + required: true |
| 8 | + image-name: |
| 9 | + description: This is the full image name before the tag (left of ':') |
| 10 | + required: true |
| 11 | + image-version: |
| 12 | + description: This is the container image end tag excluding the architecture information (right of ':') |
| 13 | + required: true |
| 14 | + nexus-username: |
| 15 | + description: The username to login to Nexus |
| 16 | + default: github |
| 17 | + nexus-password: |
| 18 | + description: The password to login to Nexus |
| 19 | + required: true |
| 20 | + harbor-username: |
| 21 | + description: The username to login to Harbor |
| 22 | + default: robot$sdp+github-action-build |
| 23 | + harbor-secret: |
| 24 | + description: The secret to login to Harbor |
| 25 | + required: true |
| 26 | +runs: |
| 27 | + using: composite |
| 28 | + steps: |
| 29 | + - name: Set up Cosign |
| 30 | + uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 # v3.5.0 |
| 31 | + |
| 32 | + - name: Set up syft |
| 33 | + uses: anchore/sbom-action/download-syft@e8d2a6937ecead383dfe75190d104edd1f9c5751 # v0.16.0 |
| 34 | + |
| 35 | + - name: Login to Stackable Nexus |
| 36 | + uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0 |
| 37 | + with: |
| 38 | + registry: docker.stackable.tech |
| 39 | + username: ${{ inputs.nexus-username }} |
| 40 | + password: ${{ inputs.nexus-password }} |
| 41 | + |
| 42 | + - name: Login to Stackable Harbor |
| 43 | + uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0 |
| 44 | + with: |
| 45 | + registry: oci.stackable.tech |
| 46 | + username: ${{ inputs.harbor-username }} |
| 47 | + password: ${{ inputs.harbor-secret }} |
| 48 | + |
| 49 | + - name: Setup Environment Variables |
| 50 | + shell: bash |
| 51 | + run: | |
| 52 | + set -euo pipefail |
| 53 | + IMAGE_VERSION=${{ inputs.image-version }} |
| 54 | + IMAGE_NAME=${{ inputs.image-name }} |
| 55 | + ARCH="$(uname -m | sed -e 's#x86_64#amd64#' | sed -e 's#aarch64#arm64#')" |
| 56 | + TAG_NAME="${IMAGE_VERSION}-${ARCH}" |
| 57 | +
|
| 58 | + echo "IMAGE_VERSION=$IMAGE_VERSION" >> $GITHUB_ENV |
| 59 | + echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV |
| 60 | + echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV |
| 61 | +
|
| 62 | + - name: Push Image to repo.stackable.tech and sign via cosign |
| 63 | + shell: bash |
| 64 | + run: | |
| 65 | + set -euo pipefail |
| 66 | + # Store the output of `docker image push` into a variable, so we can |
| 67 | + # parse it for the digest |
| 68 | + PUSH_OUTPUT=$(docker image push "$(< bake-target-tags)" 2>&1) |
| 69 | + echo "$PUSH_OUTPUT" |
| 70 | + # Obtain the digest of the pushed image from the output of `docker image |
| 71 | + # push`, because signing by tag is deprecated and will be removed from |
| 72 | + # cosign in the future |
| 73 | + DIGEST=$(echo "$PUSH_OUTPUT" | awk "/: digest: sha256:[a-f0-9]{64} size: [0-9]+$/ { print \$3 }") |
| 74 | + echo "DIGEST=$DIGEST" >> $GITHUB_ENV |
| 75 | + # Refer to image via its digest (docker.stackable.tech/stackable/airflow@sha256:0a1b2c...) |
| 76 | + # This generates a signature and publishes it to the registry, next to the image |
| 77 | + # Uses the keyless signing flow with Github Actions as identity provider |
| 78 | + cosign sign -y "$IMAGE_NAME@$DIGEST" |
| 79 | +
|
| 80 | + - name: Generate SBOM for the Nexus Image |
| 81 | + shell: bash |
| 82 | + run: | |
| 83 | + set -euo pipefail |
| 84 | + syft scan --output cyclonedx-json=sbom.json --select-catalogers "-cargo-auditable-binary-cataloger" --scope all-layers --source-name "${{ inputs.product }}" --source-version "$TAG_NAME" "$IMAGE_NAME@$DIGEST"; |
| 85 | + # Determine the PURL for the image |
| 86 | + PURL="pkg:docker/stackable/${{ inputs.product }}@$DIGEST?repository_url=docker.stackable.tech"; |
| 87 | + # Get metadata from the image |
| 88 | + IMAGE_METADATA_DESCRIPTION=$(docker inspect --format='{{.Config.Labels.description}}' "$IMAGE_NAME@$DIGEST"); |
| 89 | + IMAGE_METADATA_NAME=$(docker inspect --format='{{.Config.Labels.name}}' "$IMAGE_NAME@$DIGEST"); |
| 90 | + # Merge the SBOM with the metadata for the image |
| 91 | + jq -s '{"metadata":{"component":{"description":"'"$IMAGE_METADATA_NAME. $IMAGE_METADATA_DESCRIPTION"'","supplier":{"name":"Stackable GmbH","url":["https://stackable.tech/"]},"author":"Stackable GmbH","purl":"'"$PURL"'","publisher":"Stackable GmbH"}}} * .[0]' sbom.json > sbom.merged.json; |
| 92 | + # Attest the SBOM to the image |
| 93 | + cosign attest -y --predicate sbom.merged.json --type cyclonedx "$IMAGE_NAME@$DIGEST" |
| 94 | +
|
| 95 | + - name: Push Image to oci.stackable.tech and sign via cosign |
| 96 | + shell: bash |
| 97 | + run: | |
| 98 | + set -euo pipefail |
| 99 | + IMAGE_NAME=oci.stackable.tech/sdp/${{ inputs.product }} |
| 100 | + echo "image: $IMAGE_NAME" |
| 101 | + docker tag "$(< bake-target-tags)" "$IMAGE_NAME:$TAG_NAME" |
| 102 | + # Store the output of `docker image push` into a variable, so we can parse it for the digest |
| 103 | + PUSH_OUTPUT=$(docker image push "$IMAGE_NAME:$TAG_NAME" 2>&1) |
| 104 | + echo "$PUSH_OUTPUT" |
| 105 | + # Obtain the digest of the pushed image from the output of `docker image push`, because signing by tag is deprecated and will be removed from cosign in the future |
| 106 | + DIGEST=$(echo "$PUSH_OUTPUT" | awk "/: digest: sha256:[a-f0-9]{64} size: [0-9]+$/ { print \$3 }") |
| 107 | + echo "DIGEST=$DIGEST" >> $GITHUB_ENV |
| 108 | + # Refer to image via its digest (oci.stackable.tech/sdp/airflow@sha256:0a1b2c...) |
| 109 | + # This generates a signature and publishes it to the registry, next to the image |
| 110 | + # Uses the keyless signing flow with Github Actions as identity provider |
| 111 | + cosign sign -y "$IMAGE_NAME@$DIGEST" |
| 112 | +
|
| 113 | + - name: Generate SBOM for the Harbor Image |
| 114 | + shell: bash |
| 115 | + run: | |
| 116 | + set -euo pipefail |
| 117 | + syft scan --output cyclonedx-json=sbom.json --select-catalogers "-cargo-auditable-binary-cataloger" --scope all-layers --source-name "${{ inputs.product }}" --source-version "$TAG_NAME" "$IMAGE_NAME@$DIGEST"; |
| 118 | + # Determine the PURL for the image |
| 119 | + PURL="pkg:docker/sdp/${{ inputs.product }}@$DIGEST?repository_url=oci.stackable.tech"; |
| 120 | + # Get metadata from the image |
| 121 | + IMAGE_METADATA_DESCRIPTION=$(docker inspect --format='{{.Config.Labels.description}}' "$IMAGE_NAME@$DIGEST"); |
| 122 | + IMAGE_METADATA_NAME=$(docker inspect --format='{{.Config.Labels.name}}' "$IMAGE_NAME@$DIGEST"); |
| 123 | + # Merge the SBOM with the metadata for the image |
| 124 | + jq -s '{"metadata":{"component":{"description":"'"$IMAGE_METADATA_NAME. $IMAGE_METADATA_DESCRIPTION"'","supplier":{"name":"Stackable GmbH","url":["https://stackable.tech/"]},"author":"Stackable GmbH","purl":"'"$PURL"'","publisher":"Stackable GmbH"}}} * .[0]' sbom.json > sbom.merged.json; |
| 125 | + # Attest the SBOM to the image |
| 126 | + cosign attest -y --predicate sbom.merged.json --type cyclonedx "$IMAGE_NAME@$DIGEST" |
0 commit comments