Skip to content

Commit a583e4b

Browse files
authored
Merge pull request docker-archive#470 from docker/aws_vacuum
Added swarm wide vacuum job to cleanup unused resources
2 parents 2882e8c + a8adf5d commit a583e4b

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

aws/cloudformation/docker_for_aws.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@
4444
"Default" : "3",
4545
"AllowedValues" : ["1", "3", "5"],
4646
"Description" : "Number of Swarm manager nodes (1, 3, 5)"
47+
},
48+
"EnableSystemPrune" : {
49+
"Type" : "String",
50+
"Default" : "no",
51+
"AllowedValues" : ["no", "yes"],
52+
"Description" : "Cleans up unused images, containers, networks and volumes"
4753
}
54+
4855
},
4956
"Metadata" : {
5057
"AWS::CloudFormation::Interface" : {
@@ -55,15 +62,16 @@
5562
},
5663
{
5764
"Label" : { "default":"Swarm Properties" },
58-
"Parameters" : [ "ManagerInstanceType", "InstanceType", "KeyName" ]
65+
"Parameters" : [ "ManagerInstanceType", "InstanceType", "KeyName", "EnableSystemPrune" ]
5966
}
6067
],
6168
"ParameterLabels" : {
6269
"ManagerSize" : { "default" : "Number of Swarm managers?" },
6370
"ClusterSize" : { "default" : "Number of Swarm worker nodes?" },
6471
"InstanceType" : { "default" : "Agent worker instance type?" },
6572
"ManagerInstanceType" : { "default" : "Swarm manager instance type?" },
66-
"KeyName" : { "default" : "Which SSH key to use?" }
73+
"KeyName" : { "default" : "Which SSH key to use?" },
74+
"EnableSystemPrune": {"default" : "Enable daily resource cleanup?"}
6775
}
6876
}
6977
},
@@ -602,6 +610,7 @@
602610
"-e ACCOUNT_ID='",{ "Ref" : "AWS::AccountId" }, "' ",
603611
"-e SWARM_QUEUE='",{ "Ref" : "SwarmSQS" }, "' ",
604612
"-e CLEANUP_QUEUE='",{ "Ref" : "SwarmSQSCleanup" }, "' ",
613+
"-e RUN_VACUUM='",{ "Ref" : "EnableSystemPrune" }, "' ",
605614
"-e DOCKER_FOR_IAAS_VERSION=$DOCKER_FOR_IAAS_VERSION ",
606615
"-v /var/run/docker.sock:/var/run/docker.sock ",
607616
"-v /usr/bin/docker:/usr/bin/docker ",
@@ -739,6 +748,7 @@
739748
"-e ACCOUNT_ID='",{ "Ref" : "AWS::AccountId" }, "' ",
740749
"-e SWARM_QUEUE='",{ "Ref" : "SwarmSQS" }, "' ",
741750
"-e CLEANUP_QUEUE='",{ "Ref" : "SwarmSQSCleanup" }, "' ",
751+
"-e RUN_VACUUM='",{ "Ref" : "EnableSystemPrune" }, "' ",
742752
"-e DOCKER_FOR_IAAS_VERSION=$DOCKER_FOR_IAAS_VERSION ",
743753
"-v /var/run/docker.sock:/var/run/docker.sock ",
744754
"-v /usr/bin/docker:/usr/bin/docker ",

aws/dockerfiles/Dockerfile.guide

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ ADD files/guide/crontab.txt /usr/docker/crontab.txt
1818
ADD files/guide/watcher.sh /usr/bin
1919
ADD files/guide/cleanup.sh /usr/bin
2020
ADD files/guide/buoy.sh /usr/bin
21+
ADD files/guide/vacuum.sh /usr/bin
2122
ADD files/bin/buoy /usr/bin
2223
COPY files/guide/entry.sh /entry.sh
2324
RUN chmod 755 /usr/bin/watcher.sh /entry.sh /usr/bin/cleanup.sh \
24-
/usr/bin/buoy /usr/bin/buoy.sh
25+
/usr/bin/buoy /usr/bin/buoy.sh /usr/bin/vacuum.sh
2526
RUN /usr/bin/crontab /usr/docker/crontab.txt
2627

2728
CMD ["/entry.sh"]

aws/dockerfiles/files/guide/crontab.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*/1 * * * * /usr/bin/watcher.sh >> /var/log/docker/watcher.log
33
*/5 * * * * /usr/bin/cleanup.sh >> /var/log/docker/cleanup.log
44
24 * * * * /usr/bin/buoy.sh >> /var/log/docker/buoy.log
5+
42 * * * * /usr/bin/vacuum.sh >> /var/log/docker/vacuum.log

aws/dockerfiles/files/guide/vacuum.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
# default to no.
4+
RUN_VACUUM=${RUN_VACUUM:-"no"}
5+
6+
if [[ "$RUN_VACUUM" != "yes" ]] ; then
7+
exit 0
8+
fi
9+
10+
# sleep for a random amount of time, so that we don't run this at the same time on all nodes.
11+
sleep $[ ( $RANDOM % 240 ) + 1 ]
12+
13+
docker system prune --force

0 commit comments

Comments
 (0)