Debian Codegraph @

script/cri-containerd/mirror.sh

raw
1 #!/bin/bash
2
3 # Copyright The containerd Authors.
4
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8
9 # http://www.apache.org/licenses/LICENSE-2.0
10
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 set -euo pipefail
18
19 if [ "${TOOLS_DIR}" == "" ] ; then
20 echo "tools dir must be provided"
21 exit 1
22 fi
23 LIST_FILE="${TOOLS_DIR}/list"
24 HOST_FILE="${TOOLS_DIR}/host"
25 SS_REPO="/go/src/github.com/containerd/stargz-snapshotter"
26
27 RETRYNUM=30
28 RETRYINTERVAL=1
29 TIMEOUTSEC=180
30 function retry {
31 local SUCCESS=false
32 for i in $(seq ${RETRYNUM}) ; do
33 if eval "timeout ${TIMEOUTSEC} ${@}" ; then
34 SUCCESS=true
35 break
36 fi
37 echo "Fail(${i}). Retrying..."
38 sleep ${RETRYINTERVAL}
39 done
40 if [ "${SUCCESS}" == "true" ] ; then
41 return 0
42 else
43 return 1
44 fi
45 }
46
47 cd "${SS_REPO}"
48 git config --global --add safe.directory "${SS_REPO}"
49 PREFIX=/out/ make ctr-remote
50 mv /out/ctr-remote /bin/ctr-remote
51
52 containerd &
53 retry ctr-remote version
54
55 HOST=$(cat "${HOST_FILE}")
56 cat "${LIST_FILE}" | sort | uniq | while read IMAGE ; do
57 MIRROR_URL="${HOST}"$(echo "${IMAGE}" | sed -E 's/^[^/]*//g' | sed -E 's/@.*//g')
58 echo "Mirroring: ${IMAGE} to ${MIRROR_URL}"
59 ctr-remote images pull "${IMAGE}"
60 ctr-remote images optimize --oci --period=1 "${IMAGE}" "${MIRROR_URL}"
61 ctr-remote images push --plain-http "${MIRROR_URL}"
62 done