-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-entrypoint.sh
executable file
·71 lines (52 loc) · 1.54 KB
/
new-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
#!/bin/sh
registry_address=${REGISTRY_HTTP_ADDR:-localhost:5000}
start_docker() {
docker daemon --host=unix:///var/run/docker.sock \
--host=tcp://0.0.0.0:2375 \
--storage-driver=vfs \
--pidfile=/var/run/docker.pid
}
stop_docker() {
kill -9 `cat /var/run/docker.pid`
}
clean_local_registry() {
docker system prune -a
}
populate_registry() {
start_docker &
# give it some time to set up
sleep 10
input="/images/names"
if [ ! -s "$input" ]; then
echo "WARNING: names file doesn't exist or is empty."
clean_local_registry
stop_docker
return
fi
cd /images
line_no=0
while IFS= read -r line
do
line_no=$((line_no+1))
file="$(echo ${line} | cut -d' ' -f1)"
tag="$(echo ${line} | cut -d' ' -f2)"
version="$(echo ${line} | cut -d' ' -f3)"
if [ "${file}" = "" ] || [ "${tag}" = "" ] || [ "${version}" = "" ]; then
echo "Skipping line ${line_no}, not enough parameters."
continue
fi
basename=$(basename $file .tar)
echo "Adding: file '${file}' (basename '$basename') as '${tag}:${version}'"
docker import ${file} ${tag}:${version}
docker tag ${basename} ${registry_address}/${tag}
docker push ${registry_address}/${tag}
done < "$input"
clean_local_registry
stop_docker
}
if [ -d "/images" ]; then
populate_registry &
else
echo "WARNING: The directory /images doesn't exist. Nothing to populate."
fi
/bin/sh /entrypoint.sh "$@"