diff --git a/grafana/Dockerfile b/grafana/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..c58f05743a105a1d0819f908ce68683234c83899 --- /dev/null +++ b/grafana/Dockerfile @@ -0,0 +1,44 @@ +FROM ubuntu:18.04 +MAINTAINER xt + +COPY sources.list /etc/apt/sources.list + +ARG GRAFANA_URL="https://dl.grafana.com/oss/release/grafana-6.7.2.linux-amd64.tar.gz" +ARG GF_UID="472" +ARG GF_GID="472" + +ENV PATH=/usr/share/grafana/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ + GF_PATHS_CONFIG="/etc/grafana/grafana.ini" \ + GF_PATHS_DATA="/var/lib/grafana" \ + GF_PATHS_HOME="/usr/share/grafana" \ + GF_PATHS_LOGS="/var/log/grafana" \ + GF_PATHS_PLUGINS="/var/lib/grafana/plugins" \ + GF_PATHS_PROVISIONING="/etc/grafana/provisioning" + +ADD grafana.tar.gz /usr/share/ + +#RUN apt-get update && apt-get install -qq -y tar libfontconfig curl ca-certificates && \ +# mkdir -p "$GF_PATHS_HOME/.aws" && \ + #curl "$GRAFANA_URL" | tar xfvz - --strip-components=1 -C "$GF_PATHS_HOME" && \ +# apt-get autoremove -y && \ +# rm -rf /var/lib/apt/lists/* && \ +RUN mkdir -p "$GF_PATHS_HOME/.aws" && \ + groupadd -r -g $GF_GID grafana && \ + useradd -r -u $GF_UID -g grafana grafana && \ + mkdir -p "$GF_PATHS_PROVISIONING/datasources" \ + "$GF_PATHS_PROVISIONING/dashboards" \ + "$GF_PATHS_LOGS" \ + "$GF_PATHS_PLUGINS" \ + "$GF_PATHS_DATA" && \ + cp "$GF_PATHS_HOME/conf/sample.ini" "$GF_PATHS_CONFIG" && \ + cp "$GF_PATHS_HOME/conf/ldap.toml" /etc/grafana/ldap.toml && \ + chown -R grafana:grafana "$GF_PATHS_DATA" "$GF_PATHS_HOME/.aws" "$GF_PATHS_LOGS" "$GF_PATHS_PLUGINS" && \ + chmod 777 "$GF_PATHS_DATA" "$GF_PATHS_HOME/.aws" "$GF_PATHS_LOGS" "$GF_PATHS_PLUGINS" + +EXPOSE 3000 + +COPY ./run.sh /run.sh + +USER grafana +WORKDIR / +ENTRYPOINT [ "/run.sh" ] diff --git a/grafana/LICENSE b/grafana/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..2699d589e8ebbbcc66b8612152583dba025b1f7f --- /dev/null +++ b/grafana/LICENSE @@ -0,0 +1,14 @@ +Copyright 2014-2016 Torkel Ödegaard, Raintank Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); you +may not use this file except in compliance with the License. You may +obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied. See the License for the specific language governing +permissions and limitations under the License. + diff --git a/grafana/README.md b/grafana/README.md new file mode 100644 index 0000000000000000000000000000000000000000..02c06bdc1ea16969092305b3df7b8601a8eed4cb --- /dev/null +++ b/grafana/README.md @@ -0,0 +1,11 @@ +# The Grafana Docker image has moved + +The build for the Grafana docker image has been moved into the main repository. This was done to simplify the build process and to tie a specific version of the docker image to a specific version of Grafana. + +This means: +- the open PR's and issues were closed and re-created in the main [repo](https://github.com/grafana/grafana) + - [docker issue](https://github.com/grafana/grafana/issues?q=is%3Aopen+is%3Aissue+label%3A%22comp%3A+docker%22) +- any new issues should be created [here](https://github.com/grafana/grafana/issues) +- the build lives [here](https://github.com/grafana/grafana/tree/master/packaging/docker), under `packaging/docker` + +We'd like to thank everyone who has helped out in creating our Docker image and look forward to keep working with you in its new home. diff --git a/grafana/build.sh b/grafana/build.sh new file mode 100755 index 0000000000000000000000000000000000000000..579d65eebb3a03002aa101860e93df5d0bdb7a0a --- /dev/null +++ b/grafana/build.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +_grafana_tag=$1 + +# If the tag starts with v, treat this as a official release +if echo "$_grafana_tag" | grep -q "^v"; then + _grafana_version=$(echo "${_grafana_tag}" | cut -d "v" -f 2) + _grafana_url="https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-${_grafana_version}.linux-amd64.tar.gz" + _docker_repo=${2:-grafana/grafana} +else + _grafana_version=$_grafana_tag + _grafana_url="https://s3-us-west-2.amazonaws.com/grafana-releases/master/grafana-${_grafana_version}.linux-x64.tar.gz" + _docker_repo=${2:-grafana/grafana-dev} +fi + +echo "Building ${_docker_repo}:${_grafana_version} from ${_grafana_url}" + +docker build \ + --build-arg GRAFANA_URL="${_grafana_url}" \ + --tag "${_docker_repo}:${_grafana_version}" \ + --no-cache=true . + +# Tag as 'latest' for official release; otherwise tag as grafana/grafana:master +if echo "$_grafana_tag" | grep -q "^v"; then + docker tag "${_docker_repo}:${_grafana_version}" "${_docker_repo}:latest" +else + docker tag "${_docker_repo}:${_grafana_version}" "grafana/grafana:master" +fi diff --git a/grafana/custom/Dockerfile b/grafana/custom/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..79eba5f29e9dcd3d2dfa1663df2596f587ce1ca3 --- /dev/null +++ b/grafana/custom/Dockerfile @@ -0,0 +1,16 @@ +ARG GRAFANA_VERSION="latest" + +FROM grafana/grafana:${GRAFANA_VERSION} + +USER grafana + +ARG GF_INSTALL_PLUGINS="" + +RUN if [ ! -z "${GF_INSTALL_PLUGINS}" ]; then \ + OLDIFS=$IFS; \ + IFS=','; \ + for plugin in ${GF_INSTALL_PLUGINS}; do \ + IFS=$OLDIFS; \ + grafana-cli --pluginsDir "$GF_PATHS_PLUGINS" plugins install ${plugin}; \ + done; \ +fi diff --git a/grafana/deploy_to_k8s.sh b/grafana/deploy_to_k8s.sh new file mode 100755 index 0000000000000000000000000000000000000000..26cf88ef68865757bb4480a1b05e1d6e424e37d3 --- /dev/null +++ b/grafana/deploy_to_k8s.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +curl -s --header "Content-Type: application/json" \ + --data "{\"build_parameters\": {\"CIRCLE_JOB\": \"deploy\", \"IMAGE_NAMES\": \"$1\"}}" \ + --request POST \ + https://circleci.com/api/v1.1/project/github/raintank/deployment_tools/tree/master?circle-token=$CIRCLE_TOKEN diff --git a/grafana/grafana.tar.gz b/grafana/grafana.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..2ac26340f4fb6746249784b86efb6d547298df66 Binary files /dev/null and b/grafana/grafana.tar.gz differ diff --git a/grafana/push_to_docker_hub.sh b/grafana/push_to_docker_hub.sh new file mode 100755 index 0000000000000000000000000000000000000000..e779b04d68d0d48ad40b25670498bf1f0ffac7b4 --- /dev/null +++ b/grafana/push_to_docker_hub.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +_grafana_tag=$1 + +# If the tag starts with v, treat this as a official release +if echo "$_grafana_tag" | grep -q "^v"; then + _grafana_version=$(echo "${_grafana_tag}" | cut -d "v" -f 2) + _docker_repo=${2:-grafana/grafana} +else + _grafana_version=$_grafana_tag + _docker_repo=${2:-grafana/grafana-dev} +fi + +echo "pushing ${_docker_repo}:${_grafana_version}" +docker push "${_docker_repo}:${_grafana_version}" + +if echo "$_grafana_tag" | grep -q "^v"; then + echo "pushing ${_docker_repo}:latest" + docker push "${_docker_repo}:latest" +else + echo "pushing grafana/grafana:master" + docker push grafana/grafana:master +fi diff --git a/grafana/run.sh b/grafana/run.sh new file mode 100755 index 0000000000000000000000000000000000000000..2d2318a9210f2c546476b0233e619c498a4779ae --- /dev/null +++ b/grafana/run.sh @@ -0,0 +1,82 @@ +#!/bin/bash -e + +PERMISSIONS_OK=0 + +if [ ! -r "$GF_PATHS_CONFIG" ]; then + echo "GF_PATHS_CONFIG='$GF_PATHS_CONFIG' is not readable." + PERMISSIONS_OK=1 +fi + +if [ ! -w "$GF_PATHS_DATA" ]; then + echo "GF_PATHS_DATA='$GF_PATHS_DATA' is not writable." + PERMISSIONS_OK=1 +fi + +if [ ! -r "$GF_PATHS_HOME" ]; then + echo "GF_PATHS_HOME='$GF_PATHS_HOME' is not readable." + PERMISSIONS_OK=1 +fi + +if [ $PERMISSIONS_OK -eq 1 ]; then + echo "You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migration-from-a-previous-version-of-the-docker-container-to-5-1-or-later" +fi + +if [ ! -d "$GF_PATHS_PLUGINS" ]; then + mkdir "$GF_PATHS_PLUGINS" +fi + +if [ ! -z ${GF_AWS_PROFILES+x} ]; then + > "$GF_PATHS_HOME/.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}]" >> "$GF_PATHS_HOME/.aws/credentials" + echo "aws_access_key_id = ${!access_key_varname}" >> "$GF_PATHS_HOME/.aws/credentials" + echo "aws_secret_access_key = ${!secret_key_varname}" >> "$GF_PATHS_HOME/.aws/credentials" + if [ ! -z "${!region_varname}" ]; then + echo "region = ${!region_varname}" >> "$GF_PATHS_HOME/.aws/credentials" + fi + fi + done + + chmod 600 "$GF_PATHS_HOME/.aws/credentials" +fi + +# Convert all environment variables with names ending in __FILE into the content of +# the file that they point at and use the name without the trailing __FILE. +# This can be used to carry in Docker secrets. +for VAR_NAME in $(env | grep '^GF_[^=]\+__FILE=.\+' | sed -r "s/([^=]*)__FILE=.*/\1/g"); do + VAR_NAME_FILE="$VAR_NAME"__FILE + if [ "${!VAR_NAME}" ]; then + echo >&2 "ERROR: Both $VAR_NAME and $VAR_NAME_FILE are set (but are exclusive)" + exit 1 + fi + echo "Getting secret $VAR_NAME from ${!VAR_NAME_FILE}" + export "$VAR_NAME"="$(< "${!VAR_NAME_FILE}")" + unset "$VAR_NAME_FILE" +done + +export HOME="$GF_PATHS_HOME" + +if [ ! -z "${GF_INSTALL_PLUGINS}" ]; then + OLDIFS=$IFS + IFS=',' + for plugin in ${GF_INSTALL_PLUGINS}; do + IFS=$OLDIFS + grafana-cli --pluginsDir "${GF_PATHS_PLUGINS}" plugins install ${plugin} + done +fi + +exec grafana-server \ + --homepath="$GF_PATHS_HOME" \ + --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" diff --git a/grafana/sources.list b/grafana/sources.list new file mode 100644 index 0000000000000000000000000000000000000000..82bd9625c805eae98764c57e76f03a3bb323a390 --- /dev/null +++ b/grafana/sources.list @@ -0,0 +1,19 @@ +# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ bionic main restricted +deb-src http://archive.ubuntu.com/ubuntu bionic main restricted #Added by software-properties +deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted +deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted multiverse universe #Added by software-properties +deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted +deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted multiverse universe #Added by software-properties +deb http://mirrors.aliyun.com/ubuntu/ bionic universe +deb http://mirrors.aliyun.com/ubuntu/ bionic-updates universe +deb http://mirrors.aliyun.com/ubuntu/ bionic multiverse +deb http://mirrors.aliyun.com/ubuntu/ bionic-updates multiverse +deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse +deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse #Added by software-properties +deb http://archive.canonical.com/ubuntu bionic partner +deb-src http://archive.canonical.com/ubuntu bionic partner +deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted +deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted multiverse universe #Added by software-properties +deb http://mirrors.aliyun.com/ubuntu/ bionic-security universe +deb http://mirrors.aliyun.com/ubuntu/ bionic-security multiverse + diff --git a/grafana/start_container.sh b/grafana/start_container.sh new file mode 100755 index 0000000000000000000000000000000000000000..7d410c25cd492df595f1d046706da55bcdd0f9fc --- /dev/null +++ b/grafana/start_container.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +docker run -i -p 3001:3000 \ + -v /home/torkel/dev/grafana-docker/data:/var/lib/grafana \ + -e "GF_SERVER_ROOT_URL=http://grafana.server.name" \ + -e "GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-piechart-panel,grafana-simple-json-datasource 1.2.3" \ + grafana/grafana:latest