diff --git a/docker/.env b/docker/.env new file mode 100644 index 0000000..e14932e --- /dev/null +++ b/docker/.env @@ -0,0 +1 @@ +RESTART_POLICY=unless-stopped diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..8ed743c --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,88 @@ +FROM ubuntu:latest + +######################################################################################################### +######################################################################################################### +## +## ZABBIX-MAILGRAPH (Dockerfile) +## ============================= +## Dockerfile to builld and configure the zabbix-mailgraph image. +## +## ----------------------------------------------------------------------------------------------------- +## v0.9.1 2025/05/05 - Mark Oudsen - First public beta - Pending documentation +## v0.9.0 2025/05/05 - Mark Oudsen - Internal test release +## v0.1.0 2025/05/05 - Mark Oudsen - Initial build, based on idea from "dima-online +## "https://github.com/moudsen/mailGraph/issues/50 +## +## ----------------------------------------------------------------------------------------------------- +## +## (C) M.J.Oudsen, mark.oudsen@puzzl.nl +## MIT License +## Credits: "demi-online" (https://github.com/dima-online) +## +######################################################################################################### +######################################################################################################### + +# Disable interactive functions +ENV DEBIAN_FRONTEND=noninteractive + +# Install Apache, PHP and supplimentary programs +RUN apt-get update && \ + apt-get install -y apache2 \ + libapache2-mod-php \ + php-curl \ + php-zip \ + curl \ + git + +# Clean out APT files +RUN rm -rf /var/lib/apt/lists/* +RUN apt-get clean -y + +# Install Composer for PHP dependencies +RUN cd /tmp && curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer + +# Enable Apache modules +RUN a2enmod php8.3 +RUN a2enmod rewrite + +# Update the PHP.ini file, enable tags and quieten logging. +RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/8.3/apache2/php.ini +RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php/8.3/apache2/php.ini + +# Manually set up the apache environment variables +ENV APACHE_RUN_USER=www-data +ENV APACHE_RUN_GROUP=www-data +ENV APACHE_LOG_DIR="/var/log/apache2" +ENV APACHE_LOCK_DIR="/var/lock/apache2" +ENV APACHE_PID_FILE="/var/run/apache2.pid" + +# Copy the Github code into Apache site directory (run fetch_mailgraph.sh before building!) +ADD www /var/www/site/public + +# Copy the cleanup script into local bin +ADD cleanup.sh /usr/local/bin/cleanup +RUN chmod +x /usr/local/bin/cleanup + +# Fetch dependencies via Composer +RUN composer require phpmailer/phpmailer +RUN composer require twig/twig + +# Move into the site directory +RUN mv /composer* /var/www/site/public/. +RUN mv /vendor /var/www/site/public/. + +# Create some directories not existing yet +RUN mkdir /var/www/site/public/log +RUN mkdir /var/www/site/public/tmp + +# Fix ownership +RUN chown www-data.www-data -R /var/www/site/public + +# Update(/overwrite) the default apache site with the config we created +ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf + +# Expose the HTTP port to external +EXPOSE 80 + +# By default, simply start apache +ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"] diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..2d34955 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,29 @@ +## Introduction ## +With the following instructions, mailGraph can be run in a Docker container. +Every new version of mailGraph will also be deployed to Docker Hub. + +## Instructions - Plain vanilla deployment ## +- Create a directory structure on your system as follows: + ``` + mkdir /opt/Zabbix-Mailgraph + mkdir /opt/Zabbix-Mailgraph/config + mkdir /opt/Zabbix-Mailgraph/templates + ``` +- Create a new `config.json` in the config directory and configure accordingly (refer to the wiki for more detailed instructions or use the `config.json.template` as a boilerplate). +- Deploy the mailGraph container, preferably using `docker-compose`. +-- Adopt and configure the `docker-compose.yml` file to your needs; +-- Configure `RESTART_POLICY=unless-stopped` in a file name `.env` (same directory as `docker-compose`). +- Start the container: `docker-compose -D up` + +## Testing and Debugging ## +- Display currently running containers `docker ps` +- Execute `docker exec -it sh` for a shell into the container +- Following the instructions in the Wiki on troubleshooting and debugging +- When done testing, `exit` the container + +## Periodic cleanup of images and logs ## +In case you like to adjust the container to your needs, you can adopt and modiyfy the provisioned scripts and files in this directory. + +## Special thank you ## +I would like to express my gratitude to the following people that have actively contributed to bring bugs and improvements to my attention with regards for mailGraph on Docker: +- [dima-online](https://github.com/dima-online) diff --git a/docker/apache-config.conf b/docker/apache-config.conf new file mode 100644 index 0000000..05064e7 --- /dev/null +++ b/docker/apache-config.conf @@ -0,0 +1,18 @@ +ServerName mailgraph.mydomain.com + + + ServerAdmin me@mydomain.com + + DocumentRoot /var/www/site/public + + + Options Indexes FollowSymLinks MultiViews + AllowOverride All + Order deny,allow + Allow from all + + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + diff --git a/docker/build.sh b/docker/build.sh new file mode 100755 index 0000000..0c18235 --- /dev/null +++ b/docker/build.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker build -t hoppa66/zabbix-mailgraph . diff --git a/docker/cleanup.sh b/docker/cleanup.sh new file mode 100644 index 0000000..0ca6819 --- /dev/null +++ b/docker/cleanup.sh @@ -0,0 +1,3 @@ +#!/bin/bash +cd /var/www/site/public +php mailGraph.php cleanup diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..c159d2c --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,13 @@ +version: '2.1' + +services: + webhook: + image: hoppa66/zabbix-mailgraph:latest + restart: ${RESTART_POLICY} + hostname: mailgraph + ports: + - "9080:80" + volumes: + - /opt/Zabbix-mailGraph/apache.log:/var/log/apache2:rw + - /opt/Zabbix-mailGraph/config:/var/www/site/public/config:ro + - /opt/Zabbix-mailGraph/templates:/var/www/site/public/templates:ro diff --git a/docker/fetch_mailgraph.sh b/docker/fetch_mailgraph.sh new file mode 100755 index 0000000..87f653d --- /dev/null +++ b/docker/fetch_mailgraph.sh @@ -0,0 +1,3 @@ +#!/bin/bash +rm -rf www +git clone https://github.com/moudsen/mailGraph.git www