|
23 | 23 | build-docker:
|
24 | 24 | runs-on: ubuntu-latest
|
25 | 25 | permissions:
|
26 |
| - packages: read |
| 26 | + packages: write # to push the test docker image |
27 | 27 | steps:
|
28 | 28 |
|
29 | 29 | - name: Check out repository
|
@@ -67,10 +67,78 @@ jobs:
|
67 | 67 | run: make setup-integration-test-utility-for-docker
|
68 | 68 |
|
69 | 69 | # Run the integration tests against the built Docker image.
|
70 |
| - - name: Test the Docker image |
| 70 | + # - name: Test the Docker image |
| 71 | + # env: |
| 72 | + # # This environment variable will be picked up by run_macaron.sh. |
| 73 | + # MACARON_IMAGE_TAG: test |
| 74 | + # DOCKER_PULL: never |
| 75 | + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + # run: make integration-test-docker |
| 77 | + |
| 78 | + # Push the test Docker image. |
| 79 | + - name: Push the Docker image |
| 80 | + id: push-docker |
| 81 | + env: |
| 82 | + IMAGE_NAME: ghcr.io/oracle/macaron |
| 83 | + RELEASE_TAG: test |
| 84 | + run: | |
| 85 | + make push-docker-test |
| 86 | + IMAGE_AND_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' "$IMAGE_NAME") |
| 87 | + NAME=$(echo "$IMAGE_AND_DIGEST" | cut -d'@' -f1 | cut -d':' -f1) |
| 88 | + DIGEST=$(echo "$IMAGE_AND_DIGEST" | cut -d'@' -f2) |
| 89 | + { |
| 90 | + echo "image-name=${NAME}" |
| 91 | + echo "image-digest=${DIGEST}" |
| 92 | + } >> "$GITHUB_OUTPUT" |
| 93 | +
|
| 94 | + # Generate the Docker image SBOM under the dist/ directory which will be published as part of the release assets. |
| 95 | + - name: Generate Docker sbom |
71 | 96 | env:
|
72 |
| - # This environment variable will be picked up by run_macaron.sh. |
73 |
| - MACARON_IMAGE_TAG: test |
74 |
| - DOCKER_PULL: never |
75 |
| - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
76 |
| - run: make integration-test-docker |
| 97 | + SYFT_BIN: ${{ github.workspace }}/bin |
| 98 | + RELEASE_TAG: test |
| 99 | + RELEASE_VERSION: test |
| 100 | + SYFT_VERSION: 1.29.0 |
| 101 | + # We install Syft, which is an SBOM generator tool for Docker images, using the instructions from: |
| 102 | + # https://github.com/anchore/syft#installation |
| 103 | + # We only generate SBOM in CycloneDX format. |
| 104 | + run: | |
| 105 | + mkdir -p "$SYFT_BIN" |
| 106 | + ASSET_NAME="syft_${SYFT_VERSION}_linux_amd64.tar.gz" |
| 107 | + CHECKSUMS="syft_${SYFT_VERSION}_checksums.txt" |
| 108 | +
|
| 109 | + # Download artifacts. |
| 110 | + echo "Downloading $ASSET_NAME" |
| 111 | + curl --output "$ASSET_NAME" --progress-bar --location \ |
| 112 | + "https://github.com/anchore/syft/releases/download/v${SYFT_VERSION}/${ASSET_NAME}" |
| 113 | + test -s "$ASSET_NAME" || (echo "Unable to download $ASSET_NAME" && exit 0) |
| 114 | + echo "Downloading $CHECKSUMS" |
| 115 | + curl --output "$CHECKSUMS" --progress-bar --location \ |
| 116 | + "https://github.com/anchore/syft/releases/download/v${SYFT_VERSION}/${CHECKSUMS}" |
| 117 | + test -s "$CHECKSUMS" || (echo "Unable to download $CHECKSUMS" && exit 0) |
| 118 | +
|
| 119 | + EXPECTED=$(grep "${ASSET_NAME}" "${CHECKSUMS}" 2>/dev/null | tr '\t' ' ' | cut -d ' ' -f 1) |
| 120 | + SYFT_DIGEST=$(sha256sum "$ASSET_NAME" | cut -d ' ' -f 1) |
| 121 | +
|
| 122 | + # Check if artifact is valid. |
| 123 | + if [ "$EXPECTED" == "$SYFT_DIGEST" ]; then |
| 124 | + tar -zxvf "$ASSET_NAME" -C "$SYFT_BIN" syft |
| 125 | + "$SYFT_BIN"/syft --version |
| 126 | + "$SYFT_BIN"/syft \ |
| 127 | + ghcr.io/oracle/macaron:"$RELEASE_TAG" \ |
| 128 | + -o cyclonedx-json=dist/macaron-"$RELEASE_VERSION"-sbom-docker.json |
| 129 | + else |
| 130 | + echo "Checksum for '$ASSET_NAME' did not verify: expected $EXPECTED but got $SYFT_DIGEST" |
| 131 | + fi |
| 132 | +
|
| 133 | + # Remove the downloaded artifacts. |
| 134 | + rm -f "$ASSET_NAME" |
| 135 | + rm -f "$CHECKSUMS" |
| 136 | +
|
| 137 | + # Upload the SBOM. |
| 138 | + - name: Upload the SBOM |
| 139 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 140 | + with: |
| 141 | + name: sbom-macaron-test |
| 142 | + path: dist/macaron-test-sbom-docker.json |
| 143 | + if-no-files-found: error |
| 144 | + retention-days: 7 |
0 commit comments