[buildout]
extends =
  ../../stack/slapos.cfg
  ../../stack/caucase/buildout.cfg
  ../../stack/nodejs.cfg
  ../../component/make/buildout.cfg
  ../../component/golang/buildout.cfg
  ../../component/openssl/buildout.cfg
  ../../component/curl/buildout.cfg
  ../../component/dash/buildout.cfg
  ../../component/jq/buildout.cfg
  ../../component/systemd/buildout.cfg
  ../../component/fluent-bit/buildout.cfg
  buildout.hash.cfg

parts =
  slapos-cookbook
  instance-profile
  gowork
  influxdb-config-file
  grafana-config-file
  grafana-provisioning-dashboards-config-file
  fluent-bit
  post-install-cleanup

[yarn]
<= yarn-4.6.0

[nodejs]
<= nodejs-22.11.0

[nodejs-headers]
<= nodejs-headers-22.11.0

[gcc]
part = gcc-12.3
min_version = 12.3.0

[go_github.com_grafana_grafana]
<= go-git-package
go.importpath = github.com/grafana/grafana
repository    = https://github.com/grafana/grafana
revision      = v11.5.0-0-gf7a938db9ad

[go_github.com_grafana_loki]
<= go-git-package
go.importpath = github.com/grafana/loki
repository    = https://github.com/grafana/loki
revision      = v3.3.2-0-g23b5fc2c9

[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.33.0-0-g679020053

[go_github.com_perrinjerome_slapos_telegraf_input]
<= go-git-package
go.importpath = github.com/perrinjerome/telegraf-input-slapos
repository    = https://github.com/perrinjerome/telegraf-input-slapos
revision      = v0.0.2-0-gd4c5221

[go_github.com_prometheus_prometheus]
<= go-git-package
go.importpath = github.com/prometheus/prometheus
repository    = https://github.com/prometheus/prometheus
revision      = v0.41.0-0-gc0d8a56c6


# [go_github.com_jaegertracking_jaeger]
# <= go-git-package
# go.importpath = github.com/jaegertracking/jaeger
# repository    = https://github.com/jaegertracking/jaeger
# revision      = v1.20.0-623-gcac21f82

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

environment =
  CGO_ENABLED=1
  CGO_CFLAGS=-I${systemd:location}/include
buildflags =
  -tags promtail_journal_enabled
cpkgpath =
  ${systemd:location}
telegraf-bin = ${:bin}/telegraf
telegraf-input-slapos-bin = ${:bin}/telegraf-input-slapos
influx-bin = ${:bin}/influx
influxd-bin = ${:bin}/influxd
grafana-bin = ${grafana:binpath}/grafana
grafana-homepath = ${grafana:homepath}
loki-bin = ${:bin}/loki
promtail-bin = ${:bin}/promtail
golang  = ${golang1.23:location}

[post-install-cleanup]
recipe = plone.recipe.command
stop-on-error = true
# remove caches and binary files confusing software check
command =
  chmod +w ${gowork.dir:directory}/pkg/mod/github.com/gabriel-vasile/mimetype@v1.4.4/testdata/ \
  && rm -rf ${gowork.dir:directory}/pkg/mod/github.com/gabriel-vasile/mimetype@v1.4.4/testdata/so.so \
  && chmod -w ${gowork.dir:directory}/pkg/mod/github.com/gabriel-vasile/mimetype@v1.4.4/testdata/ \
  && rm -rf ${buildout:directory}/.cache/

[grafana]
recipe = plone.recipe.command
command = bash -ce "
  cd ${:homepath} && \
  . ${gowork:env.sh} && \
  go run ./pkg/build/wire/cmd/wire/main.go gen -tags oss ./pkg/server && \
  go run build.go setup && \
  go run build.go build && \
  export NODE_OPTIONS=--max_old_space_size=8192 && \
  ${yarn:location}/bin/yarn install --immutable && \
  ${yarn:location}/bin/yarn run build"
homepath = ${go_github.com_grafana_grafana:location}
# XXX "linux-amd64" is not portable here
binpath = ${go_github.com_grafana_grafana:location}/bin/linux-amd64
stop-on-error = true

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

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

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

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

[instance-eggs]
recipe = zc.recipe.egg
eggs =
  toml


[instance-agent]
<= download-file-base

[instance-default]
<= download-file-base

[instance-profile]
recipe = slapos.recipe.template:jinja2
url = ${:_profile_base_location_}/${:filename}
output = ${buildout:directory}/instance.cfg
extensions = jinja2.ext.do
context =
  section buildout buildout
  key instance_default instance-default:target
  key instance_agent instance-agent:target
  key openssl_bin openssl-output:openssl
  key telegraf_bin gowork:telegraf-bin
  key telegraf_input_slapos_bin gowork:telegraf-input-slapos-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 jq_bin :jq-bin
  key caucase_jinja2_library caucase-jinja2-library:target
curl-bin = ${curl:location}/bin/curl
dash-bin = ${dash:location}/bin/dash
jq-bin = ${jq:location}/bin/jq
depends = ${instance-eggs:eggs} ${caucase-eggs:eggs}


[versions]
toml = 0.10.2
