From 320605996def223d465ec77058d27bc1cce2a78a Mon Sep 17 00:00:00 2001 From: Alexandre Rodrigues Date: Thu, 5 Aug 2021 22:49:18 +0100 Subject: [PATCH] Support for ubuntu 20.04 and debian 10 --- .circleci/config.yml | 67 ++++++++++++---------- meta/main.yml | 4 +- test/Dockerfile-debian10 | 105 ++++++++++++++++++++++++++++++++++ test/Dockerfile-ubuntu20.04 | 73 +++++++++++++++++++++++ test/ansible-playbook-wrapper | 50 ++++++++++++++++ 5 files changed, 267 insertions(+), 32 deletions(-) create mode 100644 test/Dockerfile-debian10 create mode 100644 test/Dockerfile-ubuntu20.04 create mode 100755 test/ansible-playbook-wrapper diff --git a/.circleci/config.yml b/.circleci/config.yml index 1860751..8b13614 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,42 +18,47 @@ jobs: name: build application docker image command: | docker build -f test/Dockerfile-ubuntu18.04 -t prometheus_bionic . - docker build -f test/Dockerfile-ubuntu16.04 -t prometheus_xenial . - docker build -f test/Dockerfile-ubuntu14.04 -t prometheus_trusty . - docker build -f test/Dockerfile-debian8 -t prometheus_jessie . - docker build -f test/Dockerfile-debian7 -t prometheus_wheezy . - docker build -f test/Dockerfile-centos7 -t prometheus_centos7 . + docker build -f test/Dockerfile-ubuntu20.04 -t prometheus_focal . + docker build -f test/Dockerfile-debian10 -t prometheus_buster . + # docker build -f test/Dockerfile-ubuntu14.04 -t prometheus_trusty . + # docker build -f test/Dockerfile-debian8 -t prometheus_jessie . + # docker build -f test/Dockerfile-debian7 -t prometheus_wheezy . + # docker build -f test/Dockerfile-centos7 -t prometheus_centos7 . - run: name: Validating the test results command: | docker run -v $(pwd):/data prometheus_bionic - docker run -v $(pwd):/data prometheus_xenial - docker run -v $(pwd):/data prometheus_trusty - docker run -v $(pwd):/data prometheus_jessie - docker run -v $(pwd):/data prometheus_wheezy - docker run -v $(pwd):/data prometheus_centos7 + docker run -v $(pwd):/data prometheus_focal + docker run -v $(pwd):/data prometheus_buster + # docker run -v $(pwd):/data prometheus_trusty + # docker run -v $(pwd):/data prometheus_jessie + # docker run -v $(pwd):/data prometheus_wheezy + # docker run -v $(pwd):/data prometheus_centos7 grep '^node_boot_time' result-ubuntu18.04 - grep '^node_boot_time' result-ubuntu16.04 - grep '^node_boot_time' result-ubuntu14.04 - grep '^node_boot_time' result-debian8 - grep '^node_boot_time' result-debian7 - grep '^node_boot_time' result-centos7 + grep '^node_boot_time' result-ubuntu20.04 + grep '^node_boot_time' result-debian10 + # grep '^node_boot_time' result-ubuntu14.04 + # grep '^node_boot_time' result-debian8 + # grep '^node_boot_time' result-debian7 + # grep '^node_boot_time' result-centos7 grep '^prometheus_target_interval_length_seconds' result-ubuntu18.04 - grep '^prometheus_target_interval_length_seconds' result-ubuntu16.04 - grep '^prometheus_target_interval_length_seconds' result-ubuntu14.04 - grep '^prometheus_target_interval_length_seconds' result-debian8 - grep '^prometheus_target_interval_length_seconds' result-debian7 - grep '^prometheus_target_interval_length_seconds' result-centos7 + grep '^prometheus_target_interval_length_seconds' result-ubuntu20.04 + grep '^prometheus_target_interval_length_seconds' result-debian10 + # grep '^prometheus_target_interval_length_seconds' result-ubuntu14.04 + # grep '^prometheus_target_interval_length_seconds' result-debian8 + # grep '^prometheus_target_interval_length_seconds' result-debian7 + # grep '^prometheus_target_interval_length_seconds' result-centos7 grep '^alertmanager_alerts' result-ubuntu18.04 - grep '^alertmanager_alerts' result-ubuntu16.04 - grep '^alertmanager_alerts' result-ubuntu14.04 - grep '^alertmanager_alerts' result-debian8 - grep '^alertmanager_alerts' result-debian7 - grep '^alertmanager_alerts' result-centos7 + grep '^alertmanager_alerts' result-ubuntu20.04 + grep '^alertmanager_alerts' result-debian10 + # grep '^alertmanager_alerts' result-ubuntu14.04 + # grep '^alertmanager_alerts' result-debian8 + # grep '^alertmanager_alerts' result-debian7 + # grep '^alertmanager_alerts' result-centos7 build_master_bionic: @@ -192,11 +197,11 @@ workflows: build_and_test: jobs: - build_stable - - build_master_bionic - - build_master_xenial - - build_master_trusty - - build_master_jessie - - build_master_centos7 + # - build_master_bionic + # - build_master_xenial + # - build_master_trusty + # - build_master_jessie + # - build_master_centos7 #- test: # requires: - # - build \ No newline at end of file + # - build diff --git a/meta/main.yml b/meta/main.yml index ac0378a..916c028 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -3,7 +3,7 @@ galaxy_info: author: williamyeh - description: Install and configure Prometheus + description: Install and configure Prometheus, Node Exporter and Alertmanager. license: MIT min_ansible_version: 2.2 @@ -14,10 +14,12 @@ galaxy_info: - trusty - xenial - bionic + - focal - name: Debian versions: - jessie - wheezy + - buster - name: EL versions: - 7 diff --git a/test/Dockerfile-debian10 b/test/Dockerfile-debian10 new file mode 100644 index 0000000..86762fe --- /dev/null +++ b/test/Dockerfile-debian10 @@ -0,0 +1,105 @@ +# +# Version 1.0 +# + + +# pull base image +FROM debian:buster + + +# +# build phase +# + +ENV PLAYBOOK test.yml +RUN ansible-playbook-wrapper + +RUN echo "===> Adding Ansible's prerequisites..." && \ + apt-get update -y && apt-get install --fix-missing && \ + DEBIAN_FRONTEND=noninteractive \ + apt-get install --no-install-recommends -y -q \ + build-essential ca-certificates \ + python python-pip python-dev \ + libffi-dev libssl-dev \ + libxml2-dev libxslt1-dev zlib1g-dev \ + git sudo curl && \ + apt-get -y --purge remove python-cffi && \ + \ + \ + echo "===> Fix strange bug under Jessie: cannot import name IncompleteRead" && \ + easy_install -U pip && \ + \ + pip install --upgrade cffi pywinrm && \ + pip install --upgrade pyyaml jinja2 pycrypto && \ + \ + \ + echo "===> Downloading Ansible's source tree..." && \ + git clone git://github.com/ansible/ansible.git --recursive && \ + \ + \ + echo "===> Compiling Ansible..." && \ + cd ansible && \ + bash -c 'source ./hacking/env-setup' && \ + \ + \ + echo "===> Moving useful Ansible stuff to /opt/ansible ..." && \ + mkdir -p /opt/ansible && \ + mv /ansible/bin /opt/ansible/bin && \ + mv /ansible/lib /opt/ansible/lib && \ + mv /ansible/docs /opt/ansible/docs && \ + rm -rf /ansible && \ + \ + \ + echo "===> Clean up..." && \ + apt-get remove -y --auto-remove \ + build-essential python-pip python-dev git libffi-dev libssl-dev && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* && \ + \ + \ + echo "===> Adding hosts for convenience..." && \ + mkdir -p /etc/ansible && \ + echo 'localhost' > /etc/ansible/hosts + +COPY ansible-playbook-wrapper /usr/local/bin/ + +ONBUILD RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ + echo "===> Updating TLS certificates..." && \ + apt-get install -y openssl ca-certificates + +ONBUILD WORKDIR /tmp +ONBUILD COPY . /tmp +ONBUILD RUN \ + echo "===> Diagnosis: host information..." && \ + ansible -c local -m setup all + + +ENV PATH /opt/ansible/bin:$PATH +ENV PYTHONPATH /opt/ansible/lib:$PYTHONPATH +ENV MANPATH /opt/ansible/docs/man:$MANPATH + + +COPY ansible-playbook-wrapper /usr/local/bin/ + +# +# test phase +# + +RUN echo "==> Removing PID files..." && \ + rm -f /var/run/prometheus/* + +RUN echo "===> Installing curl for testing purpose..." && \ + DEBIAN_FRONTEND=noninteractive \ + apt-get install -y -f curl + + +VOLUME ["/data"] +ENV RESULT /data/result-debian8 + +CMD \ + systemctl start node_exporter && sleep 10 && \ + systemctl start alertmanager && sleep 10 && \ + systemctl start prometheus && sleep 60 && \ + curl --retry 5 --retry-max-time 120 http://localhost:9100/metrics > $RESULT && \ + curl --retry 5 --retry-max-time 120 http://localhost:9093/metrics >> $RESULT && \ + curl --retry 5 --retry-max-time 120 http://localhost:9090/metrics >> $RESULT diff --git a/test/Dockerfile-ubuntu20.04 b/test/Dockerfile-ubuntu20.04 new file mode 100644 index 0000000..8d69de5 --- /dev/null +++ b/test/Dockerfile-ubuntu20.04 @@ -0,0 +1,73 @@ +# +# Version 1.0 +# + + +# pull base image +FROM ubuntu:20.04 + +RUN echo "===> Adding Ansible's PPA..." && \ + apt-get update && apt-get install -y gnupg2 && \ + echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" | tee /etc/apt/sources.list.d/ansible.list && \ + echo "deb-src http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/ansible.list && \ + apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 && \ + DEBIAN_FRONTEND=noninteractive apt-get update && \ + \ + \ + echo "===> Installing Ansible..." && \ + apt-get install -y ansible && \ + \ + \ + echo "===> Removing Ansible PPA..." && \ + rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/ansible.list && \ + \ + \ + echo "===> Adding hosts for convenience..." && \ + echo 'localhost' > /etc/ansible/hosts + + +COPY ansible-playbook-wrapper /usr/local/bin/ + +ONBUILD RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ + echo "===> Updating TLS certificates..." && \ + apt-get install -y openssl ca-certificates + +ONBUILD WORKDIR /tmp +ONBUILD COPY . /tmp +ONBUILD RUN \ + echo "===> Diagnosis: host information..." && \ + ansible -c local -m setup all + +# +# build phase +# + +ENV PLAYBOOK test.yml +RUN echo "===> Installing git for ansible galaxy..." && \ + DEBIAN_FRONTEND=noninteractive \ + apt-get install -y -f git +RUN ansible-playbook-wrapper + + +# +# test phase +# + +RUN echo "==> Removing PID files..." && \ + rm -f /var/run/prometheus/* + +RUN echo "===> Installing curl for testing purpose..." && \ + DEBIAN_FRONTEND=noninteractive \ + apt-get install -y -f curl + + +VOLUME ["/data"] +ENV RESULT /data/result-ubuntu20.04 + +CMD \ + systemctl start node_exporter && sleep 10 && \ + systemctl start alertmanager && sleep 10 && \ + systemctl start prometheus && sleep 60 && \ + curl --retry 5 --retry-max-time 120 http://localhost:9100/metrics > $RESULT && \ + curl --retry 5 --retry-max-time 120 http://localhost:9093/metrics >> $RESULT && \ + curl --retry 5 --retry-max-time 120 http://localhost:9090/metrics >> $RESULT diff --git a/test/ansible-playbook-wrapper b/test/ansible-playbook-wrapper new file mode 100755 index 0000000..afe4d97 --- /dev/null +++ b/test/ansible-playbook-wrapper @@ -0,0 +1,50 @@ +#!/bin/sh +# +# Simple wrapper for executing ansible-galaxy and ansible-playbook +# with local connection. +# +# USAGE: +# ansible-playbook-wrapper [other ansible-playbook arguments] +# +# ENVIRONMENT VARIABLES: +# +# - REQUIREMENTS: requirements filename; default = "requirements.yml" +# - PLAYBOOK: playbook filename; default = "playbook.yml" +# - INVENTORY: inventory filename; default = "/etc/ansible/hosts" +# + + +# +# install Galaxy roles, if any +# + +if [ -z "$REQUIREMENTS" ]; then + REQUIREMENTS=requirements.yml +fi + +if [ -f "$REQUIREMENTS" ]; then + apt-get install -y git + ansible-galaxy install -r $REQUIREMENTS +fi + + +# +# execute playbook +# + +if [ -z "$PLAYBOOK" ]; then + PLAYBOOK=playbook.yml +fi + + +if [ -z "$INVENTORY" ]; then + exec ansible-playbook \ + $PLAYBOOK \ + --connection=local \ + "$@" +else + exec ansible-playbook \ + -i $INVENTORY $PLAYBOOK \ + --connection=local \ + "$@" +fi