Skip to content

Commit 60bdaca

Browse files
authored
Merge pull request #64 from myii/chore/standardise-structure
feat: enable Vagrant-based testing using GitHub Actions for FreeBSD, OpenBSD & Windows
2 parents b511c40 + 05c942e commit 60bdaca

File tree

15 files changed

+387
-9
lines changed

15 files changed

+387
-9
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
name: 'Kitchen Vagrant (FreeBSD, OpenBSD & Windows)'
5+
'on': ['push', 'pull_request']
6+
7+
env:
8+
KITCHEN_LOCAL_YAML: 'kitchen.vagrant.yml'
9+
10+
jobs:
11+
test:
12+
runs-on: 'macos-10.15'
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
instance:
17+
- default-freebsd-130-master-py3
18+
# - archive-freebsd-130-master-py3
19+
# - source-freebsd-130-master-py3
20+
# - repo-freebsd-130-master-py3
21+
- default-freebsd-123-master-py3
22+
# - archive-freebsd-123-master-py3
23+
# - source-freebsd-123-master-py3
24+
# - repo-freebsd-123-master-py3
25+
# - default-freebsd-130-3004-0-py3
26+
# - default-freebsd-123-3004-0-py3
27+
- default-openbsd-70-3003-3-py3
28+
# - archive-openbsd-70-3003-3-py3
29+
- default-openbsd-69-3002-6-py3
30+
# - archive-openbsd-69-3002-6-py3
31+
- default-windows-10-latest-py3
32+
# - archive-windows-10-latest-py3
33+
- default-windows-81-latest-py3
34+
# - archive-windows-81-latest-py3
35+
steps:
36+
- name: 'Check out code'
37+
uses: 'actions/checkout@v2'
38+
- name: 'Set up Bundler cache'
39+
uses: 'actions/cache@v1'
40+
with:
41+
path: 'vendor/bundle'
42+
key: "${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}"
43+
restore-keys: "${{ runner.os }}-gems-"
44+
- name: 'Run Bundler'
45+
run: |
46+
ruby --version
47+
bundle config path vendor/bundle
48+
bundle install --jobs 4 --retry 3
49+
- name: 'Run Test Kitchen'
50+
run: 'bundle exec kitchen verify ${{ matrix.instance }}'
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
name: 'Kitchen (Windows)'
5+
'on': ['push', 'pull_request']
6+
7+
env:
8+
machine_user: kitchen
9+
machine_pass: Pass@word1
10+
machine_port: 5985
11+
KITCHEN_LOCAL_YAML: 'kitchen.windows.yml'
12+
13+
jobs:
14+
test-2022:
15+
runs-on: 'windows-2022'
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
instance:
20+
- default-windows-2022-latest-py3
21+
# - archive-windows-2022-latest-py3
22+
steps:
23+
- name: 'Check out code'
24+
uses: 'actions/checkout@v2'
25+
- name: 'Install Chef'
26+
uses: 'actionshub/[email protected]'
27+
with:
28+
project: 'chef'
29+
version: '16.10.8'
30+
- name: 'Add Chef bindir to PATH'
31+
uses: 'myci-actions/export-env-var-powershell@1'
32+
with:
33+
name: 'PATH'
34+
value: "C:\\opscode\\chef\\bin;\
35+
C:\\opscode\\chef\\embedded\\bin;$env:PATH"
36+
- name: 'Set up Bundler cache'
37+
uses: 'actions/cache@v1'
38+
with:
39+
path: 'vendor/bundle'
40+
key: "${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}"
41+
restore-keys: "${{ runner.os }}-gems-"
42+
- name: 'Set up test user'
43+
run: |
44+
$password = ConvertTo-SecureString $env:machine_pass -AsPlainText -Force
45+
New-LocalUser $env:machine_user -Password $password
46+
Add-LocalGroupMember -Group "Administrators" -Member $env:machine_user
47+
- name: 'Set up WinRM'
48+
run: |
49+
Set-WSManQuickConfig -Force
50+
- name: 'Run Bundler'
51+
run: |
52+
ruby --version
53+
bundle config path vendor/bundle
54+
bundle install --jobs 4 --retry 3
55+
- name: 'Run Test Kitchen'
56+
run: 'bundle exec kitchen verify ${{ matrix.instance }}'
57+
test-2019:
58+
runs-on: 'windows-2019'
59+
strategy:
60+
fail-fast: false
61+
matrix:
62+
instance:
63+
- default-windows-2019-latest-py3
64+
# - archive-windows-2019-latest-py3
65+
steps:
66+
- name: 'Check out code'
67+
uses: 'actions/checkout@v2'
68+
- name: 'Install Chef'
69+
uses: 'actionshub/[email protected]'
70+
with:
71+
project: 'chef'
72+
version: '16.10.8'
73+
- name: 'Add Chef bindir to PATH'
74+
uses: 'myci-actions/export-env-var-powershell@1'
75+
with:
76+
name: 'PATH'
77+
value: "C:\\opscode\\chef\\bin;\
78+
C:\\opscode\\chef\\embedded\\bin;$env:PATH"
79+
- name: 'Set up Bundler cache'
80+
uses: 'actions/cache@v1'
81+
with:
82+
path: 'vendor/bundle'
83+
key: "${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}"
84+
restore-keys: "${{ runner.os }}-gems-"
85+
- name: 'Set up test user'
86+
run: |
87+
$password = ConvertTo-SecureString $env:machine_pass -AsPlainText -Force
88+
New-LocalUser $env:machine_user -Password $password
89+
Add-LocalGroupMember -Group "Administrators" -Member $env:machine_user
90+
- name: 'Set up WinRM'
91+
run: |
92+
Set-WSManQuickConfig -Force
93+
- name: 'Run Bundler'
94+
run: |
95+
ruby --version
96+
bundle config path vendor/bundle
97+
bundle install --jobs 4 --retry 3
98+
- name: 'Run Test Kitchen'
99+
run: 'bundle exec kitchen verify ${{ matrix.instance }}'

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ gem 'kitchen-docker', git: 'https://gitlab.com/saltstack-formulas/infrastructure
1717

1818
gem 'kitchen-inspec', '>= 2.5.0'
1919
gem 'kitchen-salt', '>= 0.7.2'
20+
21+
group :vagrant do
22+
gem 'kitchen-vagrant'
23+
end

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ GEM
387387
kitchen-salt (0.7.2)
388388
hashie (>= 3.5)
389389
test-kitchen (>= 1.4)
390+
kitchen-vagrant (1.11.0)
391+
test-kitchen (>= 1.4, < 4)
390392
license-acceptance (2.1.13)
391393
pastel (~> 0.7)
392394
tomlrb (>= 1.2, < 3.0)
@@ -669,6 +671,7 @@ DEPENDENCIES
669671
kitchen-docker!
670672
kitchen-inspec (>= 2.5.0)
671673
kitchen-salt (>= 0.7.2)
674+
kitchen-vagrant
672675

673676
BUNDLED WITH
674677
2.1.2

docs/README.rst

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,64 @@ Runs all of the stages above in one go: i.e. ``destroy`` + ``converge`` + ``veri
162162

163163
Gives you SSH access to the instance for manual testing.
164164

165+
Testing with Vagrant
166+
--------------------
167+
168+
Windows/FreeBSD/OpenBSD testing is done with ``kitchen-salt``.
169+
170+
Requirements
171+
^^^^^^^^^^^^
172+
173+
* Ruby
174+
* Virtualbox
175+
* Vagrant
176+
177+
Setup
178+
^^^^^
179+
180+
.. code-block:: bash
181+
182+
$ gem install bundler
183+
$ bundle install --with=vagrant
184+
$ bin/kitchen test [platform]
185+
186+
Where ``[platform]`` is the platform name defined in ``kitchen.vagrant.yml``,
187+
e.g. ``windows-81-latest-py3``.
188+
189+
Note
190+
^^^^
191+
192+
When testing using Vagrant you must set the environment variable ``KITCHEN_LOCAL_YAML`` to ``kitchen.vagrant.yml``. For example:
193+
194+
.. code-block:: bash
195+
196+
$ KITCHEN_LOCAL_YAML=kitchen.vagrant.yml bin/kitchen test # Alternatively,
197+
$ export KITCHEN_LOCAL_YAML=kitchen.vagrant.yml
198+
$ bin/kitchen test
199+
200+
Then run the following commands as needed.
201+
202+
``bin/kitchen converge``
203+
^^^^^^^^^^^^^^^^^^^^^^^^
204+
205+
Creates the Vagrant instance and runs the ``vault`` main states, ready for testing.
206+
207+
``bin/kitchen verify``
208+
^^^^^^^^^^^^^^^^^^^^^^
209+
210+
Runs the ``inspec`` tests on the actual instance.
211+
212+
``bin/kitchen destroy``
213+
^^^^^^^^^^^^^^^^^^^^^^^
214+
215+
Removes the Vagrant instance.
216+
217+
``bin/kitchen test``
218+
^^^^^^^^^^^^^^^^^^^^
219+
220+
Runs all of the stages above in one go: i.e. ``destroy`` + ``converge`` + ``verify`` + ``destroy``.
221+
222+
``bin/kitchen login``
223+
^^^^^^^^^^^^^^^^^^^^^
224+
225+
Gives you RDP/SSH access to the instance for manual testing.

kitchen.vagrant.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
driver:
5+
name: vagrant
6+
cache_directory: false
7+
customize:
8+
usbxhci: 'off'
9+
gui: false
10+
ssh:
11+
shell: /bin/sh
12+
<% unless ENV['CI'] %>
13+
linked_clone: true
14+
synced_folders:
15+
- - '.kitchen/kitchen-vagrant/%{instance_name}/vagrant'
16+
- '/vagrant'
17+
- 'create: true, disabled: false'
18+
<% end %>
19+
20+
platforms:
21+
- name: freebsd-130-master-py3
22+
driver:
23+
box: myii/freebsd-13.0-master-py3
24+
- name: freebsd-123-master-py3
25+
driver:
26+
box: myii/freebsd-12.3-master-py3
27+
- name: freebsd-130-3004-0-py3
28+
driver:
29+
box: myii/freebsd-13.0-3004.0-py3
30+
- name: freebsd-123-3004-0-py3
31+
driver:
32+
box: myii/freebsd-12.3-3004.0-py3
33+
- name: openbsd-70-3003-3-py3
34+
driver:
35+
box: myii/openbsd-7.0-3003.3-py3
36+
ssh:
37+
shell: /bin/ksh
38+
synced_folders: []
39+
- name: openbsd-69-3002-6-py3
40+
driver:
41+
box: myii/openbsd-6.9-3002.6-py3
42+
ssh:
43+
shell: /bin/ksh
44+
synced_folders: []
45+
- name: windows-10-latest-py3
46+
driver:
47+
box: techneg/win10x64-pro-salt
48+
cache_directory: "/omnibus/cache"
49+
customize: {}
50+
ssh: {}
51+
provisioner:
52+
# yamllint disable rule:line-length
53+
init_environment: |
54+
# Workaround to allow `kitchen converge` to be used multiple times
55+
# without having to `kitchen destroy` first: remove state files cached by
56+
# Salt during the previous `converge` (if present)
57+
rm -recurse `
58+
C:\Users\vagrant\AppData\Local\Temp\kitchen\var\cache\salt\minion\files\base `
59+
-ErrorAction SilentlyContinue
60+
salt-call --local state.single file.managed `
61+
C:\Users\vagrant\AppData\Local\Temp\kitchen\srv\salt\win\repo-ng\node.js.sls `
62+
source=https://github.com/saltstack/salt-winrepo-ng/raw/master/node.js.sls `
63+
skip_verify=True makedirs=True
64+
exit 0
65+
# yamllint enable rule:line-length
66+
- name: windows-81-latest-py3
67+
driver:
68+
box: techneg/win81x64-pro-salt
69+
cache_directory: "/omnibus/cache"
70+
customize: {}
71+
ssh: {}
72+
provisioner:
73+
# yamllint disable rule:line-length
74+
init_environment: |
75+
# Workaround to allow `kitchen converge` to be used multiple times
76+
# without having to `kitchen destroy` first: remove state files cached by
77+
# Salt during the previous `converge` (if present)
78+
rm -recurse `
79+
C:\Users\vagrant\AppData\Local\Temp\kitchen\var\cache\salt\minion\files\base `
80+
-ErrorAction SilentlyContinue
81+
salt-call --local state.single file.managed `
82+
C:\Users\vagrant\AppData\Local\Temp\kitchen\srv\salt\win\repo-ng\node.js.sls `
83+
source=https://github.com/saltstack/salt-winrepo-ng/raw/master/node.js.sls `
84+
skip_verify=True makedirs=True
85+
exit 0
86+
# yamllint enable rule:line-length

kitchen.windows.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
driver:
5+
name: proxy
6+
host: localhost
7+
reset_command: "exit 0"
8+
port: 5985
9+
username: kitchen
10+
password: Pass@word1
11+
12+
provisioner:
13+
salt_install: bootstrap
14+
salt_bootstrap_options: -pythonVersion 3
15+
# yamllint disable rule:line-length
16+
init_environment: |
17+
salt-call --local state.single file.managed `
18+
C:\Users\kitchen\AppData\Local\Temp\kitchen\srv\salt\win\repo-ng\node.js.sls `
19+
source=https://github.com/saltstack/salt-winrepo-ng/raw/master/node.js.sls `
20+
skip_verify=True makedirs=True
21+
# yamllint enable rule:line-length
22+
23+
platforms:
24+
- name: windows-2022-latest-py3
25+
- name: windows-2019-latest-py3

node/config/environ.sls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{%- from tplroot ~ "/map.jinja" import node with context %}
77
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
88
9-
{%- if 'environ' in node and node.environ %}
9+
{%- if 'environ' in node and node.environ and grains.os_family != 'Windows' %}
1010
1111
{%- if node.pkg.use_upstream_source %}
1212
{%- set sls_package_install = tplroot ~ '.source.install' %}

node/config/file.sls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ node-config-npmrc-file-managed-config_file:
2424
lookup='node-config-file-file-managed-config_file'
2525
)
2626
}}
27+
{%- if grains.os_family != 'Windows' %}
2728
- mode: 640
2829
- user: {{ node.rootuser }}
2930
- group: {{ node.rootgroup }}
31+
{%- endif %}
3032
- makedirs: True
3133
- template: jinja
3234
- context:

node/init.sls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{%- set tplroot = tpldir.split('/')[0] %}
66
{%- from tplroot ~ "/map.jinja" import node with context %}
77
8-
{%- if grains.os_family not in ('FreeBSD', 'Windows', 'MacOS',) %}
8+
{%- if grains.os_family not in ('MacOS',) %}
99
{%- set p = node.pkg %}
1010
1111
include:

0 commit comments

Comments
 (0)