Skip to content

Commit 0211a21

Browse files
bestbeforetodaydenyeart
authored andcommitted
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 <[email protected]>
1 parent 0f75fdc commit 0211a21

File tree

1 file changed

+67
-10
lines changed

1 file changed

+67
-10
lines changed

scripts/install-fabric.sh

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ _arg_comp=('' )
2424
_arg_fabric_version="2.5.11"
2525
_arg_ca_version="1.5.15"
2626

27-
REGISTRY=${FABRIC_DOCKER_REGISTRY:-docker.io/hyperledger}
28-
2927
OS=$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')
3028
ARCH=$(uname -m | sed 's/x86_64/amd64/g' | sed 's/aarch64/arm64/g')
3129
PLATFORM=${OS}-${ARCH}
3230

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

34+
HYPERLEDGER_NAMESPACE=hyperledger
35+
DOCKER_NAMESPACE="${FABRIC_DOCKER_REGISTRY:-${HYPERLEDGER_NAMESPACE}}"
36+
3637

3738
die()
3839
{
@@ -142,21 +143,77 @@ assign_positional_args()
142143

143144
singleImagePull() {
144145
#three_digit_image_tag is passed in, e.g. "1.4.7"
145-
three_digit_image_tag=$1
146+
local three_digit_image_tag=$1
146147
shift
147148
#two_digit_image_tag is derived, e.g. "1.4", especially useful as a local tag for two digit references
149+
local two_digit_image_tag
148150
two_digit_image_tag=$(echo "$three_digit_image_tag" | cut -d'.' -f1,2)
149-
while [[ $# -gt 0 ]]
150-
do
151-
image_name="$1"
152-
echo "====> ${REGISTRY}/fabric-$image_name:$three_digit_image_tag"
153-
${CONTAINER_CLI} pull "${REGISTRY}/fabric-$image_name:$three_digit_image_tag"
154-
${CONTAINER_CLI} tag "${REGISTRY}/fabric-$image_name:$three_digit_image_tag" "${REGISTRY}/fabric-$image_name"
155-
${CONTAINER_CLI} tag "${REGISTRY}/fabric-$image_name:$three_digit_image_tag" "${REGISTRY}/fabric-$image_name:$two_digit_image_tag"
151+
152+
153+
while [[ $# -gt 0 ]]; do
154+
local component_name="$1"
155+
local registry
156+
registry="$(dockerComponentRegistry "${component_name}" "${three_digit_image_tag}")"
157+
local image_name="${registry}/fabric-${component_name}:${three_digit_image_tag}"
158+
159+
echo "====> ${image_name}"
160+
${CONTAINER_CLI} pull "${image_name}"
161+
162+
163+
${CONTAINER_CLI} tag "${image_name}" "${DOCKER_NAMESPACE}/fabric-${component_name}"
164+
${CONTAINER_CLI} tag "${image_name}" "${DOCKER_NAMESPACE}/fabric-${component_name}:${two_digit_image_tag}"
165+
# Re-tag 3-digit version to ensure there is a tag without registry prefix
166+
${CONTAINER_CLI} tag "${image_name}" "${DOCKER_NAMESPACE}/fabric-${component_name}:${three_digit_image_tag}"
167+
156168
shift
157169
done
158170
}
159171

172+
dockerComponentRegistry() {
173+
if [[ -n ${FABRIC_DOCKER_REGISTRY} ]]; then
174+
echo -n "${FABRIC_DOCKER_REGISTRY}"
175+
return
176+
fi
177+
178+
local component="$1"
179+
local image_version="$2"
180+
181+
case "${component}" in
182+
ca)
183+
echo -n "$(dockerCARegistry "${image_version}")/${HYPERLEDGER_NAMESPACE}"
184+
;;
185+
*)
186+
echo -n "$(dockerFabricRegistry "${image_version}")/${HYPERLEDGER_NAMESPACE}"
187+
;;
188+
esac
189+
}
190+
191+
dockerCARegistry() {
192+
local version="$1"
193+
194+
case "${version}" in
195+
1.[0-4].*|1.5.[0-9]|1.5.1[0-4])
196+
echo -n 'docker.io'
197+
;;
198+
*)
199+
echo -n 'ghcr.io'
200+
;;
201+
esac
202+
}
203+
204+
dockerFabricRegistry() {
205+
local version="$1"
206+
207+
case "${version}" in
208+
1.*|2.[0-4].*|2.5.[0-9]|2.5.10|3.0.0)
209+
echo -n 'docker.io'
210+
;;
211+
*)
212+
echo -n 'ghcr.io'
213+
;;
214+
esac
215+
}
216+
160217
cloneSamplesRepo() {
161218
# clone (if needed) hyperledger/fabric-samples and checkout corresponding
162219
# version to the binaries and docker images to be downloaded

0 commit comments

Comments
 (0)