Skip to content

Commit

Permalink
Default to GHCR instead of DockerHub for install
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bestbeforetoday authored and denyeart committed Feb 12, 2025
1 parent 0f75fdc commit 0211a21
Showing 1 changed file with 67 additions and 10 deletions.
77 changes: 67 additions & 10 deletions scripts/install-fabric.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ _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}

# Fabric < 1.2 uses uname -m for architecture.
MARCH=$(uname -m)

HYPERLEDGER_NAMESPACE=hyperledger
DOCKER_NAMESPACE="${FABRIC_DOCKER_REGISTRY:-${HYPERLEDGER_NAMESPACE}}"


die()
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0211a21

Please sign in to comment.