From 859005d497fe14bcd7335bfd8bd95a0bdaa5e63b Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Fri, 11 Mar 2022 11:52:47 +1100 Subject: [PATCH] grafana: add helper script Add a helper script and assocated README.rst to explain the interactive development process. Depends-On: https://review.opendev.org/c/opendev/grafyaml/+/833212 Change-Id: Ibbc2b116d0c496655a7ce6bb6971e8270ac32647 --- grafana/README.rst | 14 ++++++++++++++ grafana/run-grafana.sh | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 grafana/README.rst create mode 100644 grafana/run-grafana.sh diff --git a/grafana/README.rst b/grafana/README.rst new file mode 100644 index 0000000000..d04e3fc50e --- /dev/null +++ b/grafana/README.rst @@ -0,0 +1,14 @@ +Developing Graphs +================= + +The ``run-grafana.sh`` script in this directory will start a Docker +container with Grafana listening on port 3000. It will then load the +datasources and dashboards in this directory. Repeated runs of the +script will re-load the scripts. + +You can log into the instance with the username "admin" and password +"password". You can then use the Grafana UI to develop graphs. + +The "share" icon on the graph in the UI can be used to export a JSON +file, which your browser will download. You can copy that to this +directory (or update existing files) and submit a review. diff --git a/grafana/run-grafana.sh b/grafana/run-grafana.sh new file mode 100644 index 0000000000..29a3b8cf29 --- /dev/null +++ b/grafana/run-grafana.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +DOCKER=docker +GRAFYAML_DIR=$(pwd) +SECRETS_DIR=$(pwd)/grafana-secrets + +if [ ! -d ${SECRETS_DIR} ]; then + mkdir -p ${SECRETS_DIR} + echo "password" > ${SECRETS_DIR}/admin_password + echo "admin" > ${SECRETS_DIR}/admin_user + echo "key" > ${SECRETS_DIR}/secret_key + +fi + +if [[ $(${DOCKER} ps -f "name=grafana-opendev_test" --format '{{.Names}}') \ + != 'grafana-opendev_test' ]]; then + + echo "Running Grafana" + + ${DOCKER} run -d --rm \ + --name grafana-opendev_test \ + -p 3000:3000 \ + -v ${SECRETS_DIR}:/etc/grafana/secrets \ + -e GF_AUTH_ANONYMOUS_ENABLED=true \ + -e GF_USER_ALLOW_SIGN_UP=false \ + -e GF_SECURITY_ADMIN_PASSWORD__FILE=/etc/grafana/secrets/admin_password \ + -e GF_SECURITY_ADMIN_USER__FILE=/etc/grafana/secrets/admin_user \ + -e GF_SECURITY_SECRET_KEY__FILE=/etc/grafana/secrets/secret_key \ + docker.io/grafana/grafana-oss + + echo "Grafana listening on :3000" +fi + +echo "Reloading dashboards" + +${DOCKER} run --rm -t --network=host \ + -e 'GRAFANA_URL=http://admin:password@localhost:3000' \ + -v ${GRAFYAML_DIR}:/grafana:ro \ + opendevorg/grafyaml