Skip to content

Commit

Permalink
Merge pull request #3 from komminarlabs/tk/grafana
Browse files Browse the repository at this point in the history
Added Grafana OSS pack
  • Loading branch information
thulasirajkomminar authored Sep 5, 2024
2 parents 02f1955 + 232a0eb commit 97b01e2
Show file tree
Hide file tree
Showing 13 changed files with 487 additions and 88 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ nomad-pack registry add default github.com/komminarlabs/nomad-pack-registry

## Available packs

- [Grafana OSS](/packs/grafana/README.md)
- [InfluxDB OSS](/packs/influxdb2/README.md)
3 changes: 3 additions & 0 deletions packs/grafana/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 0.1.0

- Initial release
22 changes: 22 additions & 0 deletions packs/grafana/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Grafana OSS

This pack uses Docker driver to deploy Grafana OSS in Nomad.

## Variables

- `datacenters` (list of string) - A list of datacenters in the region which are eligible for task placement.
- `docker_env_vars` (map of string) - Environment variables to pass to Docker container.
- `grafana_task_config_datasources` (string) - The yaml configuration for automatic provision of datasources.
- `grafana_task_config_ini` (string) - ini string for grafana.ini.
- `grafana_task_resources` (object) - The resource to assign to the Grafana service task.
- `region` (string) - The region where the job should be placed.
- `constraints` (list of object) - Constraints to apply to the entire job.
- `consul_service` (object) - The consul service for grafana.
- `data_volume` (object) - The dedicated data volume you want InfluxDB to use.
- `grafana_task_artifacts` (list of object) - Define external artifacts for Grafana.
- `grafana_task_config_dashboards` (string) - The yaml configuration for automatic provision of dashboards.
- `grafana_version_tag` (string) - The docker image version. For options, see https://hub.docker.com/grafana/grafana.
- `grafana_task_config_plugins` (string) - The yaml configuration for automatic provision of plugins.
- `namespace` (string) - The namespace where the job should be placed.
- `node_pool` (string) - The node_pool where the job should be placed.
- `vault_policies` (list of string) - List of Vault Policies.
16 changes: 16 additions & 0 deletions packs/grafana/metadata.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
app {
url = "https://grafana.com/"
author = "Grafana Labs"
}

pack {
name = "grafana"
description = "Dashboard anything. Observe everything."
url = "https://github.com/komminarlabs/nomad-pack-registry/grafana"
version = "0.1.0"
}

integration {
identifier = "nomad/komminarlabs/grafana"
name = "Grafana OSS"
}
3 changes: 3 additions & 0 deletions packs/grafana/outputs.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Congrats on deploying [[ meta "pack.name" . ]].

There are [[ var "app_count" . ]] instances of your job now running on Nomad.
4 changes: 4 additions & 0 deletions packs/grafana/overrides.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data_volume = {
name = "grafana_data_volume"
type = "host"
}
184 changes: 184 additions & 0 deletions packs/grafana/templates/grafana.nomad.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
job "grafana" {
region = "[[ var "region" . ]]"
datacenters = [[ (var "datacenters" .) | toStringList ]]
node_pool = "[[ var "node_pool" . ]]"
type = "service"
[[- if var "namespace" . ]]
namespace = "[[ var "namespace" . ]]"
[[- end ]]
[[- if var "constraints" . ]][[ range $idx, $constraint := var "constraints" . ]]
constraint {
[[- if ne $constraint.attribute "" ]]
attribute = "[[ $constraint.attribute ]]"
[[- end ]]
[[- if ne $constraint.value "" ]]
value = "[[ $constraint.value ]]"
[[- end ]]
[[- if ne $constraint.operator "" ]]
operator = "[[ $constraint.operator ]]"
[[- end ]]
}
[[- end ]]
[[- end ]]

group "grafana" {
count = 1
network {
port "http" {
static = 3000
}
}

[[- if var "consul_service.register" . ]]

service {
name = "[[ var "consul_service.name" . ]]"
[[- if ne (len (var "consul_service.tags" .)) 0 ]]
tags = [[ (var "consul_service.tags" .) | toStringList ]]
[[- end ]]
port = "http"
check {
name = "alive"
type = "http"
path = "/health"
interval = "10s"
timeout = "2s"
}
}
[[- end ]]

[[- if var "vault_policies" . ]]

vault {
policies = [[ (var "vault_policies" .) | toStringList ]]
change_mode = "noop"
}
[[- end ]]

[[- if var "data_volume" . ]]
volume "[[ var "data_volume.name" . ]]" {
type = "[[ var "data_volume.type" . ]]"
read_only = false
source = "[[ var "data_volume.name" . ]]"
}
[[- end ]]

[[- if var "data_volume" . ]]

task "chown_data_volume" {
driver = "docker"
lifecycle {
hook = "prestart"
sidecar = false
}

volume_mount {
volume = "[[ var "data_volume.name" . ]]"
destination = "/var/lib/grafana"
read_only = false
}

config {
image = "busybox:stable"
command = "sh"
args = ["-c", "chown -R 1000:1000 /var/lib/grafana"]
}

resources {
cpu = 200
memory = 128
}
}
[[- end ]]

task "grafana" {
driver = "docker"
[[- if var "data_volume" . ]]
volume_mount {
volume = "[[ var "data_volume.name" . ]]"
destination = "/var/lib/grafana"
read_only = false
}
[[- end ]]

config {
image = "grafana/grafana:[[ var "grafana_version_tag" . ]]"
ports = ["http"]
}

resources {
cpu = [[ var "grafana_task_resources.cpu" . ]]
memory = [[ var "grafana_task_resources.memory" . ]]
}

[[- if ne (len (var "docker_env_vars" .)) 0 ]]

env {
[[- range $key, $var := var "docker_env_vars" . ]]
[[if ne (len $var) 0 ]][[ $key | upper ]] = [[ $var | quote ]][[ end ]]
[[- end ]]
}
[[- end ]]

[[- if var "grafana_task_artifacts" . ]]
[[- range $artifact := var "grafana_task_artifacts" . ]]

artifact {
source = "[[ $artifact.source ]]"
destination = "[[ $artifact.destination ]]"
mode = "[[ $artifact.mode ]]"
[[- if $artifact.options ]]
options {
[[- range $option, $val := $artifact.options ]]
[[ $option ]] = "[[ $val ]]"
[[- end ]]
}
[[- end ]]
}
[[- end ]]
[[- end ]]

template {
data = <<EOF
[[ var "grafana_task_config_ini" . ]]
EOF
destination = "/local/grafana/grafana.ini"
}

[[- if var "grafana_task_config_dashboards" . ]]
template {
data = <<EOF
[[ var "grafana_task_config_dashboards" . ]]
EOF
destination = "/local/grafana/provisioning/dashboards/dashboards.yaml"
}
[[ end ]]

[[- if var "grafana_task_config_datasources" . ]]
template {
data = <<EOF
[[ var "grafana_task_config_datasources" . ]]
EOF
destination = "/local/grafana/provisioning/datasources/datasources.yaml"
}
[[ end ]]

[[- if var "grafana_task_config_plugins" . ]]

template {
data = <<EOF
[[ var "grafana_task_config_plugins" . ]]
EOF
destination = "/local/grafana/provisioning/plugins/plugins.yml"
}
[[- end -]]
}
}
}
Loading

0 comments on commit 97b01e2

Please sign in to comment.