blob: b85124c02aaf120464bafb03f0b499377ce5bcc9 [file] [log] [blame]
Michael Kutýf0c0aa72015-11-19 21:51:21 +01001cookiecutter-salt-formula
2=========================
Ales Komarek7792c702015-10-19 20:41:02 +02003
Filip Pytloun38c74a32018-01-18 13:03:41 +01004A cookiecutter template for Salt Formula.
Ales Komarek7792c702015-10-19 20:41:02 +02005
Filip Pytloun38c74a32018-01-18 13:03:41 +01006Installation
Michael Kutýf0c0aa72015-11-19 21:51:21 +01007============
Ales Komarek7792c702015-10-19 20:41:02 +02008
Michael Kutýf0c0aa72015-11-19 21:51:21 +01009.. code-block:: bash
Ales Komarek7792c702015-10-19 20:41:02 +020010
Petr Michalec84d25042016-11-15 23:42:12 +010011 pip install cookiecutter
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020012
Filip Pytloun38c74a32018-01-18 13:03:41 +010013 cd cookiecutter
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020014
Filip Pytloun38c74a32018-01-18 13:03:41 +010015 cookiecutter salt-formula
16
Oleksandr Shyshko50756c32019-02-07 10:41:12 +020017Procedure of Data model and Schemas validation.
18===============================
19
20run_tests.sh script is able to validate data model by schemas and test pillars.
21It supports versioned and unversioned schemas and pillars. Schemas and pillars must contains yaml format.
22
23Unversioned items must be avaible in:
24
25.. code-block:: text
26
27 {FORMULA_NAME}/{FORMULA_NAME}/schemas/
28 {FORMULA_NAME}/tests/pillar/
29
30Versioned items must be avaible in:
31
32.. code-block:: text
33
34 {FORMULA_NAME}/{FORMULA_NAME}/schemas/{version}/
35 {FORMULA_NAME}/tests/pillar/{version}/
36
37You can run run_tests.sh by following command:
38
39.. code-block:: shell
40
41 # cd <formula repository>
42 ./tests/run_tests.sh
43
44You can run run_tests.sh which inlude schema validation if schemas present by following command:
45
46.. code-block:: shell
47
48 # cd <formula repository>
49 ./tests/run_tests.sh model-validate
50
51Example schemas:
52
53.. code-block:: yaml
54
55 %YAML 1.1
56 ---
57 "$schema": "http://json-schema.org/draft-06/schema#"
58 title: {{cookiecutter.service_name}} daemon role
59 description: |
60 {{cookiecutter.service_name|capitalize}} daemon, server role
61 type: object
62 additionalProperties: false
63
64 required:
65 - enabled
66
67 properties:
68 enabled:
69 description: |
70 Enables {{cookiecutter.service_name}} daemon service
71 type: boolean
72
73Example pillar:
74
75.. code-block:: yaml
76 {{cookiecutter.service_name}}:
77 {{cookiecutter.role_name}}:
78 enabled: true
79
80You can read more about it here:
81 http://json-schema.org/implementations.html
82 http://github.com/Julian/jsonschema
Filip Pytloun38c74a32018-01-18 13:03:41 +010083
84Init Test Kitchen configuration
85===============================
86
87Follow the `salt formula testing <https://salt-formulas.readthedocs.io/en/latest/develop/testing-formulas.html>`_ guidelines and
88automated CI in the main `documentation <https://salt-formulas.readthedocs.io/en/latest/develop/testing.html>`_.
89
90To generate ``.kitchen.yml`` for new or existing project:
91
92- install `envtpl`, renders jinja2 templates with shell environment variables
93- install required gems, it depends on drivers configured to be used (docker by default)
94
95.. code-block:: shell
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020096
97 pip install envtpl
Filip Pytloun38c74a32018-01-18 13:03:41 +010098 gem install kitchen-docker kitchen-salt [kitchen-openstack kitchen-vagrant kitchen-inspec busser-serverspec]
Petr Michalecd1ff7bd2016-07-14 10:43:13 +020099
Filip Pytloun38c74a32018-01-18 13:03:41 +0100100Once you create your `tests/pillar` structure (required if you want to auto-populate kitchen yaml with test suites)
Petr Michalecd1ff7bd2016-07-14 10:43:13 +0200101
Filip Pytloun38c74a32018-01-18 13:03:41 +0100102.. code-block:: shell
Petr Michalecd1ff7bd2016-07-14 10:43:13 +0200103
Filip Pytloun38c74a32018-01-18 13:03:41 +0100104 # cd <formula repository>
105 ../kitchen-init.sh
106
107Instantly, to add kitchen configuration into existing repository:
108
109.. code-block:: shell
110
111 # cd <formula repository>
Filip Pytloun80ff5b02018-01-18 13:28:43 +0100112 curl -skL "https://raw.githubusercontent.com/salt-formulas/cookiecutter-salt-formula/master/kitchen-init.sh" | bash -s --
Filip Pytloun38c74a32018-01-18 13:03:41 +0100113
Petr Ruzicka8ebb5c72018-01-19 13:32:43 +0100114
115Docker way
116===============================
117
118.. code-block:: bash
119
Petr Ruzicka9d1d97c2018-01-30 16:07:07 +0100120 MY_NEW_SALT_FORMULA_DIR="watchdog"
Petr Ruzicka8ebb5c72018-01-19 13:32:43 +0100121 mkdir $MY_NEW_SALT_FORMULA_DIR
122 git clone https://github.com/salt-formulas/cookiecutter-salt-formula.git
123 docker run --rm -it -u $(id -u):$(id -g) --env HOME=/$MY_NEW_SALT_FORMULA_DIR -v $PWD/$MY_NEW_SALT_FORMULA_DIR:/$MY_NEW_SALT_FORMULA_DIR -v $PWD/cookiecutter-salt-formula:/cookiecutter-salt-formula:ro cookiecutter/cookiecutter /cookiecutter-salt-formula --output-dir /$MY_NEW_SALT_FORMULA_DIR
Petr Ruzicka9d1d97c2018-01-30 16:07:07 +0100124 service_name [some_service]: watchdog
125 role_name [server]:
126 initial_version [2018.1]:
127 copyright_year [2018]:
128 copyright_holder [Your Name et al.]: Mirantis, Inc.
129 author_name [John Doe]: Petr Ruzicka
130 author_contact [jdoe@domain.com]: pruzicka@mirantis.com
131 homepage [https://github.com/salt-formulas]:
132 debian_version [xenial]:
133 kitchen_driver [docker]:
134 kitchen_verifier [inspec]:
135 kitchen_formula [watchdog]:
136 kitchen_suites []: server