github.com/metasources/buildx@v0.0.0-20230418141019-7aa1459cedea/test/compare/rpm.sh (about)

     1  #!/usr/bin/env bash
     2  set -eux
     3  set -o pipefail
     4  
     5  DISTDIR=$1
     6  ACC_DIR=$2
     7  TEST_IMAGE=$3
     8  RESULTSDIR=$4
     9  
    10  EXIT_CODE=1
    11  TEST_TYPE=rpm
    12  WORK_DIR=`mktemp -d -t "buildx-acceptance-test-${TEST_TYPE}-XXXXXX"`
    13  NORMAL_TEST_IMAGE=$(echo ${TEST_IMAGE} | tr ':' '-' )
    14  REPORT=${WORK_DIR}/acceptance-${TEST_TYPE}-${NORMAL_TEST_IMAGE}.json
    15  GOLDEN_REPORT=${ACC_DIR}/test-fixtures/acceptance-${NORMAL_TEST_IMAGE}.json
    16  
    17  # check if tmp dir was created
    18  if [[ ! "${WORK_DIR}" || ! -d "${WORK_DIR}" ]]; then
    19    echo "Could not create temp dir"
    20    exit 1
    21  fi
    22  
    23  function cleanup {
    24    rm -rf "${WORK_DIR}"
    25    exit ${EXIT_CODE}
    26  }
    27  
    28  trap cleanup EXIT
    29  
    30  # fetch test image
    31  docker pull ${TEST_IMAGE}
    32  
    33  # install and run buildx
    34  docker run --rm \
    35      -v /var/run/docker.sock://var/run/docker.sock \
    36      -v /${PWD}:/src \
    37      -v ${WORK_DIR}:${WORK_DIR} \
    38      -e BUILDX_CHECK_FOR_APP_UPDATE=0 \
    39      -w /src \
    40      centos:latest \
    41          /bin/bash -x -c "\
    42              rpm -ivh ${DISTDIR}/buildx_*_linux_amd64.rpm && \
    43              buildx version && \
    44              buildx packages ${TEST_IMAGE} -vv -o json > ${REPORT} \
    45          "
    46  
    47  # keep the generated report around
    48  mkdir -p ${RESULTSDIR}
    49  cp ${REPORT} ${RESULTSDIR}
    50  
    51  # compare the results to a known good output
    52  ${ACC_DIR}/compare.py \
    53      ${GOLDEN_REPORT} \
    54      ${REPORT} | tee ${RESULTSDIR}/acceptance-${TEST_TYPE}.txt
    55  
    56  EXIT_CODE=0