forked from balena-io-experimental/balena-aerofs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aerofs-docker.sh
38 lines (30 loc) · 1.37 KB
/
aerofs-docker.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
#!/bin/bash
set -ex
mkdir -p /ship/loader/run
[[ -f /ship/loader/run/repo ]] || echo 'registry.aerofs.com' > /ship/loader/run/repo
[[ -f /ship/loader/run/target ]] || echo 'maintenance' > /ship/loader/run/target
[[ -f /ship/loader/run/tag ]] || {
TAG=$(docker run --rm $(cat /ship/loader/run/repo)/aerofs/loader tag)
echo ${TAG} > /ship/loader/run/tag
}
IMAGES=$(docker run --rm -v /var/run/docker.sock:/var/run/docker.sock $(cat \
/ship/loader/run/repo)/aerofs/loader images)
for i in ${IMAGES}; do
IMAGE="$(cat /ship/loader/run/repo)/${i}:$(cat /ship/loader/run/tag)"
set +e; docker inspect "${IMAGE}" 1>/dev/null 2>/dev/null; EXIT=$?; set -e
[[ ${EXIT} = 0 ]] || docker pull "${IMAGE}"
done
while true; do
IMAGE="$(cat /ship/loader/run/repo)/aerofs/loader:$(cat /ship/loader/run/tag)"
CONTAINER=loader-$(cat /ship/loader/run/tag)
[[ "$(docker ps -a | grep ${CONTAINER})" ]] || \
docker create --name "${CONTAINER}" \
-v /var/run/docker-aerofs.sock:/var/run/docker.sock \
-v /ship/loader/run/repo:/host/ship/loader/run/repo \
-v /ship/loader/run/tag:/host/ship/loader/run/tag \
-v /ship/loader/run/target:/host/ship/loader/run/target \
"${IMAGE}" load /host/ship/loader/run/repo /host/ship/loader/run/tag /host/ship/loader/run/target
echo 'Starting Loader...'
docker start -a "${CONTAINER}"
echo 'Loader stopped'
done