# Note: Intended to be run as "make test-push-pull" or "test-push-pull-verbose" # Makefile target installs & checks all necessary tooling # Extra tools that are not covered in Makefile target needs to be added in verify_prerequisites() load helpers_zot function verify_prerequisites { if [ ! $(command -v curl) ]; then echo "you need to install curl as a prerequisite to running the tests" >&3 return 1 fi if [ ! $(command -v jq) ]; then echo "you need to install jq as a prerequisite to running the tests" >&3 return 1 fi return 0 } function setup_file() { # Verify prerequisites are available if ! $(verify_prerequisites); then exit 1 fi # Download test data to folder common for the entire suite, not just this file skopeo --insecure-policy copy --format=oci docker://ghcr.io/project-zot/golang:1.20 oci:${TEST_DATA_DIR}/golang:1.20 # Setup zot server local zot_root_dir=${BATS_FILE_TMPDIR}/zot local zot_config_file=${BATS_FILE_TMPDIR}/zot_config.json local oci_data_dir=${BATS_FILE_TMPDIR}/oci mkdir -p ${zot_root_dir} mkdir -p ${oci_data_dir} cat > ${zot_config_file}< config.json echo "hello world" > artifact.txt run oras push --plain-http 127.0.0.1:8080/hello-artifact:v2 \ --config config.json:application/vnd.acme.rocket.config.v1+json artifact.txt:text/plain -d -v [ "$status" -eq 0 ] rm -f artifact.txt rm -f config.json } @test "pull oras artifact" { run oras pull --plain-http 127.0.0.1:8080/hello-artifact:v2 -d -v [ "$status" -eq 0 ] grep -q "hello world" artifact.txt rm -f artifact.txt } @test "attach oras artifacts" { # attach signature echo "{\"artifact\": \"\", \"signature\": \"pat hancock\"}" > ${BATS_FILE_TMPDIR}/signature.json run oras attach --plain-http 127.0.0.1:8080/golang:1.20 --image-spec v1.1-image --artifact-type 'signature/example' ${BATS_FILE_TMPDIR}/signature.json:application/json [ "$status" -eq 0 ] # attach sbom echo "{\"version\": \"0.0.0.0\", \"artifact\": \"'127.0.0.1:8080/golang:1.20'\", \"contents\": \"good\"}" > ${BATS_FILE_TMPDIR}/sbom.json run oras attach --plain-http 127.0.0.1:8080/golang:1.20 --image-spec v1.1-image --artifact-type 'sbom/example' ${BATS_FILE_TMPDIR}/sbom.json:application/json [ "$status" -eq 0 ] } @test "discover oras artifacts" { run oras discover --plain-http -o json 127.0.0.1:8080/golang:1.20 [ "$status" -eq 0 ] [ $(echo "$output" | jq -r ".manifests | length") -eq 2 ] } @test "push helm chart" { run helm package ${BATS_FILE_TMPDIR}/helm-charts/charts/zot -d ${BATS_FILE_TMPDIR} [ "$status" -eq 0 ] local chart_version=$(awk '/version/{printf $2}' ${BATS_FILE_TMPDIR}/helm-charts/charts/zot/Chart.yaml) run helm push ${BATS_FILE_TMPDIR}/zot-${chart_version}.tgz oci://localhost:8080/zot-chart [ "$status" -eq 0 ] } @test "pull helm chart" { local chart_version=$(awk '/version/{printf $2}' ${BATS_FILE_TMPDIR}/helm-charts/charts/zot/Chart.yaml) run helm pull oci://localhost:8080/zot-chart/zot --version ${chart_version} -d ${BATS_FILE_TMPDIR} [ "$status" -eq 0 ] } @test "push image with regclient" { run regctl registry set localhost:8080 --tls disabled [ "$status" -eq 0 ] run regctl image copy ocidir://${TEST_DATA_DIR}/golang:1.20 localhost:8080/test-regclient [ "$status" -eq 0 ] } @test "pull image with regclient" { run regctl image copy localhost:8080/test-regclient ocidir://${TEST_DATA_DIR}/golang:1.20 [ "$status" -eq 0 ] } @test "list repositories with regclient" { run regctl repo ls localhost:8080 [ "$status" -eq 0 ] found=0 for i in "${lines[@]}" do if [ "$i" = 'test-regclient' ]; then found=1 fi done [ "$found" -eq 1 ] } @test "list image tags with regclient" { run regctl tag ls localhost:8080/test-regclient [ "$status" -eq 0 ] found=0 for i in "${lines[@]}" do if [ "$i" = 'latest' ]; then found=1 fi done [ "$found" -eq 1 ] } @test "push manifest with regclient" { manifest=$(regctl manifest get localhost:8080/test-regclient --format=raw-body) run regctl manifest put localhost:8080/test-regclient:1.0.0 --format oci --content-type application/vnd.oci.image.manifest.v1+json --format oci <