Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Petr Michalec | 993e3fa | 2016-07-15 15:56:34 +0200 | [diff] [blame] | 3 | # Script to add Kitchen configuration to existing formulas. |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 4 | # usage: |
Filip Pytloun | 38c74a3 | 2018-01-18 13:03:41 +0100 | [diff] [blame^] | 5 | # curl -skL "https://raw.githubusercontent.com/salt-formulas/salt-formulas-cookiecutter/master/salt-formula/kitchen-init.sh" | bash -s -- |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 6 | |
Petr Michalec | a7af122 | 2016-09-23 09:47:24 +0200 | [diff] [blame] | 7 | # source gist: |
| 8 | # https://gist.github.com/epcim/b0368794e69e6807635b0c7268e5ceec |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 9 | |
| 10 | # CONFIG |
Petr Michalec | 993e3fa | 2016-07-15 15:56:34 +0200 | [diff] [blame] | 11 | ################################### |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 12 | |
Petr Michalec | 3f949f6 | 2016-11-15 23:21:56 +0100 | [diff] [blame] | 13 | export driver=${driver:-docker} # vagrant, dokken, openstack, ... |
Petr Michalec | 993e3fa | 2016-07-15 15:56:34 +0200 | [diff] [blame] | 14 | export verifier=${verifier:-inspec} # serverspec, pester |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 15 | |
Petr Michalec | a347c80 | 2016-07-20 21:49:52 +0200 | [diff] [blame] | 16 | export formula=${formula:-$(awk -F: '/^name/{gsub(/[\ \"]/,"");print $2}' metadata.yml)} |
Petr Michalec | 60b1b21 | 2016-07-26 07:37:39 +0200 | [diff] [blame] | 17 | export suites=$(ls tests/pillar|xargs -I{} basename {} .sls) |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 18 | |
Filip Pytloun | 38c74a3 | 2018-01-18 13:03:41 +0100 | [diff] [blame^] | 19 | export SOURCE_REPO_URI="https://raw.githubusercontent.com/salt-formulas/salt-formulas-cookiecutter/master/salt-formula/%7B%7Bcookiecutter.service_name%7D%7D" |
Petr Michalec | 993e3fa | 2016-07-15 15:56:34 +0200 | [diff] [blame] | 20 | |
Petr Michalec | 1eac0ef | 2016-07-26 20:56:55 +0200 | [diff] [blame] | 21 | which envtpl &> /dev/null || { |
Petr Michalec | 3f949f6 | 2016-11-15 23:21:56 +0100 | [diff] [blame] | 22 | echo "ERROR: missing prerequisite, install 'envtpl' first : sudo pip install envtpl" |
Petr Michalec | 1eac0ef | 2016-07-26 20:56:55 +0200 | [diff] [blame] | 23 | exit 1 |
| 24 | } |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 25 | |
| 26 | # INIT |
Petr Michalec | 993e3fa | 2016-07-15 15:56:34 +0200 | [diff] [blame] | 27 | ################################### |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 28 | test ! -e .kitchen.yml || { |
Filip Pytloun | 38c74a3 | 2018-01-18 13:03:41 +0100 | [diff] [blame^] | 29 | kitchen init -D kitchen-${driver} -P kitchen-salt --no-create-gemfile |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 30 | echo .kitchen >> .gitignore |
Filip Pytloun | 38c74a3 | 2018-01-18 13:03:41 +0100 | [diff] [blame^] | 31 | echo .bundle >> .gitignore |
| 32 | echo .vendor >> .gitignore |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 33 | rm -rf test |
| 34 | rm -f .kitchen.yml |
| 35 | rm -f chefignore |
| 36 | } |
| 37 | |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 38 | |
Petr Michalec | 993e3fa | 2016-07-15 15:56:34 +0200 | [diff] [blame] | 39 | # CONFIGURE & SCAFFOLD TEST DIR |
| 40 | ################################### |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 41 | test -d tests/integration || { |
Petr Michalec | 3f949f6 | 2016-11-15 23:21:56 +0100 | [diff] [blame] | 42 | mkdir -p tests/integration |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 43 | } |
Filip Pytloun | 38c74a3 | 2018-01-18 13:03:41 +0100 | [diff] [blame^] | 44 | # Generate suites: |
Petr Michalec | 3f949f6 | 2016-11-15 23:21:56 +0100 | [diff] [blame] | 45 | # 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 Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 52 | |
| 53 | |
| 54 | # .KITCHEN.YML |
Petr Michalec | 993e3fa | 2016-07-15 15:56:34 +0200 | [diff] [blame] | 55 | ################################### |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 56 | |
Petr Michalec | 993e3fa | 2016-07-15 15:56:34 +0200 | [diff] [blame] | 57 | test -e .kitchen.yml || \ |
Petr Michalec | 3f949f6 | 2016-11-15 23:21:56 +0100 | [diff] [blame] | 58 | envtpl < <(curl -skL "${SOURCE_REPO_URI}/.kitchen.${driver}.yml" -- | sed 's/cookiecutter\.kitchen_//g' ) > .kitchen.yml |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 59 | |
Petr Michalec | 221b232 | 2016-07-26 07:33:42 +0200 | [diff] [blame] | 60 | [[ "$driver" != "docker" ]] && { |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 61 | test -e .kitchen.docker.yml || \ |
Petr Michalec | 3f949f6 | 2016-11-15 23:21:56 +0100 | [diff] [blame] | 62 | envtpl < <(curl -skL "${SOURCE_REPO_URI}/.kitchen.docker.yml" -- | sed 's/cookiecutter\.kitchen_//g') > .kitchen.docker.yml |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 63 | } |
| 64 | |
Petr Michalec | 3f949f6 | 2016-11-15 23:21:56 +0100 | [diff] [blame] | 65 | [[ "$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 Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 74 | |
Filip Pytloun | 38c74a3 | 2018-01-18 13:03:41 +0100 | [diff] [blame^] | 75 | # .TRAVIS.YML |
Petr Michalec | 993e3fa | 2016-07-15 15:56:34 +0200 | [diff] [blame] | 76 | ################################### |
Petr Michalec | d1ff7bd | 2016-07-14 10:43:13 +0200 | [diff] [blame] | 77 | |
Filip Pytloun | 38c74a3 | 2018-01-18 13:03:41 +0100 | [diff] [blame^] | 78 | test -e .travis.yml || \ |
| 79 | curl -skL "${SOURCE_REPO_URI}/.travis.yml" -o .travis.yml |
Petr Michalec | 993e3fa | 2016-07-15 15:56:34 +0200 | [diff] [blame] | 80 | |
| 81 | |
Filip Pytloun | 38c74a3 | 2018-01-18 13:03:41 +0100 | [diff] [blame^] | 82 | # ADD CHANGES |
| 83 | ############# |
Petr Michalec | 993e3fa | 2016-07-15 15:56:34 +0200 | [diff] [blame] | 84 | |
Filip Pytloun | 38c74a3 | 2018-01-18 13:03:41 +0100 | [diff] [blame^] | 85 | echo "**************************************" |
| 86 | echo "To update to latest test scripts, run:" |
| 87 | echo "SOURCE_REPO_URI=${SOURCE_REPO_URI}" |
| 88 | echo 'curl -skL "${SOURCE_REPO_URI}/Makefile" -o Makefile' |
| 89 | echo 'curl -skL "${SOURCE_REPO_URI}/tests/run_tests.sh" -o tests/run_tests.sh' |
Petr Michalec | 993e3fa | 2016-07-15 15:56:34 +0200 | [diff] [blame] | 90 | |
| 91 | git add \ |
| 92 | .gitignore \ |
Filip Pytloun | 38c74a3 | 2018-01-18 13:03:41 +0100 | [diff] [blame^] | 93 | .kitchen.yml \ |
| 94 | .travis.yml |
Petr Michalec | 993e3fa | 2016-07-15 15:56:34 +0200 | [diff] [blame] | 95 | |
Petr Michalec | 3684212 | 2016-11-15 23:59:42 +0100 | [diff] [blame] | 96 | git status |