forked from openshift-metal3/dev-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoc_mirror.sh
executable file
·83 lines (63 loc) · 2.19 KB
/
oc_mirror.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash
set -euxo pipefail
# Utility functions to create a local mirror registry using 'mirror-registry' and mirror
# a release using 'oc mirror'
function add_auth_to_pull_secret() {
quay_auths=$1
tmpauthfile=$(mktemp --tmpdir "quayauth--XXXXXXXXXX")
_tmpfiles="$_tmpfiles $tmpauthfile"
tmppullsecret=$(mktemp --tmpdir "pullsecret--XXXXXXXXXX")
_tmpfiles="$_tmpfiles $tmppullsecret"
cat > "${tmpauthfile}" << EOF
{
"auths": {
"${LOCAL_REGISTRY_DNS_NAME}:${LOCAL_REGISTRY_PORT}": {
"auth": "$quay_auths"
}
}
}
EOF
jq -s '.[0] * .[1]' ${tmpauthfile} ${PULL_SECRET_FILE} > ${tmppullsecret}
cp ${tmppullsecret} ${PULL_SECRET_FILE}
}
function update_docker_config() {
if [[ -f ${DOCKER_CONFIG_FILE} ]]; then
cp ${DOCKER_CONFIG_FILE} ${DOCKER_CONFIG_FILE}.old
fi
cp ${PULL_SECRET_FILE} ${DOCKER_CONFIG_FILE}
}
function setup_quay_mirror_registry() {
mkdir -p ${WORKING_DIR}/quay-install
pushd ${WORKING_DIR}/mirror-registry
sudo ./mirror-registry install --quayHostname ${LOCAL_REGISTRY_DNS_NAME}:${LOCAL_REGISTRY_PORT} --quayRoot ${WORKING_DIR}/quay-install/ --initUser ${REGISTRY_USER} --initPassword ${REGISTRY_PASS} --sslCheckSkip -v
quay_auths=`echo -n "${REGISTRY_USER}:${REGISTRY_PASS}" | base64 -w0`
add_auth_to_pull_secret ${quay_auths}
popd
}
# Set up a mirror using the 'oc mirror' command
# The backend registry can be either 'podman' or 'quay'
function setup_oc_mirror() {
update_docker_config
# Create imageset containing the local URL and the OCP release to mirror
tmpimageset=$(mktemp --tmpdir "imageset--XXXXXXXXXX")
_tmpfiles="$_tmpfiles $tmpimageset"
cat > "${tmpimageset}" << EOF
apiVersion: mirror.openshift.io/v1alpha2
kind: ImageSetConfiguration
archiveSize: 4
storageConfig:
registry:
imageURL: ${LOCAL_REGISTRY_DNS_NAME}:${LOCAL_REGISTRY_PORT}/origin:latest
skipTLS: true
mirror:
platform:
channels:
- name: candidate-${OPENSHIFT_RELEASE_STREAM}
type: ocp
additionalImages:
- name: registry.redhat.io/ubi8/ubi:latest
EOF
pushd ${WORKING_DIR}
oc mirror --dest-skip-tls --config ${tmpimageset} docker://${LOCAL_REGISTRY_DNS_NAME}:${LOCAL_REGISTRY_PORT}
popd
}