From 95b92627aa84bf73744724f02fbffd367c2c6751 Mon Sep 17 00:00:00 2001 From: Dominique Roux Date: Thu, 29 Dec 2016 14:36:46 +0100 Subject: [PATCH] Added --state absent functionality to docker types Changed types: __docker __docker_compose --- cdist/conf/type/__docker/manifest | 56 ++++++++++--------- .../type/__docker/parameter/default/state | 1 + cdist/conf/type/__docker/parameter/optional | 1 + .../conf/type/__docker_compose/gencode-remote | 13 +++-- cdist/conf/type/__docker_compose/manifest | 11 +++- .../__docker_compose/parameter/default/state | 1 + .../type/__docker_compose/parameter/optional | 1 + 7 files changed, 51 insertions(+), 33 deletions(-) create mode 100644 cdist/conf/type/__docker/parameter/default/state create mode 100644 cdist/conf/type/__docker/parameter/optional create mode 100644 cdist/conf/type/__docker_compose/parameter/default/state diff --git a/cdist/conf/type/__docker/manifest b/cdist/conf/type/__docker/manifest index ba13b3e4..1f473afb 100755 --- a/cdist/conf/type/__docker/manifest +++ b/cdist/conf/type/__docker/manifest @@ -20,38 +20,39 @@ os=$(cat "$__global/explorer/os") +state=$(cat "$__object/parameter/state") case "$os" in - centos) - component="main" + centos) + component="main" + if [ -f "$__object/parameter/experimental" ]; then + component="experimental" + fi + __yum_repo docker \ + --name 'Docker Repository' \ + --baseurl "https://yum.dockerproject.org/repo/$component/centos/\$releasever/" \ + --enabled \ + --gpgcheck 1 \ + --gpgkey 'https://yum.dockerproject.org/gpg' \ + --state ${state} + require="__yum_repo/docker" __package docker-engine --state ${state} + ;; + ubuntu) + component="main" if [ -f "$__object/parameter/experimental" ]; then component="experimental" fi - export CDIST_ORDER_DEPENDENCY=on - __yum_repo docker \ - --name 'Docker Repository' \ - --baseurl "https://yum.dockerproject.org/repo/$component/centos/\$releasever/" \ - --enabled \ - --gpgcheck \ - --gpgkey 'https://yum.dockerproject.org/gpg' - __package docker-engine - unset CDIST_ORDER_DEPENDENCY - ;; - ubuntu) - component="main" - if [ -f "$__object/parameter/experimental" ]; then - component="experimental" - fi - __package apparmor - __package ca-certificates - __package apt-transport-https - __apt_key docker --keyid 58118E89F3A912897C070ADBF76221572C52609D + __package apparmor --state ${state} + __package ca-certificates --state ${state} + __package apt-transport-https --state ${state} + __apt_key docker --keyid 58118E89F3A912897C070ADBF76221572C52609D --state ${state} export CDIST_ORDER_DEPENDENCY=on __apt_source docker \ --uri https://apt.dockerproject.org/repo \ --distribution "ubuntu-$(cat "$__global/explorer/lsb_codename")" \ + --state ${state} \ --component "$component" - __package docker-engine + __package docker-engine --state ${state} unset CDIST_ORDER_DEPENDENCY ;; debian) @@ -60,16 +61,17 @@ case "$os" in component="experimental" fi - __package apt-transport-https - __package ca-certificates - __package gnupg2 - __apt_key docker --keyid 58118E89F3A912897C070ADBF76221572C52609D + __package apt-transport-https --state ${state} + __package ca-certificates --state ${state} + __package gnupg2 --state ${state} + __apt_key docker --keyid 58118E89F3A912897C070ADBF76221572C52609D --state ${state} export CDIST_ORDER_DEPENDENCY=on __apt_source docker \ --uri https://apt.dockerproject.org/repo \ --distribution "debian-$(cat "$__global/explorer/lsb_codename")" \ + --state ${state} \ --component "$component" - __package docker-engine + __package docker-engine --state ${state} unset CDIST_ORDER_DEPENDENCY ;; diff --git a/cdist/conf/type/__docker/parameter/default/state b/cdist/conf/type/__docker/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__docker/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__docker/parameter/optional b/cdist/conf/type/__docker/parameter/optional new file mode 100644 index 00000000..ff72b5c7 --- /dev/null +++ b/cdist/conf/type/__docker/parameter/optional @@ -0,0 +1 @@ +state diff --git a/cdist/conf/type/__docker_compose/gencode-remote b/cdist/conf/type/__docker_compose/gencode-remote index 3424ed6d..bd1ad452 100644 --- a/cdist/conf/type/__docker_compose/gencode-remote +++ b/cdist/conf/type/__docker_compose/gencode-remote @@ -20,9 +20,12 @@ # Variables version="$(cat "$__object/parameter/version")" +state="$(cat "$__object/parameter/state")" -# Download docker-compose file - echo 'curl -L "https://github.com/docker/compose/releases/download/'${version}'/docker-compose-$(uname -s)-$(uname -m)" -o /tmp/docker-compose' - echo 'mv /tmp/docker-compose /usr/local/bin/docker-compose' -# Change permissions -echo 'chmod +x /usr/local/bin/docker-compose' +if [ ${state} = "present" ]; then + # Download docker-compose file + echo 'curl -L "https://github.com/docker/compose/releases/download/'${version}'/docker-compose-$(uname -s)-$(uname -m)" -o /tmp/docker-compose' + echo 'mv /tmp/docker-compose /usr/local/bin/docker-compose' + # Change permissions + echo 'chmod +x /usr/local/bin/docker-compose' +fi diff --git a/cdist/conf/type/__docker_compose/manifest b/cdist/conf/type/__docker_compose/manifest index 2ff80aca..113e87e9 100644 --- a/cdist/conf/type/__docker_compose/manifest +++ b/cdist/conf/type/__docker_compose/manifest @@ -19,6 +19,15 @@ # # +state="$(cat "$__object/parameter/state")" + # Needed packages -__docker +__docker --state ${state} __package curl + +if [ ${state} = "absent" ]; then + __file /usr/local/bin/docker-compose --state absent +elif [ ${state} != "present" -a ${state} != "absent" ]; then + echo "Unknown state: $state_should" >&2 + exit 1 +fi diff --git a/cdist/conf/type/__docker_compose/parameter/default/state b/cdist/conf/type/__docker_compose/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__docker_compose/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__docker_compose/parameter/optional b/cdist/conf/type/__docker_compose/parameter/optional index 088eda41..4d595ed7 100644 --- a/cdist/conf/type/__docker_compose/parameter/optional +++ b/cdist/conf/type/__docker_compose/parameter/optional @@ -1 +1,2 @@ +state version