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