Note: For testing containers see the dgoss wrapper.
Also, user submitted wrapper scripts for Kubernetes kgoss
and Docker Compose dcgoss.
Note: For some Docker/Kubernetes healthcheck, health endpoint, and
container ordering examples, see my blog post
here.
Introduction
What is Goss?
Goss is a YAML based serverspec alternative tool for validating a server's configuration.
It eases the process of writing tests by allowing the user to generate tests from the current system state.
Once the test suite is written they can be executed, waited-on, or served as a health endpoint.
As it is Serverspec alternative tool, there are some differences between them.
Pros of Goss
Easier to write as it is YAML
Tests can be defined by a single YAML file, easier to manage and doesn't require much time to learn.
Able to create test suite within a second.
Goss provides a command to define a test state automatically.
Easy to install
Goss comes with one single binary so no need to think about dependency.
Pros of Serverspec
Executable from remote
Like Ansible or Chef, able to execute from a remote node with SSH
More Resources
Goss supports about 20 Resources but Serverspec has twice (as of Mar 28th, 2019)
More flexible
Serverspec is more flexible as it allows us to code with Ruby.
Let's try
CentOS 7.5.1804 on Vagrant.
Goss v0.3.6.
Install
A script is prepared officially so it cannot be easier to install.
Also, dgoss which is a command for Docker container would be installed but I am not going to use it this time.
And please be noted that the script is not recommended for production environment.
Try manual install instead.
[vagrant@Vag2] ~
% curl -fsSL https://goss.rocks/install | sudo sh
Downloading https://github.com/aelsabbahy/goss/releases/download/v0.3.6/goss-linux-amd64
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 606 0 606 0 0 808 0 --:--:-- --:--:-- --:--:-- 809
100 8324k 100 8324k 0 0 236k 0 0:00:35 0:00:35 --:--:-- 240k
Goss v0.3.6 has been installed to /usr/local/bin/goss
goss --version
goss version v0.3.6
Downloading https://raw.githubusercontent.com/aelsabbahy/goss/master/extras/dgoss/dgoss
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3803 100 3803 0 0 9722 0 --:--:-- --:--:-- --:--:-- 9726
dgoss master has been installed to /usr/local/bin/dgoss
[vagrant@Vag2] ~
% which goss
/usr/local/bin/goss
[vagrant@Vag2] ~
%
Create a test suite
As I mentioned earlier, Goss has commands to create a test suite automatically.
goss.yaml will be created by goss autoadd or goss add [resource].
In this post, I will work on a host which HAProxy is installed.
[vagrant@Vag2] ~/work
% goss autoadd haproxy
Adding Group to './goss.yaml':
haproxy:
exists: true
gid: 188
Adding Package to './goss.yaml':
haproxy:
installed: true
versions:
- 1.5.18
Adding Process to './goss.yaml':
haproxy:
running: true
Adding Service to './goss.yaml':
haproxy:
enabled: true
running: true
Adding User to './goss.yaml':
haproxy:
exists: true
uid: 188
gid: 188
groups:
- haproxy
home: /var/lib/haproxy
shell: /sbin/nologin
[vagrant@Vag2] ~/work
%
After goss autoadd, the created goss.yaml is here.
As I tried, Goss is extremely great since it allows us to test within a minute.
In this post, it was only a simple test but it can be applied to production environment with more customize.
I assume Ansible can be a good match with Goss when comes to production use.
Or maybe it can extend monitoring accuracy with Goss healthcheck mode.