[buildout]
extends =
  ../../stack/slapos.cfg
  ../../stack/nodejs.cfg
  ../../stack/monitor/buildout.cfg
  ../../component/make/buildout.cfg
  ../../component/golang/buildout.cfg
  ../../component/openssl/buildout.cfg
  ../../component/curl/buildout.cfg
  ../../component/dash/buildout.cfg
  buildout.hash.cfg
  gowork.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


[nodejs]
<= nodejs-10.6.0

[yarn]
# this could become a component, but it needs to be invoked from nodejs explicitly,
# otherwise it uses system's nodejs
recipe = slapos.recipe.build:download-unpacked
url = https://github.com/yarnpkg/yarn/releases/download/v1.16.0/yarn-v1.16.0.tar.gz
md5sum = 46790033c23803387890f545e4040690


[gowork]
# All the softwares installed in the go workspace have "non standard" installation
# methods, so we install them in specific parts with custom commands.
# They will be installed because they are dependencies of ${gowork.goinstall}
install =

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

# use recent go
golang  = ${golang1.12:location}
gcc-bin-directory  = ${golang1.12:gcc-bin-directory}

[gowork.goinstall]
command = :
depends =
   ${influxdb-install:recipe}
   ${telegraf-install:recipe}
   ${grafana-install:recipe}
   ${loki-install:recipe}
   ${promtail-install:recipe}

[influxdb-install]
<= gowork.goinstall
command = bash -c ". ${gowork:env.sh} && \
   go install -v github.com/golang/dep/cmd/dep && \
   cd ${gowork:directory}/src/github.com/influxdata/influxdb && \
   dep ensure && \
   go install ./cmd/..."
update-command =

[telegraf-install]
<= gowork.goinstall
command = bash -c ". ${gowork:env.sh} && \
   go install -v github.com/golang/dep/cmd/dep && \
   cd ${gowork:directory}/src/github.com/influxdata/telegraf && \
   ${make:location}/bin/make &&
   cp telegraf ${gowork:bin}"
update-command =

[grafana-install]
<= gowork.goinstall
# yarn and go run build.go needs our nodejs in $PATH
command = bash -c "export PATH=${nodejs:location}/bin/:$PATH && \
   . ${gowork:env.sh} && \
   cd ${gowork:directory}/src/github.com/grafana/grafana && \
   go run build.go setup && \
   go run build.go build && \
   ${yarn:location}/bin/yarn install --pure-lockfile && \
   ${nodejs:location}/bin/npm run build"
update-command =

[loki-install]
<= gowork.goinstall
# loki also uses nodejs
command = bash -c "export PATH=${nodejs:location}/bin/:$PATH && \
   . ${gowork:env.sh} && \
   go install -v github.com/golang/dep/cmd/dep && \
   cd ${gowork:directory}/src/github.com/grafana/loki && \
   go install ./cmd/loki"
update-command =

[promtail-install]
<= gowork.goinstall
# CGO_ENABLED is to disable systemd support (did not compile in my case)
command = bash -c "export CGO_ENABLED=0 && \
   . ${gowork:env.sh} && \
   go install -v github.com/golang/dep/cmd/dep && \
   cd ${gowork:directory}/src/github.com/grafana/loki && \
   go install ./cmd/promtail"
update-command =


[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
  key monitor_template monitor2-template:rendered
curl-bin = ${curl:location}/bin/curl
dash-bin = ${dash:location}/bin/dash

[versions]
slapos.recipe.template = 4.2
inotifyx = 0.2.2