From 95b92627aa84bf73744724f02fbffd367c2c6751 Mon Sep 17 00:00:00 2001 From: Dominique Roux Date: Thu, 29 Dec 2016 14:36:46 +0100 Subject: [PATCH 1/5] 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 From 54a58abcaa23357d14f3825b5e31ee121a7b1ec2 Mon Sep 17 00:00:00 2001 From: Dominique Roux Date: Thu, 29 Dec 2016 14:47:29 +0100 Subject: [PATCH 2/5] Changed man.rst of __docker and __docker_compose - Added state parameter for both types in the man.rst - Changed --state absent behavior of __docker_compose -- only remove docker-compose binary not whole docker --- cdist/conf/type/__docker/man.rst | 9 ++++++++- cdist/conf/type/__docker_compose/man.rst | 7 +++++++ cdist/conf/type/__docker_compose/manifest | 10 +++++----- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cdist/conf/type/__docker/man.rst b/cdist/conf/type/__docker/man.rst index 42e71af5..70b92cc7 100644 --- a/cdist/conf/type/__docker/man.rst +++ b/cdist/conf/type/__docker/man.rst @@ -26,17 +26,24 @@ BOOLEAN PARAMETERS experimental Install the experimental docker-engine package instead of the latest stable release. +state + 'present' or 'absent', defaults to 'present' + EXAMPLES -------- .. code-block:: sh + # Install docker __docker - # experimental + # Install experimental __docker --experimental + # Remove docker + __docker --state absent + AUTHORS ------- diff --git a/cdist/conf/type/__docker_compose/man.rst b/cdist/conf/type/__docker_compose/man.rst index 720a306e..d54b3370 100644 --- a/cdist/conf/type/__docker_compose/man.rst +++ b/cdist/conf/type/__docker_compose/man.rst @@ -21,6 +21,9 @@ OPTIONAL PARAMETERS version Define docker_compose version, defaults to "1.9.0" +state + 'present' or 'absent', defaults to 'present' + BOOLEAN PARAMETERS ------------------ @@ -32,11 +35,15 @@ EXAMPLES .. code-block:: sh + # Install docker-compose __docker_compose # Install version 1.9.0-rc4 __docker_compose --version 1.9.0-rc4 + # Remove docker-compose + __docker_compose --state absent + AUTHORS ------- diff --git a/cdist/conf/type/__docker_compose/manifest b/cdist/conf/type/__docker_compose/manifest index 113e87e9..3ab27c63 100644 --- a/cdist/conf/type/__docker_compose/manifest +++ b/cdist/conf/type/__docker_compose/manifest @@ -22,12 +22,12 @@ state="$(cat "$__object/parameter/state")" # Needed packages -__docker --state ${state} -__package curl - -if [ ${state} = "absent" ]; then +if [ ${state} = "present" ]; then + __docker + __package curl +elif [ ${state} = "absent" ]; then __file /usr/local/bin/docker-compose --state absent -elif [ ${state} != "present" -a ${state} != "absent" ]; then +else echo "Unknown state: $state_should" >&2 exit 1 fi From 0dbe9e14286428437052fa7c9c96ef5335a11b82 Mon Sep 17 00:00:00 2001 From: Dominique Roux Date: Sat, 31 Dec 2016 11:03:28 +0100 Subject: [PATCH 3/5] updated man.rst --- cdist/conf/type/__docker_compose/man.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cdist/conf/type/__docker_compose/man.rst b/cdist/conf/type/__docker_compose/man.rst index d54b3370..38366157 100644 --- a/cdist/conf/type/__docker_compose/man.rst +++ b/cdist/conf/type/__docker_compose/man.rst @@ -9,6 +9,8 @@ cdist-type__docker_compose - install docker-compose DESCRIPTION ----------- Installs docker-compose package. +State 'absent' will not remove docker binary itself +only docker-compose binary will be removed REQUIRED PARAMETERS From 07906451b23abfe4c100d7413d6f362e183cff1d Mon Sep 17 00:00:00 2001 From: Dominique Roux Date: Sat, 31 Dec 2016 11:06:06 +0100 Subject: [PATCH 4/5] updated man.rst --- cdist/conf/type/__docker_compose/man.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__docker_compose/man.rst b/cdist/conf/type/__docker_compose/man.rst index 38366157..7386e737 100644 --- a/cdist/conf/type/__docker_compose/man.rst +++ b/cdist/conf/type/__docker_compose/man.rst @@ -9,7 +9,7 @@ cdist-type__docker_compose - install docker-compose DESCRIPTION ----------- Installs docker-compose package. -State 'absent' will not remove docker binary itself +State 'absent' will not remove docker binary itself, only docker-compose binary will be removed From 4742913244ce33c7910b0b20224dba3439292147 Mon Sep 17 00:00:00 2001 From: Dominique Roux Date: Mon, 2 Jan 2017 11:48:07 +0100 Subject: [PATCH 5/5] fixed type --- cdist/conf/type/__docker_compose/manifest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__docker_compose/manifest b/cdist/conf/type/__docker_compose/manifest index 3ab27c63..559375ef 100644 --- a/cdist/conf/type/__docker_compose/manifest +++ b/cdist/conf/type/__docker_compose/manifest @@ -28,6 +28,6 @@ if [ ${state} = "present" ]; then elif [ ${state} = "absent" ]; then __file /usr/local/bin/docker-compose --state absent else - echo "Unknown state: $state_should" >&2 + echo "Unknown state: ${state}" >&2 exit 1 fi