From 0211a21efb5a917dca9d222eaf7407eca72f54b2 Mon Sep 17 00:00:00 2001 From: "Mark S. Lewis" Date: Wed, 12 Feb 2025 16:37:31 +0000 Subject: [PATCH] Default to GHCR instead of DockerHub for install DockerHub has imposed more restrictive image pull limits and costs for business users. GitHub Container Registry (GHCR) remains freely accessible. This change updates the Fabric install script to use GHCR to pull Docker images, where those image versions are available. For image versions not available on GHCR, fall back to DockerHub. Signed-off-by: Mark S. Lewis --- scripts/install-fabric.sh | 77 ++++++++++++++++++++++++++++++++++----- 1 file changed, 67 insertions(+), 10 deletions(-) diff --git a/scripts/install-fabric.sh b/scripts/install-fabric.sh index ee294fc682a..8852e2226b1 100755 --- a/scripts/install-fabric.sh +++ b/scripts/install-fabric.sh @@ -24,8 +24,6 @@ _arg_comp=('' ) _arg_fabric_version="2.5.11" _arg_ca_version="1.5.15" -REGISTRY=${FABRIC_DOCKER_REGISTRY:-docker.io/hyperledger} - OS=$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/') ARCH=$(uname -m | sed 's/x86_64/amd64/g' | sed 's/aarch64/arm64/g') PLATFORM=${OS}-${ARCH} @@ -33,6 +31,9 @@ PLATFORM=${OS}-${ARCH} # Fabric < 1.2 uses uname -m for architecture. MARCH=$(uname -m) +HYPERLEDGER_NAMESPACE=hyperledger +DOCKER_NAMESPACE="${FABRIC_DOCKER_REGISTRY:-${HYPERLEDGER_NAMESPACE}}" + die() { @@ -142,21 +143,77 @@ assign_positional_args() singleImagePull() { #three_digit_image_tag is passed in, e.g. "1.4.7" - three_digit_image_tag=$1 + local three_digit_image_tag=$1 shift #two_digit_image_tag is derived, e.g. "1.4", especially useful as a local tag for two digit references + local two_digit_image_tag two_digit_image_tag=$(echo "$three_digit_image_tag" | cut -d'.' -f1,2) - while [[ $# -gt 0 ]] - do - image_name="$1" - echo "====> ${REGISTRY}/fabric-$image_name:$three_digit_image_tag" - ${CONTAINER_CLI} pull "${REGISTRY}/fabric-$image_name:$three_digit_image_tag" - ${CONTAINER_CLI} tag "${REGISTRY}/fabric-$image_name:$three_digit_image_tag" "${REGISTRY}/fabric-$image_name" - ${CONTAINER_CLI} tag "${REGISTRY}/fabric-$image_name:$three_digit_image_tag" "${REGISTRY}/fabric-$image_name:$two_digit_image_tag" + + + while [[ $# -gt 0 ]]; do + local component_name="$1" + local registry + registry="$(dockerComponentRegistry "${component_name}" "${three_digit_image_tag}")" + local image_name="${registry}/fabric-${component_name}:${three_digit_image_tag}" + + echo "====> ${image_name}" + ${CONTAINER_CLI} pull "${image_name}" + + + ${CONTAINER_CLI} tag "${image_name}" "${DOCKER_NAMESPACE}/fabric-${component_name}" + ${CONTAINER_CLI} tag "${image_name}" "${DOCKER_NAMESPACE}/fabric-${component_name}:${two_digit_image_tag}" + # Re-tag 3-digit version to ensure there is a tag without registry prefix + ${CONTAINER_CLI} tag "${image_name}" "${DOCKER_NAMESPACE}/fabric-${component_name}:${three_digit_image_tag}" + shift done } +dockerComponentRegistry() { + if [[ -n ${FABRIC_DOCKER_REGISTRY} ]]; then + echo -n "${FABRIC_DOCKER_REGISTRY}" + return + fi + + local component="$1" + local image_version="$2" + + case "${component}" in + ca) + echo -n "$(dockerCARegistry "${image_version}")/${HYPERLEDGER_NAMESPACE}" + ;; + *) + echo -n "$(dockerFabricRegistry "${image_version}")/${HYPERLEDGER_NAMESPACE}" + ;; + esac +} + +dockerCARegistry() { + local version="$1" + + case "${version}" in + 1.[0-4].*|1.5.[0-9]|1.5.1[0-4]) + echo -n 'docker.io' + ;; + *) + echo -n 'ghcr.io' + ;; + esac +} + +dockerFabricRegistry() { + local version="$1" + + case "${version}" in + 1.*|2.[0-4].*|2.5.[0-9]|2.5.10|3.0.0) + echo -n 'docker.io' + ;; + *) + echo -n 'ghcr.io' + ;; + esac +} + cloneSamplesRepo() { # clone (if needed) hyperledger/fabric-samples and checkout corresponding # version to the binaries and docker images to be downloaded