Skip to content

Commit 20174e4

Browse files
committed
fix(builder): check etcd dir itself before deleting repo
1 parent d51816e commit 20174e4

4 files changed

Lines changed: 19 additions & 13 deletions

File tree

builder/rootfs/bin/boot

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,14 @@ docker build -t deis/slugrunner /usr/local/src/slugrunner/
7777
/usr/sbin/sshd -D -e &
7878
SSHD_PID=$!
7979

80+
# start a cleanup script to remote old repositories and images
81+
/bin/cleanup &
82+
CLEANUP_PID=$!
83+
8084
# smart shutdown on SIGINT and SIGTERM
8185
function on_exit() {
82-
kill -TERM $DOCKER_PID $SSHD_PID
83-
wait $DOCKER_PID $SSHD_PID 2>/dev/null
86+
kill -TERM $DOCKER_PID $SSHD_PID $CLEANUP_PID
87+
wait $DOCKER_PID $SSHD_PID $CLEANUP_PID 2>/dev/null
8488
exit 0
8589
}
8690
trap on_exit INT TERM EXIT

builder/rootfs/bin/cleanup

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
export ETCD=${ETCD:-$HOST:4001}
4+
5+
while true
6+
do
7+
etcdctl -C $ETCD watch --recursive /deis/services
8+
/home/git/check-repos
9+
done

builder/rootfs/etc/confd/conf.d/check-repos.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ uid = 0
55
gid = 0
66
mode = "0755"
77
keys = [
8-
"/deis/services",
98
"/deis/registry",
109
]
11-
reload_cmd = "/home/git/check-repos"

builder/rootfs/etc/confd/templates/check-repos

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
#!/usr/bin/env bash
22

3-
listcontains() {
4-
for word in $1; do
5-
[[ $word = $2 ]] && return 0
6-
done
7-
return 1
8-
}
3+
export ETCD=${ETCD:-$HOST:4001}
94

105
cd $(dirname $0) # absolute path
116

12-
for repo in *.git;
7+
for repo in *.git
138
do
149
reponame="${repo%.*}"
15-
appname="{{ getv "/deis/registry/host" }}:{{ getv "/deis/registry/port" }}/$reponame"
16-
if ! listcontains "{{ join (lsdir "/deis/services/*") " " }}" "$reponame";
10+
if ! etcdctl -C $ETCD ls /deis/services/"$reponame" > /dev/null 2>&1
1711
then
1812
rm -rf "$repo"
13+
appname="{{ getv "/deis/registry/host" }}:{{ getv "/deis/registry/port" }}/$reponame"
1914
docker images | grep $appname | awk '{ print $3 }' | xargs -r docker rmi -f
2015
# remove any dangling images left over from the cleanup
2116
docker images --filter "dangling=true" | awk '{ print $3 }' | grep -v IMAGE | xargs -r docker rmi -f

0 commit comments

Comments
 (0)