Skip to content

Commit 84a4759

Browse files
committed
initial add
0 parents  commit 84a4759

File tree

13 files changed

+329
-0
lines changed

13 files changed

+329
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.kitchen/
2+
*.swp
3+
*.swo

.kitchen.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
driver:
3+
name: vagrant
4+
network:
5+
- ["private_network", { ip: "192.168.55.55"}]
6+
7+
provisioner:
8+
name: salt_solo
9+
formula: golang
10+
pillars-from-files:
11+
golang.sls: pillar.example
12+
pillars:
13+
top.sls:
14+
base:
15+
"*":
16+
- golang
17+
state_top:
18+
base:
19+
"*":
20+
- golang
21+
- golang.debug
22+
23+
platforms:
24+
- name: ubuntu-14.04
25+
26+
suites:
27+
- name: default

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.2.2

Gemfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ruby '2.2.2'
2+
source "https://rubygems.org"
3+
4+
gem "test-kitchen", "> 1.2.1"
5+
gem "kitchen-vagrant"
6+
gem "unf"
7+
gem "kitchen-salt", ">=0.0.11"
8+
9+
10+
group :test, :development do
11+
gem 'net-ssh', '~> 2.0'
12+
gem 'serverspec'
13+
end

Gemfile.lock

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
artifactory (2.3.2)
5+
diff-lcs (1.2.5)
6+
kitchen-salt (0.0.23)
7+
test-kitchen (~> 1.4)
8+
kitchen-vagrant (0.20.0)
9+
test-kitchen (~> 1.4)
10+
mixlib-install (1.0.5)
11+
artifactory (>= 2.3.0)
12+
mixlib-shellout (>= 2.2.6)
13+
mixlib-versioning (>= 1.1.0)
14+
mixlib-shellout (2.2.6)
15+
mixlib-versioning (1.1.0)
16+
multi_json (1.11.2)
17+
net-scp (1.2.1)
18+
net-ssh (>= 2.6.5)
19+
net-ssh (2.9.4)
20+
net-telnet (0.1.1)
21+
rspec (3.4.0)
22+
rspec-core (~> 3.4.0)
23+
rspec-expectations (~> 3.4.0)
24+
rspec-mocks (~> 3.4.0)
25+
rspec-core (3.4.4)
26+
rspec-support (~> 3.4.0)
27+
rspec-expectations (3.4.0)
28+
diff-lcs (>= 1.2.0, < 2.0)
29+
rspec-support (~> 3.4.0)
30+
rspec-its (1.2.0)
31+
rspec-core (>= 3.0.0)
32+
rspec-expectations (>= 3.0.0)
33+
rspec-mocks (3.4.1)
34+
diff-lcs (>= 1.2.0, < 2.0)
35+
rspec-support (~> 3.4.0)
36+
rspec-support (3.4.1)
37+
safe_yaml (1.0.4)
38+
serverspec (2.31.1)
39+
multi_json
40+
rspec (~> 3.0)
41+
rspec-its
42+
specinfra (~> 2.53)
43+
sfl (2.2)
44+
specinfra (2.56.1)
45+
net-scp
46+
net-ssh (>= 2.7, < 4.0)
47+
net-telnet
48+
sfl
49+
test-kitchen (1.7.2)
50+
mixlib-install (~> 1.0, >= 1.0.4)
51+
mixlib-shellout (>= 1.2, < 3.0)
52+
net-scp (~> 1.1)
53+
net-ssh (>= 2.9, < 4.0)
54+
safe_yaml (~> 1.0)
55+
thor (~> 0.18)
56+
thor (0.19.1)
57+
unf (0.1.4)
58+
unf_ext
59+
unf_ext (0.0.7.2)
60+
61+
PLATFORMS
62+
ruby
63+
64+
DEPENDENCIES
65+
kitchen-salt (>= 0.0.11)
66+
kitchen-vagrant
67+
net-ssh (~> 2.0)
68+
serverspec
69+
test-kitchen (> 1.2.1)
70+
unf
71+
72+
BUNDLED WITH
73+
1.10.6

README.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
===============
2+
Golang-Formula
3+
==============
4+
5+
Formula to setup and configure specific versions of `Golang`.
6+
"Go is an open source programming language that makes it easy to build simple, reliable, and efficient software."
7+
8+
-- golang.org
9+
10+
.. note::
11+
12+
See the full `Salt Formulas installation and usage instructions
13+
<http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html>`_.
14+
15+
16+
Available states
17+
==================
18+
19+
.. contents::
20+
:local:
21+
22+
``golang``
23+
------------
24+
Install go!
25+
26+
``golang.debug``
27+
-----------------
28+
Helpful for debugging, dumps the jinja map to a text file
29+
30+
## Testing
31+
32+
Testing is done with `kitchen-salt<https://github.com/simonmcc/kitchen-salt>`_ which means you'll also need Ruby. Hopefully you're already using rbenv or whatever all of the cool kids are using these days, I'm a fuddy-duddy and use rbenv. This formula has been tested on both 1.9.3 and 2.2.2 versions of Ruby.
33+
34+
You should have `bundler` installed and have `bundle` on your $PATH, running this will set things up for Ruby. If you're not running ruby-2.2.2 an exception will be thrown because the `Gemfile` is pinned to 2.2.2, update your Ruby version and re-run bundle command(s)
35+
36+
```
37+
bundle
38+
39+
\\ or
40+
41+
bundle install
42+
```
43+
44+
Once you have successfully bundled things up, you should have the `kitchen` command on your $PATH. The first part is to run `kitchen converge` which will setup the environment by
45+
- creating a vagrant box
46+
- install salt
47+
- run the states defined in **golang-formula/.kitchen.yml**
48+
49+
50+
Once you've successfully `converged` the environment, the tests can be executed. If you were to run `kitchen verify` the tests found in `golang-formula/test/integration/default`. Currently there are only tests which use the `bats<https://blog.engineyard.com/2014/bats-test-command-line-tools>`_ ` `Busser<https://github.com/test-kitchen/busser>`_.
51+
52+
You can also run the `kitchen test` command, but that will destroy the existing vagrant before converging, roughly:
53+
```
54+
kitchen destroy && kitchen converge && kitchen verify && kitchen destroy
55+
```
56+
which is useful for CI pipelines but not so much during dev.
57+
58+
59+
## Author
60+
[Jack Scott](https://github.com/jackscott) \<[email protected]\>

golang/debug.sls

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% from "golang/map.jinja" import config with context %}
2+
3+
golang|debugin:
4+
file.managed:
5+
- name: /tmp/golang-formula.log
6+
- contents: |
7+
{% for k,v in config.items() %}
8+
{{ k }} => {{ v }}
9+
{% endfor %}

golang/defaults.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% load_yaml as meta %}
2+
prefix: /usr/local
3+
go_root: /usr/local/go
4+
go_path: /var/lib/golang
5+
version: "1.6"
6+
archive_hash: "5470eac05d273c74ff8bac7bef5bad0b5abbd1c4052efbdbc8db45332e836b0b"
7+
{% endload %}
8+
9+
{% load_yaml as rawmap %}
10+
Ubuntu:
11+
{{ meta }}
12+
RedHat:
13+
{{ meta }}
14+
{% endload %}
15+

golang/files/go_profile.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
{% from "golang/map.jinja" import config with context -%}
3+
# WARNING!! This file is managed by Salt
4+
# All edits will be lost on the next highstate
5+
export GOROOT={{ config.go_root }}
6+
export GOPATH={{ config.go_path }}
7+
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

golang/init.sls

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{% from "golang/map.jinja" import config with context %}
2+
# :TODO: Move this shit into defaults
3+
4+
# pull down a copy of the archive the first time we run but check
5+
# with the salt filesystem for a copy before hitting the web.
6+
# regardless of source, they should all pass the hash check
7+
golang|cache-archive:
8+
file.managed:
9+
- name: /tmp/{{ config.archive_name }}
10+
- source: https://storage.googleapis.com/golang/{{ config.archive_name }}
11+
- source_hash: sha256={{ config.archive_hash }}
12+
- user: root
13+
- group: root
14+
- unless:
15+
- test -f /tmp/{{ config.archive_name }}
16+
17+
# Extract the archive locally to {{ config.base_dir }}/go
18+
# which is useful if we ever need to handle multiple versions
19+
golang|extract-archive:
20+
file.directory:
21+
- names:
22+
- {{ config.base_dir }}
23+
- user: root
24+
- group: root
25+
- mode: 775
26+
- makedirs: true
27+
- recurse:
28+
- user
29+
- group
30+
- mode
31+
# golang|cache-archive provides us with a cached copy of the archive
32+
# so we only need to look in a single place when we actually exract
33+
# if the version of go is already installed and is on our path, skip extract
34+
archive.extracted:
35+
- name: {{ config.base_dir }}
36+
- source: "/tmp/{{ config.archive_name }}"
37+
- source_hash: sha256={{ config.archive_hash }}
38+
- archive_format: tar
39+
- user: root
40+
- group: root
41+
- tar_options: v
42+
- require:
43+
- file: golang|cache-archive
44+
- unless:
45+
- go version | grep {{ config.version }}
46+
- test -x {{ config.base_dir }}/go/bin/go
47+
48+
# add a symlink from versioned install to /usr/local/go
49+
golang|update-alternatives:
50+
alternatives.install:
51+
- name: golang-home-link
52+
- link: {{ config.go_root }}
53+
- path: {{ config.base_dir }}/go/
54+
- priority: 31
55+
- order: 10
56+
- watch:
57+
- archive: golang|extract-archive
58+
59+
# add symlinks to /usr/bin for the three go commands
60+
{% for i in ['go', 'godoc', 'gofmt'] %}
61+
golang|create-symlink-{{ i }}:
62+
alternatives.install:
63+
- name: link-{{ i }}
64+
- link: /usr/bin/{{ i }}
65+
- path: {{ config.go_root }}/bin/{{ i }}
66+
- priority: 40
67+
- order: 10
68+
- watch:
69+
- archive: golang|extract-archive
70+
{% endfor %}
71+
72+
golang|setup-bash-profile:
73+
file.managed:
74+
- name: /etc/profile.d/golang.sh
75+
- source:
76+
- salt://files/go_profile.sh
77+
- salt://golang/files/go_profile.sh
78+
- template: jinja
79+
- mode: 644
80+
- user: root
81+
- group: root
82+

0 commit comments

Comments
 (0)