project-config/grafana/run-grafana.sh
Ian Wienand 081f477991 grafana: pull grafyaml in helper script
Make sure before running the grafana image is pulled so we get any
updates before trying to load the dashboards.

Change-Id: I01d1a2874cc96926ff60746af617e75c19f99b1b
2022-08-04 13:58:52 +10:00

50 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
DOCKER=docker
SCRIPT_PATH=$(readlink -f $0)
GRAFYAML_DIR=$(dirname $SCRIPT_PATH)
SECRETS_DIR=${GRAFYAML_DIR}/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"
echo -n "Waiting for startup ."
until $(curl --output /dev/null --silent --head --fail http://localhost:3000); do
echo -n '.'
sleep 2
done
echo ". done"
fi
echo "Pulling grafyaml"
${DOCKER} pull opendevorg/grafyaml
echo "Reloading dashboards"
${DOCKER} run --rm --network=host \
-e 'GRAFANA_URL=http://admin:password@localhost:3000' \
-v ${GRAFYAML_DIR}:/grafana:ro \
opendevorg/grafyaml