Browse Source

Add Grafana Dockerfile

master
Charles Reid 7 years ago
parent
commit
38dd541441
  1. 2
      .gitignore
  2. 23
      d-grafana/Dockerfile.grafana
  3. 24
      d-grafana/build_grafana.sh
  4. 13
      d-grafana/run_grafana.sh
  5. 55
      d-grafana/scripts/run.sh

2
.gitignore vendored

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
# Ignore local grafana data directory
d-grafana/grafana-data

23
d-grafana/Dockerfile.grafana

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
FROM debian:jessie
ARG DOWNLOAD_URL
RUN apt-get update && \
apt-get -y --no-install-recommends install libfontconfig curl ca-certificates && \
apt-get clean && \
curl ${DOWNLOAD_URL} > /tmp/grafana.deb && \
dpkg -i /tmp/grafana.deb && \
rm /tmp/grafana.deb && \
curl -L https://github.com/tianon/gosu/releases/download/1.10/gosu-amd64 > /usr/sbin/gosu && \
chmod +x /usr/sbin/gosu && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*
ADD scripts /scripts
RUN chmod +x /scripts/*.sh
VOLUME ["/var/lib/grafana", "/var/log/grafana", "/etc/grafana"]
EXPOSE 3000
ENTRYPOINT ["/scripts/run.sh"]

24
d-grafana/build_grafana.sh

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
#!/bin/bash
#
# This script comes from the grafana-docker repo:
# https://github.com/grafana/grafana-docker
_grafana_tag=$1
_grafana_version=${_grafana_tag:1}
if [ "$_grafana_version" != "" ]; then
echo "Building version ${_grafana_version}"
echo "Download url: https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_${_grafana_version}_amd64.deb"
docker build \
--build-arg DOWNLOAD_URL=https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_${_grafana_version}_amd64.deb \
--tag "grafana/grafana:${_grafana_version}" \
--no-cache=true .
docker tag grafana/grafana:${_grafana_version} grafana/grafana:latest
else
echo "Building latest for master"
docker build \
--build-arg DOWNLOAD_URL=https://s3-us-west-2.amazonaws.com/grafana-releases/master/grafana_latest_amd64.deb \
--tag "grafana/grafana:master" \
--no-cache=true .
fi

13
d-grafana/run_grafana.sh

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
#!/bin/bash
IPADDR="`dig +short myip.opendns.com @resolver1.opendns.com`"
mkdir -p ${PWD}/grafana-data
docker run \
-i \
-p 3001:3000 \
-v ${PWD}/grafana-data:/var/lib/grafana \
-e "GF_SERVER_ROOT_URL=http://${IPADDR}" \
-e "GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-piechart-panel,grafana-simple-json-datasource 1.2.3" \
grafana/grafana:latest

55
d-grafana/scripts/run.sh

@ -0,0 +1,55 @@ @@ -0,0 +1,55 @@
#!/bin/bash -e
#
# This script comes from the grafana-docker repo:
# https://github.com/grafana/grafana-docker
: "${GF_PATHS_CONFIG:=/etc/grafana/grafana.ini}"
: "${GF_PATHS_DATA:=/var/lib/grafana}"
: "${GF_PATHS_LOGS:=/var/log/grafana}"
: "${GF_PATHS_PLUGINS:=/var/lib/grafana/plugins}"
: "${GF_PATHS_PROVISIONING:=/etc/grafana/provisioning}"
chown -R grafana:grafana "$GF_PATHS_DATA" "$GF_PATHS_LOGS"
if [ ! -z ${GF_AWS_PROFILES+x} ]; then
mkdir -p ~grafana/.aws/
> ~grafana/.aws/credentials
for profile in ${GF_AWS_PROFILES}; do
access_key_varname="GF_AWS_${profile}_ACCESS_KEY_ID"
secret_key_varname="GF_AWS_${profile}_SECRET_ACCESS_KEY"
region_varname="GF_AWS_${profile}_REGION"
if [ ! -z "${!access_key_varname}" -a ! -z "${!secret_key_varname}" ]; then
echo "[${profile}]" >> ~grafana/.aws/credentials
echo "aws_access_key_id = ${!access_key_varname}" >> ~grafana/.aws/credentials
echo "aws_secret_access_key = ${!secret_key_varname}" >> ~grafana/.aws/credentials
if [ ! -z "${!region_varname}" ]; then
echo "region = ${!region_varname}" >> ~grafana/.aws/credentials
fi
fi
done
chown grafana:grafana -R ~grafana/.aws
chmod 600 ~grafana/.aws/credentials
fi
if [ ! -z "${GF_INSTALL_PLUGINS}" ]; then
OLDIFS=$IFS
IFS=','
for plugin in ${GF_INSTALL_PLUGINS}; do
IFS=$OLDIFS
gosu grafana grafana-cli --pluginsDir "${GF_PATHS_PLUGINS}" plugins install ${plugin}
done
fi
exec gosu grafana /usr/sbin/grafana-server \
--homepath=/usr/share/grafana \
--config="$GF_PATHS_CONFIG" \
cfg:default.log.mode="console" \
cfg:default.paths.data="$GF_PATHS_DATA" \
cfg:default.paths.logs="$GF_PATHS_LOGS" \
cfg:default.paths.plugins="$GF_PATHS_PLUGINS" \
cfg:default.paths.provisioning=$GF_PATHS_PROVISIONING \
"$@"
Loading…
Cancel
Save