Add new type __docker_config

This commit is contained in:
lubo 2018-04-30 12:50:09 +02:00
parent 3869940fc8
commit 4f61f6be9c
7 changed files with 173 additions and 0 deletions

View file

@ -0,0 +1,21 @@
#!/bin/sh -e
#
# 2018 Ľubomír Kučera <lubomir.kucera.jr at gmail.com>
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
docker config inspect "${__object_id:?}" | jq -r '.[0].Spec.Data' | base64 -d

View file

@ -0,0 +1,25 @@
#!/bin/sh -e
#
# 2018 Ľubomír Kučera <lubomir.kucera.jr at gmail.com>
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
if docker config ls | grep -q " ${__object_id:?} "; then
echo yes
else
echo no
fi

View file

@ -0,0 +1,69 @@
#!/bin/sh -e
#
# 2018 Ľubomír Kučera <lubomir.kucera.jr at gmail.com>
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
config="${__object_id:?}"
config_exists=$(cat "${__object:?}/explorer/config-exists")
state=$(cat "${__object:?}/parameter/state")
case "${state}" in
absent)
if [ "${config_exists}" != "yes" ]; then
exit 0
fi
echo "docker config rm \"${config}\""
;;
present)
source=$(cat "${__object}/parameter/source")
if [ -z "${source}" ]; then
exit 0
fi
if [ "${source}" = "-" ]; then
source="${__object}/stdin"
fi
if [ "${config_exists}" = "yes" ]; then
if cmp -s "${source}" "${__object}/explorer/config-data"; then
exit 0
else
echo "docker config rm \"${config}\""
fi
fi
cat <<-EOF
source_file="\$(mktemp cdist.XXXXXXXXXX)"
base64 -d > "\${source_file}" << eof
$(base64 "${source}")
eof
docker config create "${config}" "\${source_file}"
rm "\${source_file}"
EOF
;;
*)
echo "Unsupported state: ${state}" >&2
exit 1
;;
esac

View file

@ -0,0 +1,55 @@
cdist-type__docker_config(7)
============================
NAME
----
cdist-type__docker_config - Manage Docker configs
DESCRIPTION
-----------
This type manages Docker configs.
OPTIONAL PARAMETERS
-------------------
source
Path to the source file. If it is '-' (dash), read standard input.
state
'present' or 'absent', defaults to 'present' where:
present
if the config does not exist, it is created
absent
the config is removed
CAVEATS
-------
Since Docker configs cannot be updated once created, this type tries removing
and recreating the config if it changes. If the config is used by a service at
the time of removing, then this type will fail.
EXAMPLES
--------
.. code-block:: sh
# Creates "foo" config from "bar" source file
__docker_config foo --source bar
AUTHORS
-------
Ľubomír Kučera <lubomir.kucera.jr at gmail.com>
COPYING
-------
Copyright \(C) 2018 Ľubomír Kučera. You can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1,2 @@
source
state