Add new type __docker_stack
This commit is contained in:
		
					parent
					
						
							
								e4f263ecb7
							
						
					
				
			
			
				commit
				
					
						7184228536
					
				
			
		
					 6 changed files with 145 additions and 0 deletions
				
			
		
							
								
								
									
										25
									
								
								cdist/conf/type/__docker_stack/explorer/stack-exists
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										25
									
								
								cdist/conf/type/__docker_stack/explorer/stack-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 stack ls | grep -q "^${__object_id:?} "; then
 | 
			
		||||
	echo 1
 | 
			
		||||
else
 | 
			
		||||
	echo 0
 | 
			
		||||
fi
 | 
			
		||||
							
								
								
									
										63
									
								
								cdist/conf/type/__docker_stack/gencode-remote
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										63
									
								
								cdist/conf/type/__docker_stack/gencode-remote
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,63 @@
 | 
			
		|||
#!/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/>.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
stack="${__object_id:?}"
 | 
			
		||||
state=$(cat "${__object:?}/parameter/state")
 | 
			
		||||
 | 
			
		||||
case "${state}" in
 | 
			
		||||
	absent)
 | 
			
		||||
		stack_exists=$(cat "${__object:?}/explorer/stack-exists")
 | 
			
		||||
 | 
			
		||||
		if [ "${stack_exists}" -ne 1 ]; then
 | 
			
		||||
			exit 0
 | 
			
		||||
		fi
 | 
			
		||||
 | 
			
		||||
		echo "docker stack rm ${stack}"
 | 
			
		||||
	;;
 | 
			
		||||
	present)
 | 
			
		||||
		compose_file=$(cat "${__object}/parameter/compose-file")
 | 
			
		||||
 | 
			
		||||
		if [ -z "${compose_file}" ]; then
 | 
			
		||||
			exit 0
 | 
			
		||||
		fi
 | 
			
		||||
 | 
			
		||||
		if [ "${compose_file}" = "-" ]; then
 | 
			
		||||
			compose_file="${__object}/stdin"
 | 
			
		||||
		fi
 | 
			
		||||
 | 
			
		||||
		cat <<-EOF
 | 
			
		||||
		compose_file="\$(mktemp cdist.XXXXXXXXXX)"
 | 
			
		||||
 | 
			
		||||
		base64 -d > "\${compose_file}" << eof
 | 
			
		||||
		$(base64 "${compose_file}")
 | 
			
		||||
		eof
 | 
			
		||||
 | 
			
		||||
		docker stack deploy --compose-file "\${compose_file}" \
 | 
			
		||||
			--prune ${stack}
 | 
			
		||||
 | 
			
		||||
		rm "\${compose_file}"
 | 
			
		||||
		EOF
 | 
			
		||||
	;;
 | 
			
		||||
	*)
 | 
			
		||||
		echo "Unsupported state: ${state}" >&2
 | 
			
		||||
 | 
			
		||||
		exit 1
 | 
			
		||||
	;;
 | 
			
		||||
esac
 | 
			
		||||
							
								
								
									
										54
									
								
								cdist/conf/type/__docker_stack/man.rst
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								cdist/conf/type/__docker_stack/man.rst
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,54 @@
 | 
			
		|||
cdist-type__docker_stack(7)
 | 
			
		||||
===========================
 | 
			
		||||
 | 
			
		||||
NAME
 | 
			
		||||
----
 | 
			
		||||
 | 
			
		||||
cdist-type__docker_stack - Manage Docker stacks
 | 
			
		||||
 | 
			
		||||
DESCRIPTION
 | 
			
		||||
-----------
 | 
			
		||||
 | 
			
		||||
This type manages service stacks.
 | 
			
		||||
 | 
			
		||||
.. note::
 | 
			
		||||
    Since there is no easy way to tell whether a stack needs to be updated,
 | 
			
		||||
    `docker stack deploy` is being run every time this type is invoked.
 | 
			
		||||
    However, it does not mean this type is not idempotent. If Docker does not
 | 
			
		||||
    detect changes, the existing stack will not be updated.
 | 
			
		||||
 | 
			
		||||
OPTIONAL PARAMETERS
 | 
			
		||||
-------------------
 | 
			
		||||
 | 
			
		||||
compose-file
 | 
			
		||||
    Path to the compose file. If it is '-' (dash), read standard input.
 | 
			
		||||
 | 
			
		||||
state
 | 
			
		||||
    'present' or 'absent', defaults to 'present' where:
 | 
			
		||||
 | 
			
		||||
    present
 | 
			
		||||
        the stack is deployed
 | 
			
		||||
    absent
 | 
			
		||||
        the stack is removed
 | 
			
		||||
 | 
			
		||||
EXAMPLES
 | 
			
		||||
--------
 | 
			
		||||
 | 
			
		||||
.. code-block:: sh
 | 
			
		||||
 | 
			
		||||
    # Deploys 'foo' stack defined in 'docker-compose.yml' compose file
 | 
			
		||||
    __docker_stack foo --compose-file docker-compose.yml
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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.
 | 
			
		||||
							
								
								
									
										1
									
								
								cdist/conf/type/__docker_stack/parameter/default/state
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								cdist/conf/type/__docker_stack/parameter/default/state
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
present
 | 
			
		||||
							
								
								
									
										2
									
								
								cdist/conf/type/__docker_stack/parameter/optional
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								cdist/conf/type/__docker_stack/parameter/optional
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
compose-file
 | 
			
		||||
state
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue