diff --git a/tasks/create-pyxis-image/create-pyxis-image.yaml b/tasks/create-pyxis-image/create-pyxis-image.yaml index 3e466cbf7..07a95ad35 100644 --- a/tasks/create-pyxis-image/create-pyxis-image.yaml +++ b/tasks/create-pyxis-image/create-pyxis-image.yaml @@ -157,7 +157,7 @@ spec: fi # Save the OCI manifest locally, to pass to a script to create the pyxis entry - MANIFEST_FILE="/tmp/oras-manifest-fetch.json" + MANIFEST_FILE="$(workspaces.data.path)/oras-manifest-fetch.json" oras manifest fetch \ --registry-config "$AUTH_FILE" \ "${ORAS_ARGS[@]}" \ diff --git a/tasks/create-pyxis-image/tests/mocks.sh b/tasks/create-pyxis-image/tests/mocks.sh index de1d7f292..10d7b840a 100644 --- a/tasks/create-pyxis-image/tests/mocks.sh +++ b/tasks/create-pyxis-image/tests/mocks.sh @@ -9,7 +9,7 @@ function create_container_image() { # e.g. 0001, 0002, 0003... echo The image id is $(awk 'END{printf("%04i", NR)}' $(workspaces.data.path)/mock_create_container_image.txt) - if [[ "$*" != "--pyxis-url https://pyxis.preprod.api.redhat.com/ --certified false --tags "*" --is-latest false --verbose --oras-manifest-fetch /tmp/oras-manifest-fetch.json --name "*" --media-type my_media_type --digest "*" --architecture-digest "*" --architecture "*" --rh-push "* ]] + if [[ "$*" != "--pyxis-url https://pyxis.preprod.api.redhat.com/ --certified false --tags "*" --is-latest false --verbose --oras-manifest-fetch /workspace/data/oras-manifest-fetch.json --name "*" --media-type my_media_type+gzip --digest "*" --architecture-digest "*" --architecture "*" --rh-push "* ]] then echo Error: Unexpected call echo Mock create_container_image called with: $* @@ -32,7 +32,7 @@ function skopeo() { echo $* >> $(workspaces.data.path)/mock_skopeo.txt if [[ "$*" == "inspect --raw docker://"* ]] || [[ "$*" == "inspect --no-tags --override-os linux --override-arch "*" docker://"* ]] then - echo '{"mediaType": "my_media_type"}' + echo '{"mediaType": "my_media_type+gzip"}' else echo Mock skopeo called with: $* if [[ "$*" != "inspect --no-tags docker://"* ]] @@ -61,9 +61,18 @@ function oras() { if [[ "$*" == "manifest fetch --registry-config"*.dockerfile ]] then echo '{"layers": [{"annotations": {"org.opencontainers.image.title": "Dockerfile.custom"}}]}' + elif [[ "$*" == "blob fetch --registry-config"*"/tmp/oras-blob-fetch-beef.gz"* ]] + then + echo -n 'H4sIAAAAAAAAA0vKzEssqlRISSxJVEjPTy1WyEgtSgUAXVhZVxUAAAA=' | base64 -d > /tmp/oras-blob-fetch-beef.gz + elif [[ "$*" == "blob fetch --registry-config"*"/tmp/oras-blob-fetch-pork.gz"* ]] + then + echo -n 'H4sIAAAAAAAAA8vNL0pVSEksSQQA2pxWLAkAAAA=' | base64 -d > /tmp/oras-blob-fetch-pork.gz + elif [[ "$*" == "manifest fetch --registry-config"*image-with-gzipped-layers* ]] + then + echo '{"mediaType": "my_media_type", "layers": [{"mediaType": "blob+gzip", "digest": "beef"}, {"mediaType": "blob+gzip", "digest": "pork"}]}' elif [[ "$*" == "manifest fetch --registry-config"* ]] then - echo '{"mediaType": "my_media_type"}' + echo '{"mediaType": "my_media_type", "layers": [{"mediaType": "blob+other", "digest": "tofu"}]}' elif [[ "$*" == "pull --registry-config"*dockerfile-not-found:sha256-*.dockerfile* ]] then echo Mock oras called with: $* diff --git a/tasks/create-pyxis-image/tests/test-create-pyxis-image-with-gzipped-layers.yaml b/tasks/create-pyxis-image/tests/test-create-pyxis-image-with-gzipped-layers.yaml new file mode 100644 index 000000000..0f34063f9 --- /dev/null +++ b/tasks/create-pyxis-image/tests/test-create-pyxis-image-with-gzipped-layers.yaml @@ -0,0 +1,97 @@ +--- +apiVersion: tekton.dev/v1 +kind: Pipeline +metadata: + name: test-create-pyxis-image-with-gzipped-layers +spec: + description: | + Run the create-pyxis-image task with an image that has gzipped layers, to + see that we reported the uncompressed digests correctly + workspaces: + - name: tests-workspace + tasks: + - name: setup + workspaces: + - name: data + workspace: tests-workspace + taskSpec: + workspaces: + - name: data + steps: + - name: setup-values + image: quay.io/konflux-ci/release-service-utils:65d8db844c008e7736ec8dff307868525279484d + script: | + #!/usr/bin/env bash + set -eux + + cat > "$(workspaces.data.path)"/mapped_snapshot.json << EOF + { + "application": "myapp", + "components": [ + { + "name": "comp", + "containerImage": "source@sha256:mydigest", + "repository": "registry.io/image-with-gzipped-layers", + "tags": [ + "testtag" + ] + } + ] + } + EOF + - name: run-task + taskRef: + name: create-pyxis-image + params: + - name: pyxisSecret + value: test-create-pyxis-image-cert + - name: server + value: stage + - name: snapshotPath + value: mapped_snapshot.json + workspaces: + - name: data + workspace: tests-workspace + runAfter: + - setup + - name: check-result + params: + - name: pyxisDataPath + value: $(tasks.run-task.results.pyxisDataPath) + workspaces: + - name: data + workspace: tests-workspace + taskSpec: + params: + - name: pyxisDataPath + type: string + workspaces: + - name: data + steps: + - name: check-result + image: quay.io/konflux-ci/release-service-utils:65d8db844c008e7736ec8dff307868525279484d + script: | + #!/usr/bin/env bash + set -eux + + if [ "$(wc -l < "$(workspaces.data.path)"/mock_create_container_image.txt)" != 1 ]; then + echo Error: create_container_image was expected to be called 1 time. Actual calls: + cat "$(workspaces.data.path)/mock_create_container_image.txt" + exit 1 + fi + + if [ "$(wc -l < "$(workspaces.data.path)"/mock_oras.txt)" != 5 ]; then + echo Error: oras was expected to be called 4 times. Actual calls: + cat "$(workspaces.data.path)/mock_oras.txt" + exit 1 + fi + + [ "$(head -n 1 < "$(workspaces.data.path)"/mock_skopeo.txt)" \ + = "inspect --raw docker://registry.io/image-with-gzipped-layers@sha256:mydigest" ] + + # check that the size of the decompressed layers is as expected + jq -e '.uncompressed_layers[0].size == 21' "$(workspaces.data.path)/oras-manifest-fetch.json" + jq -e '.uncompressed_layers[1].size == 9' "$(workspaces.data.path)/oras-manifest-fetch.json" + + runAfter: + - run-task