[buildout]
extends =
  ../../stack/slapos.cfg
  ../../stack/nodejs.cfg
  ../../component/make/buildout.cfg
  ../../component/golang/buildout.cfg
  ../../component/openssl/buildout.cfg
  ../../component/curl/buildout.cfg
  ../../component/dash/buildout.cfg
  buildout.hash.cfg

versions = versions
parts =
  slapos-cookbook
  instance-profile
  gowork
  influxdb-config-file
  telegraf-config-file
  grafana-config-file
  grafana-provisioning-config-file
  loki-config-file
  promtail-config-file

[python]
part = python3

[nodejs]
<= nodejs-14.16.0

[yarn]
<= yarn-1.22.10


[go_github.com_grafana_grafana]
<= go-git-package
go.importpath = github.com/grafana/grafana
repository    = https://github.com/grafana/grafana
revision      = v7.5.2-0-gca413c612f

[go_github.com_grafana_loki]
<= go-git-package
go.importpath = github.com/grafana/loki
repository    = https://github.com/grafana/loki
revision      = v2.2.1-0-gbabea82e

[go_github.com_influxdata_influxdb]
<= go-git-package
go.importpath = github.com/influxdata/influxdb
repository    = https://github.com/influxdata/influxdb
revision      = v1.8.4-0-gbc8ec4384e

[go_github.com_influxdata_telegraf]
<= go-git-package
go.importpath = github.com/influxdata/telegraf
repository    = https://github.com/influxdata/telegraf
revision      = v1.17.3-0-g24a552b90b


[gowork]
install =
  ${go_github.com_grafana_loki:location}:./cmd/loki
  ${go_github.com_grafana_loki:location}:./cmd/promtail
  ${go_github.com_grafana_loki:location}:./cmd/logcli
  ${go_github.com_influxdata_telegraf:location}:./cmd/...
  ${go_github.com_influxdata_influxdb:location}:./cmd/...

# disable cgo, to prevent loki/promtail from using go-systemd
environment =
  CGO_ENABLED = 0

telegraf-bin = ${:bin}/telegraf
influx-bin = ${:bin}/influx
influxd-bin = ${:bin}/influxd
grafana-bin = ${:bin}/grafana-server
grafana-homepath = ${grafana:homepath}
loki-bin = ${:bin}/loki
promtail-bin = ${:bin}/promtail


[grafana]
recipe = plone.recipe.command
command = bash -c "
  cd ${:homepath} &&
  . ${gowork:env.sh} &&
  # Unlike the loki, grafana _needs_ CGO_ENABLED, so we override here
  export CGO_ENABLED=1 &&
  go run build.go setup && \
  go run build.go build && \
  ${yarn:location}/bin/yarn install --pure-lockfile && \
  ${yarn:location}/bin/yarn run build && \
  ${yarn:location}/bin/yarn run plugins:build-bundled && \
  # Cleanup yarn and Cypress caches
  rm -rf ${buildout:directory}/.cache/Cypress/ && \
  rm -rf ${buildout:directory}/.cache/yarn/
  "
homepath = ${go_github.com_grafana_grafana:location}
stop-on-error = true

[download-file-base]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/${:filename}
download-only = true
mode = 0644

[influxdb-config-file]
<= download-file-base

[telegraf-config-file]
<= download-file-base

[grafana-config-file]
<= download-file-base

[grafana-provisioning-config-file]
<= download-file-base

[loki-config-file]
<= download-file-base

[promtail-config-file]
<= download-file-base

[instance-profile]
recipe = slapos.recipe.template:jinja2
template = ${:_profile_base_location_}/${:filename}
rendered = ${buildout:directory}/instance.cfg
mode = 0644
extensions = jinja2.ext.do
context =
  section buildout buildout
  key openssl_bin openssl-output:openssl
  key telegraf_bin gowork:telegraf-bin
  key influxd_bin gowork:influxd-bin
  key influx_bin gowork:influx-bin
  key grafana_bin gowork:grafana-bin
  key grafana_homepath gowork:grafana-homepath
  key loki_bin gowork:loki-bin
  key promtail_bin gowork:promtail-bin
  key curl_bin :curl-bin
  key dash_bin :dash-bin
curl-bin = ${curl:location}/bin/curl
dash-bin = ${dash:location}/bin/dash

[versions]
inotifyx = 0.2.2
