Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bootstrap-saltstack-formula for docker container states #6

Merged
merged 1 commit into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions bootstrap-saltstack-formula
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ function yes_no_question () {

# Ask a question, defaults to no
function no_yes_question () {
read -r -p "$1 [Y/n] " response
read -r -p "$1 [y/N] " response
response=${response,,}
if [[ "$response" =~ ^(no|n|)$ ]]; then
return 0
else
return 1
else
return 0
fi
}

Expand Down Expand Up @@ -100,6 +100,32 @@ then
eval "git add ."
eval "git commit -am 'Initial commit copied from template'"
eval "cd $exec_dir"

# Remove changelog
echo "Removing Changelog..."
eval "cd $dest_path"
eval "git rm CHANGELOG.rst"
eval "git commit -am 'Remove changelog'"
eval "cd $exec_dir"

if no_yes_question "Is this formula going to run a docker container?"
then
echo "Setting up files for a docker formula..."
eval "cp -r $script_dir/bootstrap/saltstack-formula/docker/* $dest_path/template/"
eval "mv $dest_path/template/pillar.example $dest_path/pillar.example"
fi

shortname=$(echo $dest_path| cut -d'-' -f 1)
if yes_no_question "Would you like to replace 'template' => '$shortname'?"
then
echo "Replacing all instances of 'template' with '$shortname'..."
eval "cd $dest_path"
eval "git mv template $shortname"
eval "git commit -m 'Renaming template directory'"
eval "find . -type f -exec sed -i "s/template/$shortname/g" {} \;"
eval "git commit -am 'Replacing template with $shortname in all files'"
eval "cd $exec_dir"
fi
else
echo "Cancelling..."
fi
7 changes: 7 additions & 0 deletions bootstrap/saltstack-formula/docker/config.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{% from "template/map.jinja" import santa with context %}

template-config:
test.nop
6 changes: 6 additions & 0 deletions bootstrap/saltstack-formula/docker/defaults.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
template:
image: username/template
name: template
branch: latest
7 changes: 7 additions & 0 deletions bootstrap/saltstack-formula/docker/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- template.install
- template.config
- template.service
9 changes: 9 additions & 0 deletions bootstrap/saltstack-formula/docker/install.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{% from "template/map.jinja" import template with context %}

template-image:
dockerng.image_present:
- name: {{ template.image }}:{{ template.branch }}
- force: True
22 changes: 22 additions & 0 deletions bootstrap/saltstack-formula/docker/map.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# vim: ft=jinja

{% import_yaml 'template/defaults.yaml' as default_settings %}

{% set os_family_map = salt['grains.filter_by']({
'Debian': {},
'Suse': {},
'Arch': {},
'RedHat': {},
}
, grain="os_family"
, merge=salt['pillar.get']('template:lookup'))
%}
{% do default_settings.santa.update(os_family_map) %}

{% set template = salt['pillar.get'](
'template',
default=default_settings.template,
merge=True
)
%}
6 changes: 6 additions & 0 deletions bootstrap/saltstack-formula/docker/pillar.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
template:
filename: /path/on/host.ext
directory: /path/on/host
port: 3000
environment:
# key: value
32 changes: 32 additions & 0 deletions bootstrap/saltstack-formula/docker/service.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{% from "template/map.jinja" import template with context %}

include:
- template.install

template-file:
file.touch:
- name: {{ template.filename }}

template-dir:
file.directory:
- name: {{ template.directory }}

template-container:
dockerng.running:
- name: {{ template.name }}
- image: {{ template.image }}:{{ template.branch }}
- binds:
- {{ template.directory }}:/path/on/container:rw
- port_bindings:
- {{ template.port }}:3000
{%- if template.environment %}
- environment:
{%- for env, value in template.environment.items() %}
- {{ env }}: {{ value|yaml_squote }}
{%- endfor %}
{%- endif %}
- require:
- dockerng: template-image