From 3da653faf16609cef5fd331f4e9b22eed835ca05 Mon Sep 17 00:00:00 2001 From: Doug Szumski Date: Thu, 18 Oct 2018 12:45:36 +0000 Subject: [PATCH] Add Monasca Grafana image This provides support for building the Monasca fork of Grafana which features Keystone integration. It is primarily for use with the Monasca Grafana datasource, although other datasources can be installed if required. In the future it would be more efficient to build and host the packages externally. Implements: blueprint monasca-grafana Change-Id: I6cb175868d1993ae31700de36b721f4833c4164b --- docker/monasca/monasca-grafana/Dockerfile.j2 | 81 +++++++++++++++++++ .../monasca/monasca-grafana/extend_start.sh | 8 ++ .../monasca/monasca-grafana/grafana_sudoers | 1 + .../add-monasca-grafana-868f1dd95725a030.yaml | 6 ++ 4 files changed, 96 insertions(+) create mode 100644 docker/monasca/monasca-grafana/Dockerfile.j2 create mode 100644 docker/monasca/monasca-grafana/extend_start.sh create mode 100644 docker/monasca/monasca-grafana/grafana_sudoers create mode 100644 releasenotes/notes/add-monasca-grafana-868f1dd95725a030.yaml diff --git a/docker/monasca/monasca-grafana/Dockerfile.j2 b/docker/monasca/monasca-grafana/Dockerfile.j2 new file mode 100644 index 0000000000..df8bb8c35f --- /dev/null +++ b/docker/monasca/monasca-grafana/Dockerfile.j2 @@ -0,0 +1,81 @@ +FROM {{ namespace }}/{{ image_prefix }}base:{{ tag }} +LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build_date }}" + +{% block monasca_grafana_header %}{% endblock %} + +{% import "macros.j2" as macros with context %} + +{{ macros.configure_user(name='monasca', homedir='/usr/share/grafana') }} + +{% if base_distro in ['centos', 'oraclelinux', 'rhel'] %} + {% set monasca_grafana_build_packages = [ + 'golang', + 'git', + 'npm', + 'bzip2', + 'gcc-c++', + 'make', + 'ruby', + 'ruby-devel', + 'fontconfig', + 'rpm-build' + ] %} +{% elif base_distro in ['debian', 'ubuntu'] %} + {% set monasca_grafana_build_packages = [ + 'golang', + 'git', + 'npm', + 'bzip2', + 'g++', + 'make', + 'ruby', + 'ruby-dev', + 'fontconfig', + 'rpm' + ] %} +{% endif %} + +{{ macros.install_packages(monasca_grafana_build_packages | customizable("packages")) }} + +WORKDIR /usr/share/grafana + +COPY grafana_sudoers /etc/sudoers.d/kolla_grafana_sudoers +COPY extend_start.sh /usr/local/bin/kolla_extend_start + +ENV GO_PATH=/grafana +ENV monasca_grafana_build_path=${GO_PATH}/src/github.com/grafana/grafana +ARG monasca_grafana_version=grafana4 +ARG monasca_grafana_url=https://github.com/monasca/grafana/archive/$monasca_grafana_version.tar.gz + +{% block monasca_grafana_install %} +RUN gem install fpm \ + && curl -sSL -o /tmp/monasca-grafana.tgz ${monasca_grafana_url} \ + && mkdir -p ${monasca_grafana_build_path} \ + && tar --strip 1 -xvf /tmp/monasca-grafana.tgz -C ${monasca_grafana_build_path} \ + && rm -f /tmp/monasca-grafana.tgz \ + && cd ${monasca_grafana_build_path} \ + && go run build.go setup \ + && npm install \ + && go run build.go build package \ + && mv ${monasca_grafana_build_path}/dist /grafana_pkgs \ + && rm -rf /grafana + +{% if base_distro in ['centos', 'oraclelinux', 'rhel'] %} + {% set monasca_grafana_packages = ['/grafana_pkgs/grafana*.rpm'] %} +{% elif base_distro in ['debian', 'ubuntu'] %} + {% set monasca_grafana_packages = ['/grafana_pkgs/grafana*.deb'] %} +{% endif %} + +{{ macros.install_packages(monasca_grafana_packages | customizable("packages")) }} + +{% endblock %} + +RUN grafana-cli plugins install monasca-datasource \ + && chmod 750 /etc/sudoers.d \ + && chmod 440 /etc/sudoers.d/kolla_grafana_sudoers \ + && chmod 755 /usr/local/bin/kolla_extend_start + +{% block monasca_grafana_footer %}{% endblock %} +{% block footer %}{% endblock %} + +USER monasca diff --git a/docker/monasca/monasca-grafana/extend_start.sh b/docker/monasca/monasca-grafana/extend_start.sh new file mode 100644 index 0000000000..1f6f8ef600 --- /dev/null +++ b/docker/monasca/monasca-grafana/extend_start.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [[ ! -d "/var/log/kolla/monasca" ]]; then + mkdir -p /var/log/kolla/monasca +fi +if [[ $(stat -c %a /var/log/kolla/monasca) != "755" ]]; then + chmod 755 /var/log/kolla/monasca +fi diff --git a/docker/monasca/monasca-grafana/grafana_sudoers b/docker/monasca/monasca-grafana/grafana_sudoers new file mode 100644 index 0000000000..a8f01423bf --- /dev/null +++ b/docker/monasca/monasca-grafana/grafana_sudoers @@ -0,0 +1 @@ +%kolla ALL=(root) NOPASSWD: /usr/bin/chown -R monasca\: /var/lib/grafana/, /bin/chown -R monasca\: /var/lib/grafana/ diff --git a/releasenotes/notes/add-monasca-grafana-868f1dd95725a030.yaml b/releasenotes/notes/add-monasca-grafana-868f1dd95725a030.yaml new file mode 100644 index 0000000000..1ec5d68330 --- /dev/null +++ b/releasenotes/notes/add-monasca-grafana-868f1dd95725a030.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Add the Monasca fork of Grafana (v4.0.1). The Monasca fork of Grafana + adds Keystone integration, allowing Grafana users to log in with their + OpenStack credentials and see Metrics from their OpenStack project.