golang-formula

Travis CI Build Status Semantic Release

Deploy and manage golang using Salt.

1. General notes

If you are interested in writing or contributing to formulas, please pay attention to the Writing Formula Section.

If you want to use this formula, please pay attention to the FORMULA file and/or git tag, which contains the currently released version. This formula is versioned according to Semantic Versioning.

If you need (non-default) configuration, please pay attention to the pillar.example file and/or Special notes section.

See Formula Versioning Section for more details.

2. Contributing to this repo

Commit message formatting is significant!!

Please see How to contribute for more details.

3. Special notes

This formula uses (non-default) GOPATH environment variable on Unix by default; see go_path key in defaults.yaml and pillar.example files. Normally GOPATH defaults to $HOME/go on Unix/Darwin, $home/go on Plan9, and %USERPROFILE%\go on Windows; another common setup is GOPATH=$HOME && export PATH=$PATH:$(go env GOPATH)/bin too.

4. Available states

4.1. golang

Meta-state (This is a state that includes other states).

This installs the golang package, manages the golang configuration file and then starts the associated golang service.

4.2. golang.package

This state will install the golang package only.

4.3. golang.config

This state will configure the golang service and has a dependency on golang.install via include list.

4.4. golang.service

This state will start the golang service and has a dependency on golang.config via include list.

4.5. golang.cmd

This is a metastate for go command tasks.

4.6. golang.cmd.clean

This state runs go clean -i <item>…​ for each item in cmd.clean dict.

4.7. golang.cmd.goget

This state runs go get <item>…​ for each item in cmd.get dict.

4.8. golang.clean

Meta-state (This is a state that includes other states).

this state will undo everything performed in the golang meta-state in reverse order, i.e. stops the service, removes the configuration file and then uninstalls the package.

4.9. golang.service.clean

This state will stop the golang service and disable it at boot time.

4.10. golang.config.clean

This state will remove the configuration of the golang service and has a dependency on golang.service.clean via include list.

4.11. golang.package.clean

This state will remove the golang package and has a depency on golang.config.clean via include list.

5. Testing

Linux testing is done with kitchen-salt.

5.1. Requirements

  • Ruby

  • Docker

$ gem install bundler
$ bundle install
$ bin/kitchen test [platform]

Where [platform] is the platform name defined in kitchen.yml, e.g. debian-9-2019-2-py3.

5.2. bin/kitchen converge

Creates the docker instance and runs the golang main state, ready for testing.

5.3. bin/kitchen verify

Runs the inspec tests on the actual instance.

5.4. bin/kitchen destroy

Removes the docker instance.

5.5. bin/kitchen test

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

5.6. bin/kitchen login

Gives you SSH access to the instance for manual testing.

6. Testing with Vagrant

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

6.1. Requirements

  • Ruby

  • Virtualbox

  • Vagrant

6.2. Setup

$ 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.

6.3. Note

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

$ 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.

6.4. bin/kitchen converge

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

6.5. bin/kitchen verify

Runs the inspec tests on the actual instance.

6.6. bin/kitchen destroy

Removes the Vagrant instance.

6.7. bin/kitchen test

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

6.8. bin/kitchen login

Gives you RDP/SSH access to the instance for manual testing.