From 7f1be920d6f958da53cdce3aafaf6a9b86d87b9b Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 2 Feb 2020 22:20:17 +0000 Subject: [PATCH] Add some docker util scripts --- .../docker/files/docker-utils/hard-reset-all.sh | 13 +++++++++++++ ansible/roles/docker/files/docker-utils/pull-all.sh | 7 +++++++ .../roles/docker/files/docker-utils/start-all.sh | 11 +++++++++++ ansible/roles/docker/files/docker-utils/stop-all.sh | 11 +++++++++++ ansible/roles/docker/tasks/setup-docker.yml | 7 +++++++ 5 files changed, 49 insertions(+) create mode 100755 ansible/roles/docker/files/docker-utils/hard-reset-all.sh create mode 100755 ansible/roles/docker/files/docker-utils/pull-all.sh create mode 100755 ansible/roles/docker/files/docker-utils/start-all.sh create mode 100755 ansible/roles/docker/files/docker-utils/stop-all.sh diff --git a/ansible/roles/docker/files/docker-utils/hard-reset-all.sh b/ansible/roles/docker/files/docker-utils/hard-reset-all.sh new file mode 100755 index 0000000..37fbbda --- /dev/null +++ b/ansible/roles/docker/files/docker-utils/hard-reset-all.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -e + +for compose_file in /opt/**/docker-compose.yml; do + if [[ $(docker-compose -f $compose_file ps -q) ]]; then + docker-compose -f $compose_file down --remove-orphans + docker-compose -f $compose_file up -d + else + echo "> Skipping $compose_file as it's not running." + fi + +done diff --git a/ansible/roles/docker/files/docker-utils/pull-all.sh b/ansible/roles/docker/files/docker-utils/pull-all.sh new file mode 100755 index 0000000..28e90c2 --- /dev/null +++ b/ansible/roles/docker/files/docker-utils/pull-all.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -e + +for compose_file in /opt/**/docker-compose.yml; do + docker-compose -f $compose_file pull --parallel +done diff --git a/ansible/roles/docker/files/docker-utils/start-all.sh b/ansible/roles/docker/files/docker-utils/start-all.sh new file mode 100755 index 0000000..cc838b2 --- /dev/null +++ b/ansible/roles/docker/files/docker-utils/start-all.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -e + +for compose_file in /opt/**/docker-compose.yml; do + if [[ ! $(docker-compose -f $compose_file ps -q) ]]; then + docker-compose -f $compose_file up -d + else + echo "> Skipping $compose_file as it's running." + fi +done diff --git a/ansible/roles/docker/files/docker-utils/stop-all.sh b/ansible/roles/docker/files/docker-utils/stop-all.sh new file mode 100755 index 0000000..c3849cb --- /dev/null +++ b/ansible/roles/docker/files/docker-utils/stop-all.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -e + +for compose_file in /opt/**/docker-compose.yml; do + if [[ $(docker-compose -f $compose_file ps -q) ]]; then + docker-compose -f $compose_file down --remove-orphans + else + echo "> Skipping $compose_file as it's not running." + fi +done diff --git a/ansible/roles/docker/tasks/setup-docker.yml b/ansible/roles/docker/tasks/setup-docker.yml index 61ccaaa..60d855e 100644 --- a/ansible/roles/docker/tasks/setup-docker.yml +++ b/ansible/roles/docker/tasks/setup-docker.yml @@ -35,3 +35,10 @@ name: clean up docker containers special_time: weekly job: "docker system prune" + +- name: Install util scripts + copy: + src: ./files/docker-utils + dest: "{{ home }}" + mode: 0755 + directory_mode: 0755