This repository was archived by the owner on Oct 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·160 lines (137 loc) · 3.1 KB
/
entrypoint.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
mountpoint="/var/lib/registry"
checkfile="${mountpoint}/exist"
mkdir -p "${mountpoint}"
mkdir -p /var/log/
mkdir -p /etc/us3fs/
cat <<EOF >/etc/us3fs/us3fs.conf
bucket: ${BUCKET}
access_key: ${ACCESS_KEY}
secret_key: ${SECRET_KEY}
endpoint: ${ENDPOINT}
EOF
modprobe fuse
us3fs -f --passwd=/etc/us3fs/us3fs.conf --keep_pagecache "${BUCKET}" "${mountpoint}" ${US3FS_OPTS} &
us3fs_pid=$!
for i in {1..10}; do
if [ "$(df | grep -o ${mountpoint})" == "${mountpoint}" ]; then
echo "mount success"
break
fi
echo "wait the bucket mounting"
sleep 1
done
if [ "$(df | grep -o ${mountpoint})" != "${mountpoint}" ]; then
echo "mount failed"
exit 1
fi
if [ ! -f "${checkfile}" ]; then
echo "${BUCKET}" >"${checkfile}"
else
if [ "$(cat "${checkfile}")" != "${BUCKET}" ]; then
echo "The bucket has been changed, please remove the old one and mount the new one."
echo "In ${checkfile} is ${BUCKET}, the old bucket is $(cat "${checkfile}")"
exit 1
fi
fi
mkdir -p /etc/docker/registry/
function registry_mirror_config() {
cat <<EOF
version: 0.1
log:
accesslog:
disabled: true
storage:
filesystem:
rootdirectory: ${mountpoint}
maintenance:
readonly:
enabled: ${MIRROR_READ_ONLY:-false}
delete:
enabled: ${MIRROR_DELETE:-false}
http:
addr: ${MIRROR_PORT:-0.0.0.0:5000}
headers:
X-Content-Type-Options: [nosniff]
health:
storagedriver:
enabled: false
validation:
disabled: true
compatibility:
schema1:
enabled: true
EOF
if [[ "${MIRROR_REDIRECT}" != "" ]]; then
cat <<EOF
middleware:
storage:
- name: redirect
options:
baseurl: ${MIRROR_REDIRECT}
EOF
fi
if [[ "${MIRROR_REMOTE_URL}" != "" ]]; then
cat <<EOF
proxy:
remoteurl: ${MIRROR_REMOTE_URL}
EOF
fi
}
function registry_sync_config() {
cat <<EOF
version: 0.1
log:
accesslog:
disabled: true
storage:
filesystem:
rootdirectory: ${mountpoint}
maintenance:
readonly:
enabled: ${SYNC_READ_ONLY:-false}
delete:
enabled: ${SYNC_DELETE:-false}
http:
addr: ${SYNC_PORT:-0.0.0.0:80}
headers:
X-Content-Type-Options: [nosniff]
health:
storagedriver:
enabled: false
validation:
disabled: true
compatibility:
schema1:
enabled: true
EOF
}
registry_mirror_config >/etc/docker/registry/config-mirror.yml
registry serve /etc/docker/registry/config-mirror.yml &
registry_mirror_pid=$!
registry_sync_config >/etc/docker/registry/config-sync.yml
registry serve /etc/docker/registry/config-sync.yml &
registry_sync_pid=$!
echo "Started"
echo "us3fs pid: ${us3fs_pid}"
echo "registry_mirror pid: ${registry_mirror_pid}"
echo "registry_sync pid: ${registry_sync_pid}"
while true; do
if ! kill -0 "${us3fs_pid}" >/dev/null 2>&1; then
echo "PANIC: us3fs is not running"
exit 1
fi
if ! kill -0 "${registry_mirror_pid}" >/dev/null 2>&1; then
echo "PANIC: registry_mirror is not running"
exit 1
fi
if ! kill -0 "${registry_sync_pid}" >/dev/null 2>&1; then
echo "PANIC: registry_sync is not running"
exit 1
fi
if [ ! -f "${checkfile}" ]; then
echo "PANIC: ${checkfile} is not exist"
exit 1
fi
sleep 1
done