Skip to content

Commit 7354f12

Browse files
committed
Merge pull request #3752 from mboersma/fix-check-repos
Clean up old git repos and images on destroy
2 parents bccb3b7 + a11775d commit 7354f12

5 files changed

Lines changed: 19 additions & 26 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

publisher/server/publisher.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,13 @@ func (s *Server) publishContainer(container *docker.APIContainers, ttl time.Dura
109109
appName := match[1]
110110
appPath := fmt.Sprintf("%s/%s", appName, containerName)
111111
keyPath := fmt.Sprintf("/deis/services/%s", appPath)
112-
dirPath := fmt.Sprintf("/deis/services/%s", appName)
113112
for _, p := range container.Ports {
114113
// lowest port wins (docker sorts the ports)
115114
// TODO (bacongobbler): support multiple exposed ports
116115
port := strconv.Itoa(int(p.PublicPort))
117116
hostAndPort := s.host + ":" + port
118117
if s.IsPublishableApp(containerName) && s.IsPortOpen(hostAndPort) {
119118
s.setEtcd(keyPath, hostAndPort, uint64(ttl.Seconds()))
120-
s.updateDir(dirPath, uint64(ttl.Seconds()))
121119
safeMap.Lock()
122120
safeMap.data[container.ID] = appPath
123121
safeMap.Unlock()
@@ -234,14 +232,3 @@ func (s *Server) removeEtcd(key string, recursive bool) {
234232
log.Println("del", key)
235233
}
236234
}
237-
238-
// updateDir updates the given directory for a given ttl. It succeeds
239-
// only if the given directory already exists.
240-
func (s *Server) updateDir(directory string, ttl uint64) {
241-
if _, err := s.EtcdClient.UpdateDir(directory, ttl); err != nil {
242-
log.Println(err)
243-
}
244-
if s.logLevel == "debug" {
245-
log.Println("updateDir", directory)
246-
}
247-
}

0 commit comments

Comments
 (0)