Skip to content

Commit

Permalink
feat(archives): introduce support for archive files
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the parameter `pkg` is now a dictionary. References
 to `template.pkg` should be changed to `template.pkg.name`.
  • Loading branch information
noelmcloughlin committed Jun 9, 2019
1 parent e2a9da6 commit e7a1523
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 13 deletions.
11 changes: 11 additions & 0 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ starts the associated grafana service.

This state will install the grafana package only.

``grafana.archive``
^^^^^^^^^^^^^^^^^^^

This state will install the grafana software from archive file only.

``grafana.config``
^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -91,3 +96,9 @@ dependency on ``grafana.service.clean`` via include list.

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

``grafana.archive.clean``
^^^^^^^^^^^^^^^^^^^^^^^^^

This state will uninstall grafana software from archive extracted directory.

12 changes: 12 additions & 0 deletions grafana/archive/clean.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import grafana with context %}
grafana-cli-package-archive-clean-file-absent:
file.absent:
- names:
- {{ grafana.pkg.archive.name }}/grafana-6.2.2.darwin-amd64
- {{ grafana.pkg.archive.name }}/grafana-6.2.2.linux-amd64
5 changes: 5 additions & 0 deletions grafana/archive/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#.-*- coding: utf-8 -*-
# vim: ft=sls

include:
- .install
18 changes: 18 additions & 0 deletions grafana/archive/install.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import grafana with context %}
{%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %}
grafana-package-archive-install-file-directory:
file.directory:
- name: {{ grafana.pkg.archive.name }}
- makedirs: True
- require_in:
- archive: grafana-package-archive-install-archive-extracted
grafana-package-archive-install-archive-extracted:
archive.extracted:
{{- format_kwargs(grafana.pkg.archive) }}
1 change: 1 addition & 0 deletions grafana/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ include:
- .service.clean
- .config.clean
- .package.clean
- .archive.clean
4 changes: 3 additions & 1 deletion grafana/config/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ include:
grafana-config-clean-file-absent:
file.absent:
- name: {{ grafana.config_file }}
- names:
- {{ grafana.config_file }}
- {{ grafana.environ_file }}
- require:
- sls: {{ sls_service_clean }}
34 changes: 34 additions & 0 deletions grafana/config/environ.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import grafana with context %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
{%- if 'environ' in grafana and grafana.environ %}
{%- if grafana.pkg.use_upstream_archive %}
{%- set sls_package_install = tplroot ~ '.archive.install' %}
include:
- {{ sls_package_install }}
grafana-config-file-file-managed-environ_file:
file.managed:
- name: {{ grafana.environ_file }}
- source: {{ files_switch(['grafana.sh.jinja'],
lookup='grafana-config-file-file-managed-environ_file'
)
}}
- mode: 640
- user: root
- group: {{ grafana.group }}
- makedirs: True
- template: jinja
- context:
config: {{ grafana.environ|json }}
- require:
- sls: {{ sls_package_install }}
{%- endif %}
{%- endif %}
14 changes: 11 additions & 3 deletions grafana/config/file.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_package_install = tplroot ~ '.package.install' %}
{%- from tplroot ~ "/map.jinja" import grafana with context %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
{%- if 'config' in grafana and grafana.config %}
{%- if grafana.pkg.use_upstream_archive %}
{%- set sls_package_install = tplroot ~ '.archive.install' %}
{%- else %}
{%- set sls_package_install = tplroot ~ '.package.install' %}
{%- endif %}
include:
- {{ sls_package_install }}
grafana-config-file-file-managed:
grafana-config-file-file-managed-config_file:
file.managed:
- name: {{ grafana.config_file }}
- source: {{ files_switch(['grafana.ini.jinja'],
lookup='grafana-config-file-file-managed'
lookup='grafana-config-file-file-managed-config_file'
)
}}
- mode: 640
Expand All @@ -26,3 +32,5 @@ grafana-config-file-file-managed:
config: {{ grafana.config|json }}
- require:
- sls: {{ sls_package_install }}
{%- endif %}
1 change: 1 addition & 0 deletions grafana/config/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

include:
- .file
- .environ
16 changes: 14 additions & 2 deletions grafana/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@
# vim: ft=yaml
---
grafana:
pkg: grafana
pkgrepo: False
pkg:
name: grafana
binary: grafana
use_upstream_archive: False
archive:
name: /opt
source: https://dl.grafana.com/oss/release/grafana-6.2.2.linux-amd64.tar.gz
source_hash: bf2a1ffab417e54a1c31e421077b9c5278e423d5fa9b7b98d418c4f85602838b
trim_output: True
enforce_toplevel: True
pkgrepo: {}
group: grafana
config_file: /etc/grafana/grafana.ini
config: {}
environ_file: /etc/default/grafana.sh
environ:
- 'export PATH=${PATH}:/opt/grafana-6.2.2.linux-amd64'
service:
name: grafana-server
user: grafana
Expand Down
8 changes: 8 additions & 0 deletions grafana/files/default/grafana.sh.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
########################################################################
# File managed by Salt at <{{ source }}>.
# Your changes will be overwritten.
########################################################################

{%- for item in config %}
{{ item }}
{%- endfor %}
6 changes: 5 additions & 1 deletion grafana/init.sls
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import grafana with context %}
include:
- .package
- {{ '.archive' if grafana.pkg.use_upstream_archive else '.package' }}
- .config
- .service
16 changes: 14 additions & 2 deletions grafana/osfamilymap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,21 @@ OpenBSD: {}

Solaris: {}

Windows: {}
Windows:
pkg:
archive:
name: C:\\Program Files
source: https://dl.grafana.com/oss/release/grafana-6.2.2.windows-amd64.zip
source_hash: c44ae0019834a73860ba9804965b79235be9284017d716823c316ac6b24abc4f

MacOS:
rootgroup: {{ macos_group | d('') }}
group: {{ macos_group | d('') }}
service:
group: {{ macos_group | d('') }}
environ:
- 'export PATH=${PATH}:/opt/grafana-6.2.2.darwin-amd64'
pkg:
archive:
name: /opt
source: https://dl.grafana.com/oss/release/grafana-6.2.2.darwin-amd64.tar.gz
source_hash: 3c3d599ba8be48d22eee71f1854d185d7613b9439c0c655a1eb33e1e13474c50
2 changes: 1 addition & 1 deletion grafana/package/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ include:
grafana-package-clean-pkg-removed:
pkg.removed:
- name: {{ grafana.pkg }}
- name: {{ grafana.pkg.name }}
- require:
- sls: {{ sls_config_clean }}
2 changes: 1 addition & 1 deletion grafana/package/install.sls
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ grafana-package-install-pkgrepo-managed:
grafana-package-install-pkg-installed:
pkg.installed:
- name: {{ grafana.pkg }}
- name: {{ grafana.pkg.name }}
4 changes: 3 additions & 1 deletion grafana/service/running.sls
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ grafana-service-running-service-running:
service.running:
- name: {{ grafana.service.name }}
- enable: True
{%- if 'config' in grafana and grafana.config %}
- watch:
- file: grafana-config-file-file-managed
- file: grafana-config-file-file-managed-config_file
- require:
- sls: {{ sls_config_file }}
{%- endif %}
6 changes: 5 additions & 1 deletion pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
# vim: ft=yaml
---
grafana:
pkg: grafana
pkg:
name: grafana
pkgrepo:
humanname: grafana_official
name: deb https://packages.grafana.com/oss/deb stable main
file: /etc/apt/sources.list.d/grafana.list
key_url: https://packages.grafana.com/gpg.key
config_file: /etc/grafana/grafana.ini
environ_file: /etc/default.grafana.sh
service:
name: grafana-server

Expand Down Expand Up @@ -37,6 +39,8 @@ grafana:

# Pillar-based config
# See also https://grafana.com/docs/installation/configuration/
environ:
- 'export PATH=${PATH}:/opt/grafana-6.2.2.darwin-amd64'
config:
default:
instance_name: ${HOSTNAME}
Expand Down

0 comments on commit e7a1523

Please sign in to comment.