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

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


[nodejs]
<= nodejs-8.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.3.2/yarn-v1.3.2.tar.gz
md5sum = db82fa09c996e9318f2f1d2ab99228f9


[gowork]
# All the softwares installed in the go work 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}

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

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

[telegraf-install]
<= gowork.goinstall
command = bash -c ". ${gowork:env.sh} && \
   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 && \
   ${gowork:golang}/bin/go run build.go setup && \
   ${gowork:golang}/bin/go run build.go build && \
   ${yarn:location}/bin/yarn install --pure-lockfile && \
   ${nodejs:location}/bin/npm run build"
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

[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


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

