forked from ungleich-public/cdist
		
	Merge pull request #657 from devinsolutions/docker-config
Add new type __docker_config
This commit is contained in:
		
				commit
				
					
						6722f56df1
					
				
			
		
					 7 changed files with 173 additions and 0 deletions
				
			
		
							
								
								
									
										21
									
								
								cdist/conf/type/__docker_config/explorer/config-data
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								cdist/conf/type/__docker_config/explorer/config-data
									
										
									
									
									
										Normal 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
 | 
				
			||||||
							
								
								
									
										25
									
								
								cdist/conf/type/__docker_config/explorer/config-exists
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										25
									
								
								cdist/conf/type/__docker_config/explorer/config-exists
									
										
									
									
									
										Executable 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
 | 
				
			||||||
							
								
								
									
										69
									
								
								cdist/conf/type/__docker_config/gencode-remote
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										69
									
								
								cdist/conf/type/__docker_config/gencode-remote
									
										
									
									
									
										Executable 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
 | 
				
			||||||
							
								
								
									
										55
									
								
								cdist/conf/type/__docker_config/man.rst
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								cdist/conf/type/__docker_config/man.rst
									
										
									
									
									
										Normal 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.
 | 
				
			||||||
							
								
								
									
										0
									
								
								cdist/conf/type/__docker_config/parameter/default/source
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								cdist/conf/type/__docker_config/parameter/default/source
									
										
									
									
									
										Normal file
									
								
							
							
								
								
									
										1
									
								
								cdist/conf/type/__docker_config/parameter/default/state
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								cdist/conf/type/__docker_config/parameter/default/state
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					present
 | 
				
			||||||
							
								
								
									
										2
									
								
								cdist/conf/type/__docker_config/parameter/optional
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								cdist/conf/type/__docker_config/parameter/optional
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,2 @@
 | 
				
			||||||
 | 
					source
 | 
				
			||||||
 | 
					state
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue