1+ #! /bin/bash
2+ # Copyright © 2021 Alibaba Group Holding Ltd.
3+ #
4+ # Licensed under the Apache License, Version 2.0 (the "License");
5+ # you may not use this file except in compliance with the License.
6+ # You may obtain a copy of the License at
7+ #
8+ # http://www.apache.org/licenses/LICENSE-2.0
9+ #
10+ # Unless required by applicable law or agreed to in writing, software
11+ # distributed under the License is distributed on an "AS IS" BASIS,
12+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ # See the License for the specific language governing permissions and
14+ # limitations under the License.
15+
16+
17+ set -e
18+ set -x
19+ # prepare registry storage as directory
20+ cd $( dirname " $0 " )
21+
22+ REGISTRY_PORT=${1-5000}
23+ VOLUME=${2-/ var/ lib/ registry}
24+ REGISTRY_DOMAIN=${3-sea.hub}
25+
26+ container=sealer-registry
27+ rootfs=$( dirname " $( pwd) " )
28+ config=" $rootfs /etc/registry_config.yml"
29+ htpasswd=" $rootfs /etc/registry_htpasswd"
30+ certs_dir=" $rootfs /certs"
31+
32+ mkdir -p " $VOLUME " || true
33+
34+ startRegistry () {
35+ n=1
36+ while (( n <= 3 ))
37+ do
38+ echo " attempt to start registry"
39+ (nerdctl start $container && break) || (( n < 3 ))
40+ (( n++ ))
41+ sleep 3
42+ done
43+ }
44+
45+ check_registry () {
46+ n=1
47+ while (( n <= 3 ))
48+ do
49+ (nerdctl inspect sealer-registry | grep " \" Status\" : \" running\" " ) && break
50+ if [[ $n -eq 3 ]]; then
51+ echo " sealer-registry is not running, status: $registry_status "
52+ exit 1
53+ fi
54+ (( n++ ))
55+ sleep 3
56+ done
57+ }
58+
59+
60+ # # rm container if exist.
61+ ! nerdctl ps -a | grep sealer-registry || nerdctl rmi -f sealer-registry
62+ # #
63+ rm -rf /var/lib/nerdctl/1935db59/names/default/$container
64+
65+ regArgs=" -d --restart=always \
66+ --net=host \
67+ --name $container \
68+ -v $certs_dir :/certs \
69+ -v $VOLUME :/var/lib/registry \
70+ -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/$REGISTRY_DOMAIN .crt \
71+ -e REGISTRY_HTTP_TLS_KEY=/certs/$REGISTRY_DOMAIN .key"
72+
73+ if [ -f $config ]; then
74+ sed -i " s/5000/$1 /g" $config
75+ regArgs=" $regArgs \
76+ -v $config :/etc/docker/registry/config.yml"
77+ fi
78+
79+ if [ -f $htpasswd ]; then
80+ nerdctl run $regArgs \
81+ -v $htpasswd :/htpasswd \
82+ -e REGISTRY_AUTH=htpasswd \
83+ -e REGISTRY_AUTH_HTPASSWD_PATH=/htpasswd \
84+ -e REGISTRY_AUTH_HTPASSWD_REALM=" Registry Realm" registry:2.7.1 || startRegistry
85+ else
86+ nerdctl run $regArgs registry:2.7.1 || startRegistry
87+ fi
88+
89+ sleep 1
90+ check_registry
0 commit comments