blob: 67faf5f956b9ac8538742a11b6a99972c1c4573a [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 Pytloun38c74a32018-01-18 13:03:41 +01005# curl -skL "https://raw.githubusercontent.com/salt-formulas/salt-formulas-cookiecutter/master/salt-formula/kitchen-init.sh" | bash -s --
Petr Michalecd1ff7bd2016-07-14 10:43:13 +02006
Petr Michaleca7af1222016-09-23 09:47:24 +02007# source gist:
8# https://gist.github.com/epcim/b0368794e69e6807635b0c7268e5ceec
Petr Michalecd1ff7bd2016-07-14 10:43:13 +02009
10# CONFIG
Petr Michalec993e3fa2016-07-15 15:56:34 +020011###################################
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020012
Petr Michalec3f949f62016-11-15 23:21:56 +010013export driver=${driver:-docker} # vagrant, dokken, openstack, ...
Petr Michalec993e3fa2016-07-15 15:56:34 +020014export verifier=${verifier:-inspec} # serverspec, pester
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020015
Petr Michaleca347c802016-07-20 21:49:52 +020016export formula=${formula:-$(awk -F: '/^name/{gsub(/[\ \"]/,"");print $2}' metadata.yml)}
Petr Michalec60b1b212016-07-26 07:37:39 +020017export suites=$(ls tests/pillar|xargs -I{} basename {} .sls)
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020018
Filip Pytloun38c74a32018-01-18 13:03:41 +010019export SOURCE_REPO_URI="https://raw.githubusercontent.com/salt-formulas/salt-formulas-cookiecutter/master/salt-formula/%7B%7Bcookiecutter.service_name%7D%7D"
Petr Michalec993e3fa2016-07-15 15:56:34 +020020
Petr Michalec1eac0ef2016-07-26 20:56:55 +020021which envtpl &> /dev/null || {
Petr Michalec3f949f62016-11-15 23:21:56 +010022 echo "ERROR: missing prerequisite, install 'envtpl' first : sudo pip install envtpl"
Petr Michalec1eac0ef2016-07-26 20:56:55 +020023 exit 1
24}
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020025
26# INIT
Petr Michalec993e3fa2016-07-15 15:56:34 +020027###################################
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020028test ! -e .kitchen.yml || {
Filip Pytloun38c74a32018-01-18 13:03:41 +010029 kitchen init -D kitchen-${driver} -P kitchen-salt --no-create-gemfile
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020030 echo .kitchen >> .gitignore
Filip Pytloun38c74a32018-01-18 13:03:41 +010031 echo .bundle >> .gitignore
32 echo .vendor >> .gitignore
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020033 rm -rf test
34 rm -f .kitchen.yml
35 rm -f chefignore
36}
37
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020038
Petr Michalec993e3fa2016-07-15 15:56:34 +020039# CONFIGURE & SCAFFOLD TEST DIR
40###################################
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020041test -d tests/integration || {
Petr Michalec3f949f62016-11-15 23:21:56 +010042 mkdir -p tests/integration
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020043}
Filip Pytloun38c74a32018-01-18 13:03:41 +010044# Generate suites:
Petr Michalec3f949f62016-11-15 23:21:56 +010045# for suite in $(echo $suites|xargs); do
46# mkdir -p tests/integration/$suite/$verifier
47# touch tests/integration/$suite/$verifier/default_spec.rb
48# done
49# mkdir -p tests/integration/helpers/$verifier/
50# touch tests/integration/helpers/$verifier/spec_helper.rb
51#}
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020052
53
54# .KITCHEN.YML
Petr Michalec993e3fa2016-07-15 15:56:34 +020055###################################
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020056
Petr Michalec993e3fa2016-07-15 15:56:34 +020057test -e .kitchen.yml || \
Petr Michalec3f949f62016-11-15 23:21:56 +010058 envtpl < <(curl -skL "${SOURCE_REPO_URI}/.kitchen.${driver}.yml" -- | sed 's/cookiecutter\.kitchen_//g' ) > .kitchen.yml
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020059
Petr Michalec221b2322016-07-26 07:33:42 +020060[[ "$driver" != "docker" ]] && {
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020061 test -e .kitchen.docker.yml || \
Petr Michalec3f949f62016-11-15 23:21:56 +010062 envtpl < <(curl -skL "${SOURCE_REPO_URI}/.kitchen.docker.yml" -- | sed 's/cookiecutter\.kitchen_//g') > .kitchen.docker.yml
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020063}
64
Petr Michalec3f949f62016-11-15 23:21:56 +010065[[ "$driver" != "vagrant" ]] && {
66 test -e .kitchen.vagrant.yml || \
67 envtpl < <(curl -skL "${SOURCE_REPO_URI}/.kitchen.vagrant.yml" -- | sed 's/cookiecutter\.kitchen_//g') > .kitchen.vagrant.yml
68}
69
70[[ "$driver" != "openstack" ]] && {
71 test -e .kitchen.openstack.yml || \
72 envtpl < <(curl -skL "${SOURCE_REPO_URI}/.kitchen.openstack.yml" -- | sed 's/cookiecutter\.kitchen_//g') > .kitchen.openstack.yml
73}
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020074
Filip Pytloun38c74a32018-01-18 13:03:41 +010075# .TRAVIS.YML
Petr Michalec993e3fa2016-07-15 15:56:34 +020076###################################
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020077
Filip Pytloun38c74a32018-01-18 13:03:41 +010078test -e .travis.yml || \
79 curl -skL "${SOURCE_REPO_URI}/.travis.yml" -o .travis.yml
Petr Michalec993e3fa2016-07-15 15:56:34 +020080
81
Filip Pytloun38c74a32018-01-18 13:03:41 +010082# ADD CHANGES
83#############
Petr Michalec993e3fa2016-07-15 15:56:34 +020084
Filip Pytloun38c74a32018-01-18 13:03:41 +010085echo "**************************************"
86echo "To update to latest test scripts, run:"
87echo "SOURCE_REPO_URI=${SOURCE_REPO_URI}"
88echo 'curl -skL "${SOURCE_REPO_URI}/Makefile" -o Makefile'
89echo 'curl -skL "${SOURCE_REPO_URI}/tests/run_tests.sh" -o tests/run_tests.sh'
Petr Michalec993e3fa2016-07-15 15:56:34 +020090
91git add \
92 .gitignore \
Filip Pytloun38c74a32018-01-18 13:03:41 +010093 .kitchen.yml \
94 .travis.yml
Petr Michalec993e3fa2016-07-15 15:56:34 +020095
Petr Michalec36842122016-11-15 23:59:42 +010096git status