blob: 2d66184c500a30cb8e39124a74ac0d823347dfdf [file] [log] [blame]
Petr Michalecd1ff7bd2016-07-14 10:43:13 +02001#!/bin/bash
2
Petr Michalec993e3fa2016-07-15 15:56:34 +02003# Script to add Kitchen configuration to existing formulas.
Petr Michalecd1ff7bd2016-07-14 10:43:13 +02004# usage:
Filip Pytloun80ff5b02018-01-18 13:28:43 +01005# curl -skL
6# "https://raw.githubusercontent.com/salt-formulas/cookiecutter-salt-formula/master/kitchen-init.sh" | bash -s --
Petr Michalecd1ff7bd2016-07-14 10:43:13 +02007
Petr Michaleca7af1222016-09-23 09:47:24 +02008# source gist:
9# https://gist.github.com/epcim/b0368794e69e6807635b0c7268e5ceec
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020010
11# CONFIG
Petr Michalec993e3fa2016-07-15 15:56:34 +020012###################################
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020013
Petr Michalec3f949f62016-11-15 23:21:56 +010014export driver=${driver:-docker} # vagrant, dokken, openstack, ...
Petr Michalec993e3fa2016-07-15 15:56:34 +020015export verifier=${verifier:-inspec} # serverspec, pester
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020016
Petr Michaleca347c802016-07-20 21:49:52 +020017export formula=${formula:-$(awk -F: '/^name/{gsub(/[\ \"]/,"");print $2}' metadata.yml)}
Petr Michalec60b1b212016-07-26 07:37:39 +020018export suites=$(ls tests/pillar|xargs -I{} basename {} .sls)
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020019
Filip Pytloun80ff5b02018-01-18 13:28:43 +010020export SOURCE_REPO_URI="https://raw.githubusercontent.com/salt-formulas/cookiecutter-salt-formula/master/%7B%7Bcookiecutter.service_name%7D%7D"
Petr Michalec993e3fa2016-07-15 15:56:34 +020021
Petr Michalec1eac0ef2016-07-26 20:56:55 +020022which envtpl &> /dev/null || {
Petr Michalec3f949f62016-11-15 23:21:56 +010023 echo "ERROR: missing prerequisite, install 'envtpl' first : sudo pip install envtpl"
Petr Michalec1eac0ef2016-07-26 20:56:55 +020024 exit 1
25}
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020026
27# INIT
Petr Michalec993e3fa2016-07-15 15:56:34 +020028###################################
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020029test ! -e .kitchen.yml || {
Filip Pytloun38c74a32018-01-18 13:03:41 +010030 kitchen init -D kitchen-${driver} -P kitchen-salt --no-create-gemfile
Petr Michaleca1f23292018-02-06 11:59:59 +010031 grep '.kitchen' .gitignore || echo .kitchen >> .gitignore
32 grep '.bundle' .gitignore || echo .bundle >> .gitignore
33 grep '.vendor' .gitignore || echo .vendor >> .gitignore
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020034 rm -rf test
35 rm -f .kitchen.yml
36 rm -f chefignore
37}
38
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020039
Petr Michalec993e3fa2016-07-15 15:56:34 +020040# CONFIGURE & SCAFFOLD TEST DIR
41###################################
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020042test -d tests/integration || {
Petr Michalec3f949f62016-11-15 23:21:56 +010043 mkdir -p tests/integration
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020044}
Filip Pytloun38c74a32018-01-18 13:03:41 +010045# Generate suites:
Petr Michalec3f949f62016-11-15 23:21:56 +010046# for suite in $(echo $suites|xargs); do
47# mkdir -p tests/integration/$suite/$verifier
48# touch tests/integration/$suite/$verifier/default_spec.rb
49# done
50# mkdir -p tests/integration/helpers/$verifier/
51# touch tests/integration/helpers/$verifier/spec_helper.rb
52#}
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020053
54
55# .KITCHEN.YML
Petr Michalec993e3fa2016-07-15 15:56:34 +020056###################################
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020057
Petr Michalec993e3fa2016-07-15 15:56:34 +020058test -e .kitchen.yml || \
Petr Michalec3f949f62016-11-15 23:21:56 +010059 envtpl < <(curl -skL "${SOURCE_REPO_URI}/.kitchen.${driver}.yml" -- | sed 's/cookiecutter\.kitchen_//g' ) > .kitchen.yml
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020060
Petr Michalec221b2322016-07-26 07:33:42 +020061[[ "$driver" != "docker" ]] && {
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020062 test -e .kitchen.docker.yml || \
Petr Michalec3f949f62016-11-15 23:21:56 +010063 envtpl < <(curl -skL "${SOURCE_REPO_URI}/.kitchen.docker.yml" -- | sed 's/cookiecutter\.kitchen_//g') > .kitchen.docker.yml
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020064}
65
Petr Michalec3f949f62016-11-15 23:21:56 +010066[[ "$driver" != "vagrant" ]] && {
67 test -e .kitchen.vagrant.yml || \
68 envtpl < <(curl -skL "${SOURCE_REPO_URI}/.kitchen.vagrant.yml" -- | sed 's/cookiecutter\.kitchen_//g') > .kitchen.vagrant.yml
69}
70
71[[ "$driver" != "openstack" ]] && {
72 test -e .kitchen.openstack.yml || \
73 envtpl < <(curl -skL "${SOURCE_REPO_URI}/.kitchen.openstack.yml" -- | sed 's/cookiecutter\.kitchen_//g') > .kitchen.openstack.yml
74}
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020075
Martin Polreicha294af02018-11-12 16:22:27 +010076# # .TRAVIS.YML
77# ###################################
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020078
Martin Polreicha294af02018-11-12 16:22:27 +010079# test -e .travis.yml || \
80# curl -skL "${SOURCE_REPO_URI}/.travis.yml" -o .travis.yml
Petr Michalec993e3fa2016-07-15 15:56:34 +020081
Petr Michaleca1f23292018-02-06 11:59:59 +010082# OTHER metadata if formula was not generated by up-to-date cookiecutter-salt-formula
83#####################################################################################
84
85test -e tests/pillar || \
86 mkdir -p tests/pillar
87
88test -e metadata.yml || \
89 curl -skL "${SOURCE_REPO_URI}/metadata.yml" -o metadata.yml
90
91# Always update to letests
92curl -skL "${SOURCE_REPO_URI}/Makefile" -o Makefile
93curl -skL "${SOURCE_REPO_URI}/tests/run_tests.sh" -o tests/run_tests.sh && chmod u+x tests/run_tests.sh
Petr Michalec993e3fa2016-07-15 15:56:34 +020094
Filip Pytloun38c74a32018-01-18 13:03:41 +010095# ADD CHANGES
96#############
Petr Michalec993e3fa2016-07-15 15:56:34 +020097
Petr Michalec993e3fa2016-07-15 15:56:34 +020098git add \
99 .gitignore \
Martin Polreicha294af02018-11-12 16:22:27 +0100100 .kitchen.yml
101 # .travis.yml
Petr Michalec993e3fa2016-07-15 15:56:34 +0200102
Petr Michalec36842122016-11-15 23:59:42 +0100103git status