Skip to content
This repository has been archived by the owner on Sep 7, 2018. It is now read-only.

Commit

Permalink
First stab at a new docker image for Grafana.
Browse files Browse the repository at this point in the history
- chown removed
- based on tar.gz instead of deb pkg
- volumes for logs and config removed
- gosu removed

Related to #141
  • Loading branch information
xlson committed Mar 20, 2018
1 parent 04caf1b commit f99b597
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
28 changes: 17 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
FROM debian:jessie

ARG DOWNLOAD_URL="https://s3-us-west-2.amazonaws.com/grafana-releases/master/grafana_latest_amd64.deb"
ARG GRAFANA_VERSION="latest"
ARG GF_HOME="/usr/share/grafana"

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 && \
RUN apt-get update && apt-get install -qq -y wget tar sqlite libfontconfig curl ca-certificates && \
wget -O /tmp/grafana.tar.gz https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-$GRAFANA_VERSION.linux-x64.tar.gz && \
tar -zxvf /tmp/grafana.tar.gz -C /tmp && rm /tmp/grafana.tar.gz && \
mv /tmp/grafana-* $GF_HOME && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*

RUN mkdir -p /etc/grafana/provisioning/datasources && \
mkdir -p /etc/grafana/provisioning/dashboards && \
mkdir -p /var/lib/grafana/plugins && \
mkdir -p /var/log/grafana && \
cp $GF_HOME/conf/sample.ini /etc/grafana/grafana.ini && \
cp $GF_HOME/conf/ldap.toml /etc/grafana/ldap.toml && \
cp $GF_HOME/bin/grafana-server /usr/sbin/grafana-server && \
cp $GF_HOME/bin/grafana-cli /usr/sbin/grafana-cli

VOLUME ["/var/lib/grafana", "/var/log/grafana", "/etc/grafana"]
VOLUME ["/var/lib/grafana"]

EXPOSE 3000

COPY ./run.sh /run.sh

ENTRYPOINT ["/run.sh"]
ENTRYPOINT [ "/run.sh" ]
8 changes: 3 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/bin/bash

_grafana_tag=$1
_grafana_version=${_grafana_tag:1}
_grafana_version=$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 \
--build-arg GRAFANA_VERSION=${_grafana_version} \
--tag "grafana/grafana:${_grafana_version}" \
--no-cache=true .
docker tag grafana/grafana:${_grafana_version} grafana/grafana:latest
Expand All @@ -16,5 +14,5 @@ else
echo "Building latest for master"
docker build \
--tag "grafana/grafana:master" \
--no-cache=true .
.
fi
22 changes: 10 additions & 12 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,39 @@
: "${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
mkdir -p /usr/share/grafana/.aws/
> /usr/share/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
echo "[${profile}]" >> /usr/share/grafana/.aws/credentials
echo "aws_access_key_id = ${!access_key_varname}" >> /usr/share/grafana/.aws/credentials
echo "aws_secret_access_key = ${!secret_key_varname}" >> /usr/share/grafana/.aws/credentials
if [ ! -z "${!region_varname}" ]; then
echo "region = ${!region_varname}" >> ~grafana/.aws/credentials
echo "region = ${!region_varname}" >> /usr/share/grafana/.aws/credentials
fi
fi
done

chown grafana:grafana -R ~grafana/.aws
chmod 600 ~grafana/.aws/credentials
# 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}
grafana-cli --pluginsDir "${GF_PATHS_PLUGINS}" plugins install ${plugin}
done
fi

exec gosu grafana /usr/sbin/grafana-server \
exec /usr/sbin/grafana-server \
--homepath=/usr/share/grafana \
--config="$GF_PATHS_CONFIG" \
cfg:default.log.mode="console" \
Expand Down

0 comments on commit f99b597

Please sign in to comment.