github.com/cactusblossom/fabric-ca@v0.0.0-20200611062428-0082fc643826/scripts/multiarch.sh (about)

     1  #!/bin/sh
     2  #
     3  # Copyright IBM Corp. All Rights Reserved.
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  #
     7  # This script publishes the fabric docker images to hyperledger dockerhub and nexus3 repositories.
     8  # when publishing the images to dockerhub the values for NS_PULL & NS_PUSH variables set to default values.
     9  # when publishing the images to nexus3 repository the values for NS_PULL & NS_PUSH variables set like below
    10  # NS_PULL=nexus3.hyperledger.org:10001/hyperledger & NS_PUSH=nexus3.hyperledger.org:10002/hyperledger
    11  # since nexus has separate port numbers to pull and push the images to nexus3.
    12  
    13  usage() {
    14    echo "Usage: $0 <username> <password>"
    15    echo "<username> and <password> credentials for the repository"
    16    echo "ENV:"
    17    echo "  NS_PULL=$NS_PULL"
    18    echo "  NS_PUSH=$NS_PUSH"
    19    echo "  VERSION=$VERSION"
    20    echo "  TWO_DIGIT_VERSION=$TWO_DIGIT_VERSION"
    21    exit 1
    22  }
    23  
    24  missing() {
    25    echo "Error: some image(s) missing from registry"
    26    echo "ENV:"
    27    echo "  NS_PULL=$NS_PULL"
    28    echo "  NS_PUSH=$NS_PUSH"
    29    echo "  VERSION=$VERSION"
    30    echo "  TWO_DIGIT_VERSION=$TWO_DIGIT_VERSION"
    31    exit 1
    32  }
    33  
    34  failed() {
    35    echo "Error: multiarch manifest push failed"
    36    echo "ENV:"
    37    echo "  NS_PULL=$NS_PULL"
    38    echo "  NS_PUSH=$NS_PUSH"
    39    echo "  VERSION=$VERSION"
    40    echo "  TWO_DIGIT_VERSION=$TWO_DIGIT_VERSION"
    41    exit 1
    42  }
    43  
    44  USER=${1:-nobody}
    45  PASSWORD=${2:-nohow}
    46  NS_PULL=${NS_PULL:-hyperledger}
    47  NS_PUSH=${NS_PUSH:-hyperledger}
    48  VERSION=${BASE_VERSION}
    49  TWO_DIGIT_VERSION=${TWO_DIGIT_VERSION:-1.4}
    50  
    51  if [ "$#" -ne 2 ]; then
    52    usage
    53  fi
    54  
    55  # verify that manifest-tool is installed and found on PATH
    56  which manifest-tool
    57  if [ "$?" -ne 0 ]; then
    58    echo "manifest-tool not installed or not found on PATH"
    59    exit 1
    60  fi
    61  
    62  IMAGES="fabric-ca"
    63  
    64  # check that all images have been published
    65  for image in ${IMAGES}; do
    66    docker pull ${NS_PULL}/${image}:amd64-${VERSION} || missing
    67    docker pull ${NS_PULL}/${image}:s390x-${VERSION} || missing
    68  done
    69  
    70  # push the multiarch manifest and tag with $VERSION,$TWO_DIGIT_VERSION and latest tag
    71  for image in ${IMAGES}; do
    72    manifest-tool --username ${USER} --password ${PASSWORD} push from-args\
    73     --platforms linux/amd64,linux/s390x --template "${NS_PULL}/${image}:ARCH-${VERSION}"\
    74     --target "${NS_PUSH}/${image}:${VERSION}"
    75    manifest-tool --username ${USER} --password ${PASSWORD} push from-args\
    76     --platforms linux/amd64,linux/s390x --template "${NS_PULL}/${image}:ARCH-${VERSION}"\
    77     --target "${NS_PUSH}/${image}:latest"
    78    manifest-tool --username ${USER} --password ${PASSWORD} push from-args\
    79     --platforms linux/amd64,linux/s390x --template "${NS_PULL}/${image}:ARCH-${VERSION}"\
    80     --target "${NS_PUSH}/${image}:${TWO_DIGIT_VERSION}"
    81  done
    82  
    83  # test that manifest is working as expected
    84  for image in ${IMAGES}; do
    85    docker pull ${NS_PULL}/${image}:${VERSION} || failed
    86    docker pull ${NS_PULL}/${image}:${TWO_DIGIT_VERSION} || failed
    87    docker pull ${NS_PULL}/${image}:latest || failed
    88  done
    89  
    90  echo "Successfully pushed multiarch manifest"
    91  exit 0