From c4bb9d637ea2a4cd16d90b64cf6cea88539edd6b Mon Sep 17 00:00:00 2001 From: Dan Cech Date: Thu, 1 Dec 2022 11:08:31 -0500 Subject: [PATCH] Build: Unify custom dockerfiles, fix missing semicolon (#59615) * unify custom dockerfiles, fix missing semicolon * tweak verbiage Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com> * update example description Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com> --- .../installation/docker/index.md | 25 +++++++--- packaging/docker/custom/Dockerfile | 22 ++++++-- packaging/docker/custom/ubuntu.Dockerfile | 50 ------------------- 3 files changed, 34 insertions(+), 63 deletions(-) delete mode 100644 packaging/docker/custom/ubuntu.Dockerfile diff --git a/docs/sources/setup-grafana/installation/docker/index.md b/docs/sources/setup-grafana/installation/docker/index.md index b8ca45f0975..d685ea47d66 100644 --- a/docs/sources/setup-grafana/installation/docker/index.md +++ b/docs/sources/setup-grafana/installation/docker/index.md @@ -113,7 +113,20 @@ docker run -d \ You can build your own customized image that includes plugins. This saves time if you are creating multiple images and you want them all to have the same plugins installed on build. -In the [Grafana GitHub repository](https://github.com/grafana/grafana) there is a folder called `packaging/docker/custom/`, which includes two Dockerfiles, `Dockerfile` and `ubuntu.Dockerfile`, that can be used to build a custom Grafana image. It accepts `GRAFANA_VERSION`, `GF_INSTALL_PLUGINS`, and `GF_INSTALL_IMAGE_RENDERER_PLUGIN` as build arguments. +In the [Grafana GitHub repository](https://github.com/grafana/grafana) there is a folder called `packaging/docker/custom/`, which includes a Dockerfile that can be used to build a custom Grafana image. It accepts `GRAFANA_VERSION`, `GF_INSTALL_PLUGINS`, and `GF_INSTALL_IMAGE_RENDERER_PLUGIN` as build arguments. + +The `GRAFANA_VERSION` build argument must be a valid `grafana/grafana` docker image tag. By default, this builds an Alpine-based image. To build an Ubuntu-based image, append `-ubuntu` to the `GRAFANA_VERSION` build argument (available in Grafana v6.5 and later). + +The following example shows you how to build and run a custom Grafana Docker image based on the latest official Ubuntu-based Grafana Docker image: + +```bash +cd packaging/docker/custom +docker build \ + --build-arg "GRAFANA_VERSION=latest-ubuntu" \ + -t grafana-custom . + +docker run -d -p 3000:3000 --name=grafana grafana-custom +``` ### Build with pre-installed plugins @@ -126,7 +139,7 @@ cd packaging/docker/custom docker build \ --build-arg "GRAFANA_VERSION=latest" \ --build-arg "GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource" \ - -t grafana-custom -f Dockerfile . + -t grafana-custom . docker run -d -p 3000:3000 --name=grafana grafana-custom ``` @@ -140,13 +153,11 @@ cd packaging/docker/custom docker build \ --build-arg "GRAFANA_VERSION=latest" \ --build-arg "GF_INSTALL_PLUGINS=http://plugin-domain.com/my-custom-plugin.zip;custom-plugin,grafana-clock-panel" \ - -t grafana-custom -f Dockerfile . + -t grafana-custom . docker run -d -p 3000:3000 --name=grafana grafana-custom ``` -Replace `Dockerfile` in above example with `ubuntu.Dockerfile` to build a custom Ubuntu based image (Grafana v6.5+). - ### Build with Grafana Image Renderer plugin pre-installed > Only available in Grafana v6.5 and later. This is experimental. @@ -160,13 +171,11 @@ cd packaging/docker/custom docker build \ --build-arg "GRAFANA_VERSION=latest" \ --build-arg "GF_INSTALL_IMAGE_RENDERER_PLUGIN=true" \ - -t grafana-custom -f Dockerfile . + -t grafana-custom . docker run -d -p 3000:3000 --name=grafana grafana-custom ``` -Replace `Dockerfile` in above example with `ubuntu.Dockerfile` to build a custom Ubuntu-based image (Grafana v6.5+). - ## Migrate from previous Docker containers versions This section contains important information if you want to migrate from previous Grafana container versions to a more current one. diff --git a/packaging/docker/custom/Dockerfile b/packaging/docker/custom/Dockerfile index bc914e680ed..3a4c6aa1bbd 100644 --- a/packaging/docker/custom/Dockerfile +++ b/packaging/docker/custom/Dockerfile @@ -2,23 +2,35 @@ ARG GRAFANA_VERSION="latest" FROM grafana/grafana:${GRAFANA_VERSION} -USER root - ARG GF_INSTALL_IMAGE_RENDERER_PLUGIN="false" ARG GF_GID="0" + ENV GF_PATHS_PLUGINS="/var/lib/grafana-plugins" +ENV GF_PLUGIN_RENDERING_CHROME_BIN="/usr/bin/chrome" + +USER root RUN mkdir -p "$GF_PATHS_PLUGINS" && \ chown -R grafana:${GF_GID} "$GF_PATHS_PLUGINS" && \ if [ $GF_INSTALL_IMAGE_RENDERER_PLUGIN = "true" ]; then \ - apk add --no-cache udev ttf-opensans chromium \ + if grep -i -q alpine /etc/issue; then \ + apk add --no-cache udev ttf-opensans chromium && \ + ln -s /usr/bin/chromium-browser "$GF_PLUGIN_RENDERING_CHROME_BIN"; \ + else \ + cd /tmp && \ + curl -sLO https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \ + DEBIAN_FRONTEND=noninteractive && \ + apt-get update -q && \ + apt-get install -q -y ./google-chrome-stable_current_amd64.deb && \ + rm -rf /var/lib/apt/lists/* && \ + rm ./google-chrome-stable_current_amd64.deb && \ + ln -s /usr/bin/google-chrome "$GF_PLUGIN_RENDERING_CHROME_BIN"; \ + fi \ fi USER grafana -ENV GF_PLUGIN_RENDERING_CHROME_BIN="/usr/bin/chromium-browser" - RUN if [ $GF_INSTALL_IMAGE_RENDERER_PLUGIN = "true" ]; then \ grafana-cli \ --pluginsDir "$GF_PATHS_PLUGINS" \ diff --git a/packaging/docker/custom/ubuntu.Dockerfile b/packaging/docker/custom/ubuntu.Dockerfile deleted file mode 100644 index 6b4c59a107f..00000000000 --- a/packaging/docker/custom/ubuntu.Dockerfile +++ /dev/null @@ -1,50 +0,0 @@ -ARG GRAFANA_VERSION="latest" - -FROM grafana/grafana:${GRAFANA_VERSION}-ubuntu - -USER root - -ARG GF_INSTALL_IMAGE_RENDERER_PLUGIN="false" - -ARG GF_GID="0" -ENV GF_PATHS_PLUGINS="/var/lib/grafana-plugins" - -RUN mkdir -p "$GF_PATHS_PLUGINS" && \ - chown -R grafana:${GF_GID} "$GF_PATHS_PLUGINS" && \ - if [ $GF_INSTALL_IMAGE_RENDERER_PLUGIN = "true" ]; then \ - cd /tmp && \ - curl -LO https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \ - DEBIAN_FRONTEND=noninteractive && \ - apt-get update && \ - apt-get install -y ./google-chrome-stable_current_amd64.deb && \ - rm -rf /var/lib/apt/lists/* && \ - rm ./google-chrome-stable_current_amd64.deb \ - fi - -USER grafana - -ENV GF_PLUGIN_RENDERING_CHROME_BIN="/usr/bin/google-chrome" - -RUN if [ $GF_INSTALL_IMAGE_RENDERER_PLUGIN = "true" ]; then \ - grafana-cli \ - --pluginsDir "$GF_PATHS_PLUGINS" \ - --pluginUrl https://github.com/grafana/grafana-image-renderer/releases/latest/download/plugin-linux-x64-glibc-no-chromium.zip \ - plugins install grafana-image-renderer; \ - fi - -ARG GF_INSTALL_PLUGINS="" - -RUN if [ ! -z "${GF_INSTALL_PLUGINS}" ]; then \ - OLDIFS=$IFS; \ - IFS=','; \ - for plugin in ${GF_INSTALL_PLUGINS}; do \ - IFS=$OLDIFS; \ - if expr match "$plugin" '.*\;.*'; then \ - pluginUrl=$(echo "$plugin" | cut -d';' -f 1); \ - pluginInstallFolder=$(echo "$plugin" | cut -d';' -f 2); \ - grafana-cli --pluginUrl ${pluginUrl} --pluginsDir "${GF_PATHS_PLUGINS}" plugins install "${pluginInstallFolder}"; \ - else \ - grafana-cli --pluginsDir "${GF_PATHS_PLUGINS}" plugins install ${plugin}; \ - fi \ - done \ - fi