Skip to content

Commit

Permalink
Merge pull request #64 from myii/chore/standardise-structure
Browse files Browse the repository at this point in the history
feat: enable Vagrant-based testing using GitHub Actions for FreeBSD, OpenBSD & Windows
  • Loading branch information
myii committed Mar 24, 2022
2 parents b511c40 + 05c942e commit 60bdaca
Show file tree
Hide file tree
Showing 15 changed files with 387 additions and 9 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/kitchen.vagrant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
name: 'Kitchen Vagrant (FreeBSD, OpenBSD & Windows)'
'on': ['push', 'pull_request']

env:
KITCHEN_LOCAL_YAML: 'kitchen.vagrant.yml'

jobs:
test:
runs-on: 'macos-10.15'
strategy:
fail-fast: false
matrix:
instance:
- default-freebsd-130-master-py3
# - archive-freebsd-130-master-py3
# - source-freebsd-130-master-py3
# - repo-freebsd-130-master-py3
- default-freebsd-123-master-py3
# - archive-freebsd-123-master-py3
# - source-freebsd-123-master-py3
# - repo-freebsd-123-master-py3
# - default-freebsd-130-3004-0-py3
# - default-freebsd-123-3004-0-py3
- default-openbsd-70-3003-3-py3
# - archive-openbsd-70-3003-3-py3
- default-openbsd-69-3002-6-py3
# - archive-openbsd-69-3002-6-py3
- default-windows-10-latest-py3
# - archive-windows-10-latest-py3
- default-windows-81-latest-py3
# - archive-windows-81-latest-py3
steps:
- name: 'Check out code'
uses: 'actions/checkout@v2'
- name: 'Set up Bundler cache'
uses: 'actions/cache@v1'
with:
path: 'vendor/bundle'
key: "${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}"
restore-keys: "${{ runner.os }}-gems-"
- name: 'Run Bundler'
run: |
ruby --version
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: 'Run Test Kitchen'
run: 'bundle exec kitchen verify ${{ matrix.instance }}'
99 changes: 99 additions & 0 deletions .github/workflows/kitchen.windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
name: 'Kitchen (Windows)'
'on': ['push', 'pull_request']

env:
machine_user: kitchen
machine_pass: Pass@word1
machine_port: 5985
KITCHEN_LOCAL_YAML: 'kitchen.windows.yml'

jobs:
test-2022:
runs-on: 'windows-2022'
strategy:
fail-fast: false
matrix:
instance:
- default-windows-2022-latest-py3
# - archive-windows-2022-latest-py3
steps:
- name: 'Check out code'
uses: 'actions/checkout@v2'
- name: 'Install Chef'
uses: 'actionshub/chef-install@1.1.0'
with:
project: 'chef'
version: '16.10.8'
- name: 'Add Chef bindir to PATH'
uses: 'myci-actions/export-env-var-powershell@1'
with:
name: 'PATH'
value: "C:\\opscode\\chef\\bin;\
C:\\opscode\\chef\\embedded\\bin;$env:PATH"
- name: 'Set up Bundler cache'
uses: 'actions/cache@v1'
with:
path: 'vendor/bundle'
key: "${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}"
restore-keys: "${{ runner.os }}-gems-"
- name: 'Set up test user'
run: |
$password = ConvertTo-SecureString $env:machine_pass -AsPlainText -Force
New-LocalUser $env:machine_user -Password $password
Add-LocalGroupMember -Group "Administrators" -Member $env:machine_user
- name: 'Set up WinRM'
run: |
Set-WSManQuickConfig -Force
- name: 'Run Bundler'
run: |
ruby --version
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: 'Run Test Kitchen'
run: 'bundle exec kitchen verify ${{ matrix.instance }}'
test-2019:
runs-on: 'windows-2019'
strategy:
fail-fast: false
matrix:
instance:
- default-windows-2019-latest-py3
# - archive-windows-2019-latest-py3
steps:
- name: 'Check out code'
uses: 'actions/checkout@v2'
- name: 'Install Chef'
uses: 'actionshub/chef-install@1.1.0'
with:
project: 'chef'
version: '16.10.8'
- name: 'Add Chef bindir to PATH'
uses: 'myci-actions/export-env-var-powershell@1'
with:
name: 'PATH'
value: "C:\\opscode\\chef\\bin;\
C:\\opscode\\chef\\embedded\\bin;$env:PATH"
- name: 'Set up Bundler cache'
uses: 'actions/cache@v1'
with:
path: 'vendor/bundle'
key: "${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}"
restore-keys: "${{ runner.os }}-gems-"
- name: 'Set up test user'
run: |
$password = ConvertTo-SecureString $env:machine_pass -AsPlainText -Force
New-LocalUser $env:machine_user -Password $password
Add-LocalGroupMember -Group "Administrators" -Member $env:machine_user
- name: 'Set up WinRM'
run: |
Set-WSManQuickConfig -Force
- name: 'Run Bundler'
run: |
ruby --version
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: 'Run Test Kitchen'
run: 'bundle exec kitchen verify ${{ matrix.instance }}'
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ gem 'kitchen-docker', git: 'https://gitlab.com/saltstack-formulas/infrastructure

gem 'kitchen-inspec', '>= 2.5.0'
gem 'kitchen-salt', '>= 0.7.2'

group :vagrant do
gem 'kitchen-vagrant'
end
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ GEM
kitchen-salt (0.7.2)
hashie (>= 3.5)
test-kitchen (>= 1.4)
kitchen-vagrant (1.11.0)
test-kitchen (>= 1.4, < 4)
license-acceptance (2.1.13)
pastel (~> 0.7)
tomlrb (>= 1.2, < 3.0)
Expand Down Expand Up @@ -669,6 +671,7 @@ DEPENDENCIES
kitchen-docker!
kitchen-inspec (>= 2.5.0)
kitchen-salt (>= 0.7.2)
kitchen-vagrant

BUNDLED WITH
2.1.2
61 changes: 61 additions & 0 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,64 @@ Runs all of the stages above in one go: i.e. ``destroy`` + ``converge`` + ``veri

Gives you SSH access to the instance for manual testing.

Testing with Vagrant
--------------------

Windows/FreeBSD/OpenBSD testing is done with ``kitchen-salt``.

Requirements
^^^^^^^^^^^^

* Ruby
* Virtualbox
* Vagrant

Setup
^^^^^

.. code-block:: bash
$ gem install bundler
$ bundle install --with=vagrant
$ bin/kitchen test [platform]
Where ``[platform]`` is the platform name defined in ``kitchen.vagrant.yml``,
e.g. ``windows-81-latest-py3``.

Note
^^^^

When testing using Vagrant you must set the environment variable ``KITCHEN_LOCAL_YAML`` to ``kitchen.vagrant.yml``. For example:

.. code-block:: bash
$ KITCHEN_LOCAL_YAML=kitchen.vagrant.yml bin/kitchen test # Alternatively,
$ export KITCHEN_LOCAL_YAML=kitchen.vagrant.yml
$ bin/kitchen test
Then run the following commands as needed.

``bin/kitchen converge``
^^^^^^^^^^^^^^^^^^^^^^^^

Creates the Vagrant instance and runs the ``vault`` main states, ready for testing.

``bin/kitchen verify``
^^^^^^^^^^^^^^^^^^^^^^

Runs the ``inspec`` tests on the actual instance.

``bin/kitchen destroy``
^^^^^^^^^^^^^^^^^^^^^^^

Removes the Vagrant instance.

``bin/kitchen test``
^^^^^^^^^^^^^^^^^^^^

Runs all of the stages above in one go: i.e. ``destroy`` + ``converge`` + ``verify`` + ``destroy``.

``bin/kitchen login``
^^^^^^^^^^^^^^^^^^^^^

Gives you RDP/SSH access to the instance for manual testing.
86 changes: 86 additions & 0 deletions kitchen.vagrant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
driver:
name: vagrant
cache_directory: false
customize:
usbxhci: 'off'
gui: false
ssh:
shell: /bin/sh
<% unless ENV['CI'] %>
linked_clone: true
synced_folders:
- - '.kitchen/kitchen-vagrant/%{instance_name}/vagrant'
- '/vagrant'
- 'create: true, disabled: false'
<% end %>

platforms:
- name: freebsd-130-master-py3
driver:
box: myii/freebsd-13.0-master-py3
- name: freebsd-123-master-py3
driver:
box: myii/freebsd-12.3-master-py3
- name: freebsd-130-3004-0-py3
driver:
box: myii/freebsd-13.0-3004.0-py3
- name: freebsd-123-3004-0-py3
driver:
box: myii/freebsd-12.3-3004.0-py3
- name: openbsd-70-3003-3-py3
driver:
box: myii/openbsd-7.0-3003.3-py3
ssh:
shell: /bin/ksh
synced_folders: []
- name: openbsd-69-3002-6-py3
driver:
box: myii/openbsd-6.9-3002.6-py3
ssh:
shell: /bin/ksh
synced_folders: []
- name: windows-10-latest-py3
driver:
box: techneg/win10x64-pro-salt
cache_directory: "/omnibus/cache"
customize: {}
ssh: {}
provisioner:
# yamllint disable rule:line-length
init_environment: |
# Workaround to allow `kitchen converge` to be used multiple times
# without having to `kitchen destroy` first: remove state files cached by
# Salt during the previous `converge` (if present)
rm -recurse `
C:\Users\vagrant\AppData\Local\Temp\kitchen\var\cache\salt\minion\files\base `
-ErrorAction SilentlyContinue
salt-call --local state.single file.managed `
C:\Users\vagrant\AppData\Local\Temp\kitchen\srv\salt\win\repo-ng\node.js.sls `
source=https://github.com/saltstack/salt-winrepo-ng/raw/master/node.js.sls `
skip_verify=True makedirs=True
exit 0
# yamllint enable rule:line-length
- name: windows-81-latest-py3
driver:
box: techneg/win81x64-pro-salt
cache_directory: "/omnibus/cache"
customize: {}
ssh: {}
provisioner:
# yamllint disable rule:line-length
init_environment: |
# Workaround to allow `kitchen converge` to be used multiple times
# without having to `kitchen destroy` first: remove state files cached by
# Salt during the previous `converge` (if present)
rm -recurse `
C:\Users\vagrant\AppData\Local\Temp\kitchen\var\cache\salt\minion\files\base `
-ErrorAction SilentlyContinue
salt-call --local state.single file.managed `
C:\Users\vagrant\AppData\Local\Temp\kitchen\srv\salt\win\repo-ng\node.js.sls `
source=https://github.com/saltstack/salt-winrepo-ng/raw/master/node.js.sls `
skip_verify=True makedirs=True
exit 0
# yamllint enable rule:line-length
25 changes: 25 additions & 0 deletions kitchen.windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
driver:
name: proxy
host: localhost
reset_command: "exit 0"
port: 5985
username: kitchen
password: Pass@word1

provisioner:
salt_install: bootstrap
salt_bootstrap_options: -pythonVersion 3
# yamllint disable rule:line-length
init_environment: |
salt-call --local state.single file.managed `
C:\Users\kitchen\AppData\Local\Temp\kitchen\srv\salt\win\repo-ng\node.js.sls `
source=https://github.com/saltstack/salt-winrepo-ng/raw/master/node.js.sls `
skip_verify=True makedirs=True
# yamllint enable rule:line-length

platforms:
- name: windows-2022-latest-py3
- name: windows-2019-latest-py3
2 changes: 1 addition & 1 deletion node/config/environ.sls
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{%- from tplroot ~ "/map.jinja" import node with context %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
{%- if 'environ' in node and node.environ %}
{%- if 'environ' in node and node.environ and grains.os_family != 'Windows' %}
{%- if node.pkg.use_upstream_source %}
{%- set sls_package_install = tplroot ~ '.source.install' %}
Expand Down
2 changes: 2 additions & 0 deletions node/config/file.sls
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ node-config-npmrc-file-managed-config_file:
lookup='node-config-file-file-managed-config_file'
)
}}
{%- if grains.os_family != 'Windows' %}
- mode: 640
- user: {{ node.rootuser }}
- group: {{ node.rootgroup }}
{%- endif %}
- makedirs: True
- template: jinja
- context:
Expand Down
2 changes: 1 addition & 1 deletion node/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import node with context %}
{%- if grains.os_family not in ('FreeBSD', 'Windows', 'MacOS',) %}
{%- if grains.os_family not in ('MacOS',) %}
{%- set p = node.pkg %}
include:
Expand Down
Loading

0 comments on commit 60bdaca

Please sign in to comment.