zotregistry.dev/zot@v1.4.4-0.20240314164342-eec277e14d20/test/blackbox/multiarch_index.bats (about)

     1  # Note: Intended to be run as "make run-blackbox-tests" or "make run-blackbox-ci"
     2  #       Makefile target installs & checks all necessary tooling
     3  #       Extra tools that are not covered in Makefile target needs to be added in verify_prerequisites()
     4  
     5  load helpers_zot
     6  
     7  function verify_prerequisites {
     8      if [ ! $(command -v regctl) ]; then
     9          echo "you need to install regctl as a prerequisite to running the tests" >&3
    10          return 1
    11      fi
    12  
    13      return 0
    14  }
    15  
    16  function setup_file() {
    17      # Verify prerequisites are available
    18      if ! $(verify_prerequisites); then
    19          exit 1
    20      fi
    21      # Setup zot server
    22      local zot_root_dir=${BATS_FILE_TMPDIR}/zot
    23      local zot_config_file=${BATS_FILE_TMPDIR}/zot_config.json
    24      local oci_data_dir=${BATS_FILE_TMPDIR}/oci
    25      mkdir -p ${zot_root_dir}
    26      mkdir -p ${oci_data_dir}
    27      zot_port=$(get_free_port)
    28      echo ${zot_port} > ${BATS_FILE_TMPDIR}/zot.port
    29      cat > ${zot_config_file}<<EOF
    30  {
    31      "distSpecVersion": "1.1.0",
    32      "storage": {
    33          "rootDirectory": "${zot_root_dir}"
    34      },
    35      "http": {
    36          "address": "0.0.0.0",
    37          "port": "${zot_port}"
    38      },
    39      "log": {
    40          "level": "debug",
    41          "output": "${BATS_FILE_TMPDIR}/zot.log"
    42      }
    43  }
    44  EOF
    45      zot_serve ${ZOT_PATH} ${zot_config_file}
    46      wait_zot_reachable ${zot_port}
    47  }
    48  
    49  function teardown() {
    50      # conditionally printing on failure is possible from teardown but not from from teardown_file
    51      cat ${BATS_FILE_TMPDIR}/zot.log
    52  }
    53  
    54  function teardown_file() {
    55      zot_stop_all
    56  }
    57  
    58  @test "push linux/amd64 image" {
    59      zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port`
    60      run regctl registry set localhost:${zot_port} --tls disabled
    61      [ "$status" -eq 0 ]
    62      echo "Pushing ghcr.io/project-zot/zot-minimal:latest image to local zot registry, for linux/amd64 platform"
    63      run regctl image copy \
    64        ghcr.io/project-zot/zot-minimal:latest \
    65        localhost:${zot_port}/test-index/zot-minimal-amd64:latest \
    66        --platform=linux/amd64
    67      [ "$status" -eq 0 ]
    68  }
    69  
    70  @test "push linux/arm64 image" {
    71      zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port`
    72      echo "Pushing ghcr.io/project-zot/zot-minimal:latest image to local zot registry, for linux/arm64 platform"
    73      run regctl image copy \
    74        ghcr.io/project-zot/zot-minimal:latest \
    75        localhost:${zot_port}/test-index/zot-minimal-arm64:latest \
    76        --platform=linux/arm64
    77      [ "$status" -eq 0 ]
    78  }
    79  
    80  @test "create multi-arch index" {
    81      zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port`
    82      echo "Creating the multi-arch zot-minimal:latest index using linux/amd64 and linux/arm64 images, in local zot registry"
    83      run regctl index create \
    84        localhost:${zot_port}/test-index/zot-minimal:latest \
    85        --ref=localhost:${zot_port}/test-index/zot-minimal-amd64:latest \
    86        --ref=localhost:${zot_port}/test-index/zot-minimal-arm64:latest \
    87        --digest-tags --referrers
    88      [ "$status" -eq 0 ]
    89  }
    90  
    91  @test "modify multi-arch image" {
    92      zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port`
    93      echo "Modifying the multi-arch zot-minimal:latest image attributes in local zot registry (suitable for Docker to OCI format conversion, or better conformance, scenarios)"
    94      run regctl image mod \
    95        localhost:${zot_port}/test-index/zot-minimal:latest \
    96        --replace \
    97        --to-oci \
    98        --to-oci-referrers \
    99        --label-to-annotation \
   100        --annotation="[*]org.opencontainers.image.title=zot-minimal" \
   101        --annotation="[*]org.opencontainers.image.description=Zot OCI registry" \
   102        --annotation="[*]org.opencontainers.image.authors=authors@zotregistry.dev" \
   103        --annotation="[*]org.opencontainers.image.licenses=Apache-2.0" \
   104        --annotation="[*]org.opencontainers.image.url=localhost:${zot_port}/test-index/zot-minimal:latest" \
   105        --annotation="[*]org.opencontainers.image.source=https://github.com/project-zot/zot" \
   106        --annotation="[*]org.opencontainers.image.version=latest" \
   107        --annotation="[*]org.opencontainers.image.created=$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
   108      [ "$status" -eq 0 ]
   109  }