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