Skip to content

Commit

Permalink
ansible: automatic clean-up of binary_tmp repo
Browse files Browse the repository at this point in the history
  • Loading branch information
joaocgreis committed Oct 3, 2018
1 parent 160e434 commit c0a483f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ansible/roles/jenkins-workspace/files/clean_binary_tmp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash -ex

cd ~binary_tmp/binary_tmp.git
(echo; date) >> ~binary_tmp/clean_binary_tmp.log

git fetch origin +master:master

for b in $(git branch | sed /\*/d); do
if [ -z "$(git log -1 --since='4 weeks ago' -s $b)" ]; then
(git branch -D $b || true) |& tee -a ~binary_tmp/clean_binary_tmp.log
fi
done

git prune

du -sh ~binary_tmp/binary_tmp.git/ >> ~binary_tmp/clean_binary_tmp.log
14 changes: 14 additions & 0 deletions ansible/roles/jenkins-workspace/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,17 @@
line: "MaxStartups 100:30:150"
dest: "{{ ssh_config }}"
regexp: "MaxStartups"

- name: Create clean-up script
copy:
src: "{{ role_path }}/files/clean_binary_tmp.sh"
dest: "~binary_tmp/clean_binary_tmp.sh"
owner: "binary_tmp"
group: "binary_tmp"
mode: 0755

- name: Schedule clean-up script to run weekly
lineinfile:
line: "0 5 * * 0 binary_tmp ~binary_tmp/clean_binary_tmp.sh"
dest: "/etc/crontab"
regexp: "clean_binary_tmp"

0 comments on commit c0a483f

Please sign in to comment.