diff --git a/Dockerfile b/Dockerfile index 660d199f..8b996986 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" ] \ No newline at end of file diff --git a/build.sh b/build.sh index ea29f4da..c8257469 100755 --- a/build.sh +++ b/build.sh @@ -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 @@ -16,5 +14,5 @@ else echo "Building latest for master" docker build \ --tag "grafana/grafana:master" \ - --no-cache=true . + . fi diff --git a/run.sh b/run.sh index 42f60322..ea556c24 100755 --- a/run.sh +++ b/run.sh @@ -6,11 +6,9 @@ : "${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" @@ -18,17 +16,17 @@ if [ ! -z ${GF_AWS_PROFILES+x} ]; then 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 @@ -36,11 +34,11 @@ if [ ! -z "${GF_INSTALL_PLUGINS}" ]; then 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" \