diff --git a/.github/workflows/github-build.yml b/.github/workflows/github-build.yml index 5d5e7c4..a57007c 100644 --- a/.github/workflows/github-build.yml +++ b/.github/workflows/github-build.yml @@ -92,11 +92,22 @@ jobs: --progress plain \ --cache-from "type=local,src=/tmp/.buildx-cache" \ --cache-to "type=local,dest=/tmp/.buildx-cache" \ - --platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 \ + --platform linux/386,linux/amd64,linux/arm64 \ --label "gitCommit=${{ github.sha }}" \ --label "org.opencontainers.image.revision=${{ github.sha }}" \ - --tag ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} \ - --output "type=image,push=false" . + --tag ${GITHUB_ACTOR}/nagios:alpine-3-21-${{ env.action_mytag }} \ + --output "type=image,push=false" -f Dockerfile . + - name: Docker Buildx (build and cache) for linux/arm/v6,linux/arm/v7 (Alpine 3.12) + run: | + docker buildx build \ + --progress plain \ + --cache-from "type=local,src=/tmp/.buildx-cache" \ + --cache-to "type=local,dest=/tmp/.buildx-cache" \ + --platform linux/arm/v6,linux/arm/v7 \ + --label "gitCommit=${{ github.sha }}" \ + --label "org.opencontainers.image.revision=${{ github.sha }}" \ + --tag ${GITHUB_ACTOR}/nagios:alpine-3-12-${{ env.action_mytag }} \ + --output "type=image,push=false" -f alpine3-12.dockerfile . - name: 'Docker Buildx: Push to Dockerhub' run: | echo "== This branch is : ${GITHUB_REF}" @@ -104,23 +115,118 @@ jobs: docker buildx build \ --progress plain \ --cache-from "type=local,src=/tmp/.buildx-cache" \ - --platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 \ + --platform linux/386,linux/amd64,linux/arm64 \ --label "gitCommit=${{ github.sha }}" \ --label "org.opencontainers.image.revision=${{ github.sha }}" \ - --tag ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} \ - --output "type=image,push=true" . - - name: 'Docker Buildx: Push to GitHub Container Registry' + --tag ${GITHUB_ACTOR}/nagios:alpine-3-21-${{ env.action_mytag }} \ + --output "type=image,push=true" -f Dockerfile . + - name: 'Docker Buildx: Push to Dockerhub for linux/arm/v6,linux/arm/v7 (Alpine 3.12)' run: | echo "== This branch is : ${GITHUB_REF}" - echo "Will push image ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} to GitHub Container Registry" + echo "Will push image ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} to DockerHub" docker buildx build \ --progress plain \ --cache-from "type=local,src=/tmp/.buildx-cache" \ - --platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 \ + --platform linux/arm/v6,linux/arm/v7 \ --label "gitCommit=${{ github.sha }}" \ --label "org.opencontainers.image.revision=${{ github.sha }}" \ - --tag ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} \ - --output "type=image,push=true" . + --tag ${GITHUB_ACTOR}/nagios:alpine-3-12-${{ env.action_mytag }} \ + --output "type=image,push=true" -f alpine3-12.dockerfile . + - name: 'Docker Buildx: Push to GitHub Container Registry' + run: | + echo "== This branch is : ${GITHUB_REF}" + echo "Will push image ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} to DockerHub" + docker buildx build \ + --progress plain \ + --cache-from "type=local,src=/tmp/.buildx-cache" \ + --platform linux/386,linux/amd64,linux/arm64 \ + --label "gitCommit=${{ github.sha }}" \ + --label "org.opencontainers.image.revision=${{ github.sha }}" \ + --tag ghcr.io/${GITHUB_ACTOR}/nagios:alpine-3-21-${{ env.action_mytag }} \ + --output "type=image,push=true" -f Dockerfile . + - name: 'Docker Buildx: Push to GitHub Container Registry for linux/arm/v6,linux/arm/v7 (Alpine 3.12)' + run: | + echo "== This branch is : ${GITHUB_REF}" + echo "Will push image ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} to DockerHub" + docker buildx build \ + --progress plain \ + --cache-from "type=local,src=/tmp/.buildx-cache" \ + --platform linux/arm/v6,linux/arm/v7 \ + --label "gitCommit=${{ github.sha }}" \ + --label "org.opencontainers.image.revision=${{ github.sha }}" \ + --tag ghcr.io/${GITHUB_ACTOR}/nagios:alpine-3-12-${{ env.action_mytag }} \ + --output "type=image,push=true" -f alpine3-12.dockerfile . + - name: Download and configure jq + run: | + echo "Download jq" + wget https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-amd64 + echo "Configure jq" + mv jq-linux-amd64 jq + chmod 744 jq + - name: Create a new unified manifest for Dockerhub + run: | + echo "Download manifest of ${GITHUB_ACTOR}/nagios:alpine-3-21-${{ env.action_mytag }}" + docker buildx imagetools inspect ${GITHUB_ACTOR}/nagios:alpine-3-21-${{ env.action_mytag }} --raw > manifest1.json + echo "Download manifest of ${GITHUB_ACTOR}/nagios:alpine-3-12-${{ env.action_mytag }}" + docker buildx imagetools inspect ${GITHUB_ACTOR}/nagios:alpine-3-12-${{ env.action_mytag }} --raw > manifest2.json + ls -l manifest*json + SHA256_AMD64=$(cat manifest1.json | ./jq -r '.manifests[]| select(.platform.architecture == "amd64") | .digest') + SHA256_ARM64=$(cat manifest1.json | ./jq -r '.manifests[]| select(.platform.architecture == "arm64") | .digest') + SHA256_I386=$(cat manifest1.json | ./jq -r '.manifests[]| select(.platform.architecture == "386") | .digest') + SHA256_ARMV6=$(cat manifest2.json | ./jq -r '.manifests[]| select(.platform.architecture == "arm") | select(.platform.variant == "v6") | .digest') + SHA256_ARMV7=$(cat manifest2.json | ./jq -r '.manifests[]| select(.platform.architecture == "arm") | select(.platform.variant == "v7") | .digest') + echo "Creating new manifest: ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }}" + set -eux + docker manifest create --amend ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} \ + "${GITHUB_ACTOR}/nagios@${SHA256_AMD64}" \ + "${GITHUB_ACTOR}/nagios@${SHA256_ARM64}" \ + "${GITHUB_ACTOR}/nagios@${SHA256_I386}" \ + "${GITHUB_ACTOR}/nagios@${SHA256_ARMV6}" \ + "${GITHUB_ACTOR}/nagios@${SHA256_ARMV7}" + echo "Annotating new manifest: ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} with platforms and architectures" + docker manifest annotate ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} "${GITHUB_ACTOR}/nagios@${SHA256_AMD64}" --arch amd64 --os linux + docker manifest annotate ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} "${GITHUB_ACTOR}/nagios@${SHA256_ARM64}" --arch arm64 --os linux + docker manifest annotate ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} "${GITHUB_ACTOR}/nagios@${SHA256_I386}" --arch 386 --os linux + docker manifest annotate ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} "${GITHUB_ACTOR}/nagios@${SHA256_ARMV6}" --arch arm --os linux --variant v6 + docker manifest annotate ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} "${GITHUB_ACTOR}/nagios@${SHA256_ARMV7}" --arch arm --os linux --variant v7 + - name: Create a new unified manifest for GitHub Container Registry + run: | + echo "Download manifest of ghcr.io/${GITHUB_ACTOR}/nagios:alpine-3-21-${{ env.action_mytag }}" + docker buildx imagetools inspect ghcr.io/${GITHUB_ACTOR}/nagios:alpine-3-21-${{ env.action_mytag }} --raw > manifest1.json + echo "Download manifest of ghcr.io/${GITHUB_ACTOR}/nagios:alpine-3-12-${{ env.action_mytag }}" + docker buildx imagetools inspect ghcr.io/${GITHUB_ACTOR}/nagios:alpine-3-12-${{ env.action_mytag }} --raw > manifest2.json + ls -l manifest*json + SHA256_AMD64=$(cat manifest1.json | ./jq -r '.manifests[]| select(.platform.architecture == "amd64") | .digest') + SHA256_ARM64=$(cat manifest1.json | ./jq -r '.manifests[]| select(.platform.architecture == "arm64") | .digest') + SHA256_I386=$(cat manifest1.json | ./jq -r '.manifests[]| select(.platform.architecture == "386") | .digest') + SHA256_ARMV6=$(cat manifest2.json | ./jq -r '.manifests[]| select(.platform.architecture == "arm") | select(.platform.variant == "v6") | .digest') + SHA256_ARMV7=$(cat manifest2.json | ./jq -r '.manifests[]| select(.platform.architecture == "arm") | select(.platform.variant == "v7") | .digest') + echo "Creating new manifest: ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }}" + set -eux + docker manifest create --amend ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} \ + ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_AMD64}" \ + ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_ARM64}" \ + ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_I386}" \ + ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_ARMV6}" \ + ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_ARMV7}" + echo "Annotating new manifest: ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} with platforms and architectures" + docker manifest annotate ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_AMD64}" --arch amd64 --os linux + docker manifest annotate ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_ARM64}" --arch arm64 --os linux + docker manifest annotate ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_I386}" --arch 386 --os linux + docker manifest annotate ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_ARMV6}" --arch arm --os linux --variant v6 + docker manifest annotate ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} ghcr.io/"${GITHUB_ACTOR}/nagios@${SHA256_ARMV7}" --arch arm --os linux --variant v7 + - name: 'Push manifest to DockerHub' + run: | + echo "== This branch is : ${GITHUB_REF}" + echo "Will push image manifest ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} to DockerHub Registry" + docker manifest push ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} + - name: 'Push manifest to GitHub Container Registry' + run: | + echo "== This branch is : ${GITHUB_REF}" + echo "Will push image ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} to GitHub Container Registry" + docker manifest push ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} - name: Inspect image run: | docker buildx imagetools inspect ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} + docker buildx imagetools inspect ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} + diff --git a/CHANGELOG.md b/CHANGELOG.md index ab8b621..fd545ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,66 +3,6 @@ This Docker image contains more than one software (Nagios, Nagios plugins, NRPE, Apache HTTPD, etc.) with different versions. Hence we decided to name the releases with the naming `Build - ` which will have an incremental unsigned integer. In this document we will describe the contents of every image in every build. -## Build 36 (2026-06-12) - -* Nagios core: v4.5.13 -* Nagios plugins: v2.5.0 -* NRPE: 4.1.3 -* Alpine: - * 3.23.4: `amd64`, `i386`, `arm64`,`arm/v6`, `arm/v7` - -### Features - -* Upgrade to Nagios Core `4.5.13`. ([#102](https://github.com/manios/docker-nagios/issues/102)) - -## Build 35 (2026-04-03) - -* Nagios core: v4.5.12 -* Nagios plugins: v2.5.0 -* NRPE: 4.1.3 -* Alpine: - * 3.23.2: `amd64`, `i386`, `arm64`,`arm/v6`, `arm/v7` - -### Features - -* Upgrade to Nagios Plugins to `2.5.0`. ([#101](https://github.com/manios/docker-nagios/issues/101)) - -## Build 34 (2026-03-26) - -* Nagios core: v4.5.12 -* Nagios plugins: v2.4.12 -* NRPE: 4.1.3 -* Alpine: - * 3.23.2: `amd64`, `i386`, `arm64`,`arm/v6`, `arm/v7` - -### Features - -* Upgrade to Nagios Core `4.5.12`. ([#100](https://github.com/manios/docker-nagios/issues/100)) - -## Build 33 (2026-01-15) - -* Nagios core: v4.5.11 -* Nagios plugins: v2.4.12 -* NRPE: 4.1.3 -* Alpine: - * 3.23.2: `amd64`, `i386`, `arm64`,`arm/v6`, `arm/v7` - -### Features - -* Upgrade to Nagios Core `4.5.11`. ([#99](https://github.com/manios/docker-nagios/issues/99)) - -## Build 32 (2025-12-04) - -* Nagios core: v4.5.10 -* Nagios plugins: v2.4.12 -* NRPE: 4.1.3 -* Alpine: - * 3.23.0: `amd64`, `i386`, `arm64`,`arm/v6`, `arm/v7` - -### Features - -* Use Alpine 3.23 as base image for all architectures after [nagioscore #1025](https://github.com/NagiosEnterprises/nagioscore/issues/1025) was fixed and tested in `arm/v6` and `arm/v7`. ([#92](https://github.com/manios/docker-nagios/issues/92)) - ## Build 31 (2025-12-01) * Nagios core: v4.5.10 diff --git a/Dockerfile b/Dockerfile index 48fe474..9036350 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ # https://www.docker.com/blog/docker-arm-virtual-meetup-multi-arch-with-buildx/ -FROM alpine:3.23 AS builder-base +FROM alpine:3.22 AS builder-base ARG TARGETPLATFORM ARG BUILDPLATFORM @@ -18,8 +18,8 @@ ENV NAGIOS_HOME=/opt/nagios \ NAGIOS_FQDN=nagios.example.com \ NAGIOSADMIN_USER=nagiosadmin \ NAGIOSADMIN_PASS=nagios \ - NAGIOS_VERSION=4.5.13 \ - NAGIOS_PLUGINS_VERSION=2.5 \ + NAGIOS_VERSION=4.5.10 \ + NAGIOS_PLUGINS_VERSION=2.4.12 \ NRPE_VERSION=4.1.3 \ APACHE_LOCK_DIR=/var/run \ APACHE_LOG_DIR=/var/log/apache2 @@ -190,7 +190,7 @@ LABEL name="Nagios" \ nrpeVersion=$NRPE_VERSION \ homepage="https://www.nagios.com/" \ maintainer="Christos Manios " \ - build="36" \ + build="31" \ org.opencontainers.image.title="Nagios" \ org.opencontainers.image.description="Nagios, the Industry Standard In IT Infrastructure Monitoring" \ org.opencontainers.image.vendor="Nagios" \ @@ -199,7 +199,7 @@ LABEL name="Nagios" \ org.opencontainers.image.url="https://hub.docker.com/r/manios/nagios" \ org.opencontainers.image.source="https://github.com/manios/docker-nagios" \ org.opencontainers.image.documentation="https://github.com/manios/docker-nagios/blob/master/README.md" \ - org.opencontainers.image.version="36" + org.opencontainers.image.version="31" RUN mkdir -p ${NAGIOS_HOME} && \ mkdir -p /orig/apache2 diff --git a/README.md b/README.md index aa8295a..d2055bf 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Build Status: ## Supported tags and respective `Dockerfile` links -* `4.5.13`, `4.5`, `latest` [(4.5.13/Dockerfile)](https://github.com/manios/docker-nagios/blob/master/Dockerfile) +* `4.5.10`, `4.5`, `latest` [(4.5.10/Dockerfile)](https://github.com/manios/docker-nagios/blob/master/Dockerfile) For more information about the image versions you may refer to the [CHANGELOG](https://github.com/manios/docker-nagios/blob/master/CHANGELOG.md) diff --git a/alpine3-12.dockerfile b/alpine3-12.dockerfile new file mode 100644 index 0000000..9684a64 --- /dev/null +++ b/alpine3-12.dockerfile @@ -0,0 +1,245 @@ +### ================================== ### +### STAGE 1 CREATE PARENT IMAGE ### +### ================================== ### + +# https://www.docker.com/blog/docker-arm-virtual-meetup-multi-arch-with-buildx/ + +FROM alpine:3.12 AS builder-base + +ARG TARGETPLATFORM +ARG BUILDPLATFORM + +ENV NAGIOS_HOME=/opt/nagios \ + NAGIOS_USER=nagios \ + NAGIOS_GROUP=nagios \ + NAGIOS_CMDUSER=nagios \ + NAGIOS_CMDGROUP=nagios \ + NAGIOS_TIMEZONE=UTC \ + NAGIOS_FQDN=nagios.example.com \ + NAGIOSADMIN_USER=nagiosadmin \ + NAGIOSADMIN_PASS=nagios \ + NAGIOS_VERSION=4.5.10 \ + NAGIOS_PLUGINS_VERSION=2.4.12 \ + NRPE_VERSION=4.1.3 \ + APACHE_LOCK_DIR=/var/run \ + APACHE_LOG_DIR=/var/log/apache2 + + +RUN addgroup -S ${NAGIOS_GROUP} && \ + adduser -S ${NAGIOS_USER} -G ${NAGIOS_CMDGROUP} -g ${NAGIOS_USER} && \ + apk update && \ + apk add --no-cache git curl unzip apache2 apache2-utils rsyslog \ + php7 php7-gd php7-cli runit parallel ssmtp \ + libltdl libintl openssl-dev php7-apache2 procps tzdata \ + libldap mariadb-connector-c freeradius-client-dev libpq libdbi \ + lm-sensors perl net-snmp-perl perl-net-snmp perl-crypt-x509 \ + perl-timedate perl-libwww perl-text-glob samba-client openssh openssl \ + net-snmp-tools bind-tools gd gd-dev bash && \ + addgroup -S apache ${NAGIOS_CMDGROUP} + + +### ================================== ### +### STAGE 2 COMPILE NAGIOS SOURCES ### +### ================================== ### + +FROM builder-base AS builder-compile +ARG TARGETPLATFORM +ARG BUILDPLATFORM + +# Add dependencies required to build Nagios +RUN apk update && \ + apk add --no-cache build-base automake libtool autoconf py-docutils gnutls \ + gnutls-dev g++ make alpine-sdk build-base gcc autoconf \ + gettext-dev linux-headers openssl-dev net-snmp net-snmp-tools \ + libcrypto1.1 libpq musl libldap libssl1.1 libdbi freeradius-client mariadb-connector-c \ + openssh-client bind-tools samba-client fping grep rpcbind \ + lm-sensors net-snmp-tools \ + file freeradius-client-dev libdbi-dev libpq linux-headers mariadb-dev \ + mariadb-connector-c-dev perl \ + net-snmp-dev openldap-dev openssl-dev postgresql-dev wget + +# Download Nagios core, plugins and nrpe sources +RUN cd /tmp && \ + echo -n "Downloading Nagios ${NAGIOS_VERSION} source code: " && \ + wget -O nagios-core.tar.gz "https://github.com/NagiosEnterprises/nagioscore/archive/refs/tags/nagios-${NAGIOS_VERSION}.tar.gz" && \ + echo -n -e "OK\nDownloading Nagios plugins ${NAGIOS_PLUGINS_VERSION} source code: " && \ + wget -O nagios-plugins.tar.gz "https://github.com/nagios-plugins/nagios-plugins/archive/refs/tags/release-${NAGIOS_PLUGINS_VERSION}.tar.gz" && \ + echo -n -e "OK\nDownloading NRPE ${NRPE_VERSION} source code: " && \ + wget -O nrpe.tar.gz "https://github.com/NagiosEnterprises/nrpe/archive/refs/tags/nrpe-${NRPE_VERSION}.tar.gz" && \ + env && \ + echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM !! == " && \ + echo "OK" + +# Compile Nagios Core +RUN ls -l /tmp && cd /tmp && \ + tar zxf nagios-core.tar.gz && \ + tar zxf nagios-plugins.tar.gz && \ + tar zxf nrpe.tar.gz && \ + cd "/tmp/nagioscore-nagios-${NAGIOS_VERSION}" && \ + echo -e "\n ===========================\n Configure Nagios Core\n ===========================\n" && \ + ./configure \ + --prefix=${NAGIOS_HOME} \ + --exec-prefix=${NAGIOS_HOME} \ + --enable-event-broker \ + --with-command-user=${NAGIOS_CMDUSER} \ + --with-command-group=${NAGIOS_CMDGROUP} \ + --with-nagios-user=${NAGIOS_USER} \ + --with-nagios-group=${NAGIOS_GROUP} && \ + : 'Apply patches to Nagios Core sources:' && \ + echo -n "Replacing \"\" with \"\": " && \ + sed -i 's///g' ./include/config.h && \ + echo "OK" && \ + echo -e "\n\n ===========================\n Compile Nagios Core\n ===========================\n" && \ + make all && \ + echo -e "\n\n ===========================\n Install Nagios Core\n ===========================\n" && \ + make install && \ + make install-commandmode && \ + make install-config && \ + make install-webconf && \ + echo -n "Nagios installed size: " && \ + du -h -s ${NAGIOS_HOME} + +# Compile Nagios Plugins +RUN echo -e "\n\n ===========================\n Configure Nagios Plugins\n ===========================\n" && \ + ls -lia /tmp && cd /tmp && \ + cd /tmp/nagios-plugins-release-${NAGIOS_PLUGINS_VERSION} && \ + ./autogen.sh && \ + ./configure --with-nagios-user=${NAGIOS_USER} \ + --with-nagios-group=${NAGIOS_USER} \ + --with-openssl \ + --prefix=${NAGIOS_HOME} \ + --with-ping-command="/bin/ping -n -w %d -c %d %s" \ + --with-ipv6 \ + --with-ping6-command="/bin/ping6 -n -w %d -c %d %s" && \ + echo "Nagios plugins configured: OK" && \ + echo -n "Replacing \"\" with \"\": " && \ + egrep -rl "\" . | xargs sed -i 's///g' && \ + egrep -rl "\"sys\/poll.h\"" . | xargs sed -i 's/"sys\/poll.h"/"poll.h"/g' && \ + echo "OK" && \ + echo -e "\n\n ===========================\n Compile Nagios Plugins\n ===========================\n" && \ + make && \ + echo "Nagios plugins compile successfully: OK" && \ + echo -e "\n\n ===========================\nInstall Nagios Plugins\n ===========================\n" && \ + make install && \ + echo "Nagios plugins installed successfully: OK" + +# Compile NRPE +RUN echo -e "\n\n =====================\n Configure NRPE\n =====================\n" && \ + cd /tmp/nrpe-nrpe-${NRPE_VERSION} && \ + ./configure --enable-command-args \ + --with-nagios-user=${NAGIOS_USER} \ + --with-nagios-group=${NAGIOS_USER} \ + --with-ssl=/usr/bin/openssl \ + --with-ssl-lib=/usr/lib && \ + echo "NRPE client configured: OK" && \ + echo -e "\n\n ===========================\n Compile NRPE\n ===========================\n" && \ + # make all && \ + make check_nrpe && \ + echo "NRPE compiled successfully: OK" && \ + echo -e "\n\n ===========================\n Install NRPE\n ===========================\n" && \ + # make install && \ + cp src/check_nrpe ${NAGIOS_HOME}/libexec/ && \ + echo "NRPE installed successfully: OK" && \ + echo -n "Final Nagios installed size: " && \ + du -h -s ${NAGIOS_HOME} + +# Compile Nagios files +# Create SSMTP configuration + + +# RUN sed -i.bak 's/.*\=www\-data//g' /etc/apache2/envvars +RUN export DOC_ROOT="DocumentRoot $(echo $NAGIOS_HOME/share)" && \ + sed -i "s,DocumentRoot.*,$DOC_ROOT," /etc/apache2/httpd.conf && \ + sed -i "s|^ *ScriptAlias.*$|ScriptAlias /cgi-bin $NAGIOS_HOME/sbin|g" /etc/apache2/httpd.conf && \ + sed -i 's/^\(.*\)#\(LoadModule cgi_module\)\(.*\)/\1\2\3/' /etc/apache2/httpd.conf && \ + echo "ServerName ${NAGIOS_FQDN}" >> /etc/apache2/httpd.conf + +RUN sed -i 's,/bin/mail,/usr/bin/mail,' ${NAGIOS_HOME}/etc/objects/commands.cfg && \ + sed -i 's,/usr/usr,/usr,' ${NAGIOS_HOME}/etc/objects/commands.cfg && \ + \ + : '# Modify Nagios mail commands in order to work with SSMTP' && \ + sed -i 's/^.*command_line.*Host Alert.*$//g' /opt/nagios/etc/objects/commands.cfg && \ + sed -i 's/^.*command_line.*Service Alert.*$//g' /opt/nagios/etc/objects/commands.cfg && \ + sed -i '/notify-host-by-email/a command_line /usr/bin/printf "%b" "Subject: $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$\\n\\n***** Nagios *****\\n\\nNotification Type: $NOTIFICATIONTYPE$\\nHost: $HOSTNAME$\\nState: $HOSTSTATE$\\nAddress: $HOSTADDRESS$\\nInfo: $HOSTOUTPUT$\\n\\nDate/Time: $LONGDATETIME$\\n" | /usr/sbin/sendmail -v $CONTACTEMAIL$' ${NAGIOS_HOME}/etc/objects/commands.cfg && \ + sed -i '/notify-service-by-email/a command_line /usr/bin/printf "%b" "Subject: $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$\\n\\n***** Nagios *****\\n\\nNotification Type: $NOTIFICATIONTYPE$\\n\\nService: $SERVICEDESC$\\nHost: $HOSTALIAS$\\nAddress: $HOSTADDRESS$\\nState: $SERVICESTATE$\\n\\nDate/Time: $LONGDATETIME$\\n\\nAdditional Info:\\n\\n$SERVICEOUTPUT$\\n" | /usr/sbin/sendmail -v $CONTACTEMAIL$' ${NAGIOS_HOME}/etc/objects/commands.cfg && \ + \ + : '# Modify etc/resource.cfg in order to include custom plugins directory' && \ + sed -i 's/^\(.*\)\(Sets .USER2. to be the path to\) event handlers.*$/\1\2 custom plugins directory/g' "${NAGIOS_HOME}"/etc/resource.cfg && \ + sed -i 's;^#\([$]USER2[$]=\).*$;\1/opt/Custom-Nagios-Plugins;g' "${NAGIOS_HOME}"/etc/resource.cfg + +RUN echo "use_timezone=${NAGIOS_TIMEZONE}" >> ${NAGIOS_HOME}/etc/nagios.cfg && \ + sed -i 's/date_format=us/date_format=iso8601/g' ${NAGIOS_HOME}/etc/nagios.cfg + +# Copy original configuration to /orig directory +RUN mkdir -p /orig/apache2 && \ + cp -r /etc/apache2/* /orig/apache2 && \ + cp -r ${NAGIOS_HOME}/etc /orig/etc && \ + cp -r ${NAGIOS_HOME}/var /orig/var + + +### ========================== ### +### START OF ACTUAL DOCKERFILE ### +### ========================== ### + +FROM builder-base + + +LABEL name="Nagios" \ + nagiosVersion=$NAGIOS_VERSION \ + nagiosPluginsVersion=$NAGIOS_PLUGINS_VERSION \ + nrpeVersion=$NRPE_VERSION \ + homepage="https://www.nagios.com/" \ + maintainer="Christos Manios " \ + build="31" \ + org.opencontainers.image.title="Nagios" \ + org.opencontainers.image.description="Nagios, the Industry Standard In IT Infrastructure Monitoring" \ + org.opencontainers.image.vendor="Nagios" \ + org.opencontainers.image.authors="Christos Manios " \ + org.opencontainers.image.licenses="MIT" \ + org.opencontainers.image.url="https://hub.docker.com/r/manios/nagios" \ + org.opencontainers.image.source="https://github.com/manios/docker-nagios" \ + org.opencontainers.image.documentation="https://github.com/manios/docker-nagios/blob/master/README.md" \ + org.opencontainers.image.version="31" + +RUN mkdir -p ${NAGIOS_HOME} && \ + mkdir -p /orig/apache2 + +WORKDIR ${NAGIOS_HOME} +COPY --from=builder-compile ${NAGIOS_HOME} ${NAGIOS_HOME} + +COPY --from=builder-compile /orig /orig + +ADD overlay/ / + +# Make +RUN chmod +x /usr/local/bin/start_nagios \ + /etc/sv/apache/run \ + /etc/sv/nagios/run \ + /etc/sv/rsyslog/run && \ + rm -rf /etc/sv/getty-5 && \ + \ + : '# enable all runit services' && \ + ln -s /etc/sv/* /etc/service && \ + \ + : '# Copy initial settings files' && \ + chown -R nagios:nagios ${NAGIOS_HOME} && \ + : '# Create special dirs' && \ + (mkdir /run/apache2 || true) && \ + mkdir -p /var/spool/rsyslog && \ + : '# Copy Apache configuration' && \ + cp -Rp /orig/apache2/* /etc/apache2 && \ + : '# Convert files to Unix format' && \ + dos2unix /etc/rsyslog.conf && \ + dos2unix /usr/local/bin/start_nagios && \ + dos2unix /etc/sv/**/run && \ + dos2unix /etc/ssmtp/ssmtp.conf && \ + : '# Add mail symbolic links to ssmtp' && \ + ln -s $(which ssmtp) /bin/mail && \ + ln -s $(which ssmtp) /usr/sbin/mail + + +EXPOSE 80 + +VOLUME "${NAGIOS_HOME}/var" "${NAGIOS_HOME}/etc" "/var/log/apache2" "/opt/Custom-Nagios-Plugins" + +CMD [ "/usr/local/bin/start_nagios" ]