From 5ef4bc93264cdf242917a8436acc8c6f4400a5bd Mon Sep 17 00:00:00 2001 From: Stacy Olivas Date: Wed, 12 Dec 2018 21:45:58 -0800 Subject: [PATCH 1/6] Modified to include crontab support and switched to using MariaDB instead of MySQL --- Dockerfile => build/Dockerfile | 17 ++++++++++++++--- build/crontab | 5 +++++ build/entrypoint.sh | 29 +++++++++++++++++++++++++++++ php.ini => build/php.ini | 1 + config/crontab | 5 +++++ docker-compose.yml | 28 ++++++++++++++++++++++++++++ 6 files changed, 82 insertions(+), 3 deletions(-) rename Dockerfile => build/Dockerfile (91%) create mode 100644 build/crontab create mode 100644 build/entrypoint.sh rename php.ini => build/php.ini (99%) create mode 100644 config/crontab create mode 100644 docker-compose.yml diff --git a/Dockerfile b/build/Dockerfile similarity index 91% rename from Dockerfile rename to build/Dockerfile index fdc95d0..88fc744 100644 --- a/Dockerfile +++ b/build/Dockerfile @@ -1,5 +1,6 @@ FROM php:5.6-apache -MAINTAINER Pierre Cheynier +LABEL "Author"="Pierre Cheynier " +LABEL "Modificaitons for cron"=" Stacy Olivas " ENV PHPIPAM_SOURCE https://github.com/phpipam/phpipam/ ENV PHPIPAM_VERSION 1.3.2 @@ -13,8 +14,8 @@ ENV WEB_REPO /var/www/html RUN sed -i /etc/apt/sources.list -e 's/$/ non-free'/ && \ apt-get update && apt-get -y upgrade && \ rm /etc/apt/preferences.d/no-debian-php && \ - apt-get install -y libcurl4-gnutls-dev libgmp-dev libmcrypt-dev libfreetype6-dev libjpeg-dev libpng-dev libldap2-dev libsnmp-dev snmp-mibs-downloader iputils-ping && \ - rm -rf /var/lib/apt/lists/* + apt-get install -y libcurl4-gnutls-dev libgmp-dev libmcrypt-dev libfreetype6-dev libjpeg-dev libpng-dev libldap2-dev libsnmp-dev snmp-mibs-downloader iputils-ping cron mariadb-client && \ + rm -rf /var/lib/apt/lists/* # Install required packages and files required for snmp RUN mkdir -p /var/lib/mibs/ietf && \ @@ -46,6 +47,8 @@ RUN docker-php-ext-configure mysqli --with-mysqli=mysqlnd && \ COPY php.ini /usr/local/etc/php/ +COPY ./crontab /etc/ + # Copy phpipam sources to web dir ADD ${PHPIPAM_SOURCE}/archive/${PHPIPAM_VERSION}.tar.gz /tmp/ RUN tar -xzf /tmp/${PHPIPAM_VERSION}.tar.gz -C ${WEB_REPO}/ --strip-components=1 @@ -70,3 +73,11 @@ RUN cp ${WEB_REPO}/config.dist.php ${WEB_REPO}/config.php && \ ${WEB_REPO}/config.php EXPOSE 80 + +COPY ./entrypoint.sh /entrypoint.sh + +RUN /bin/chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] + + diff --git a/build/crontab b/build/crontab new file mode 100644 index 0000000..5f40952 --- /dev/null +++ b/build/crontab @@ -0,0 +1,5 @@ +#run phpipam cron jobs +#path for scripts in container: /var/www/html/functions/scripts +# update host status every 15 minutes +*/15 * * * * /usr/local/bin/php /var/www/html/functions/scripts/pingCheck.php +*/15 * * * * /usr/local/bin/php /var/www/html/functions/scripts/discoveryCheck.php diff --git a/build/entrypoint.sh b/build/entrypoint.sh new file mode 100644 index 0000000..95db01b --- /dev/null +++ b/build/entrypoint.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +# copy over the crontab file from the host at /config +CT="/config/crontab" + +if [ -f "$CT" ]; then + /bin/echo "* Copying /config/crontab to /etc/crontab" + /bin/cp /config/crontab /etc +fi + + +# wait until MySQL is really available before starting cron and continuing with phpipam startup +maxcounter=60 + +counter=1 +while ! mysql --protocol TCP -u"$MYSQL_ENV_MYSQL_USER" -p"$MYSQL_ENV_MYSQL_PASSWORD" -h"$MYSQL_ENV_MYSQL_HOST" -e "show databases;" > /dev/null 2>&1; do + sleep 1 + counter=`expr $counter + 1` + if [ $counter -gt $maxcounter ]; then + >&2 echo "We have been waiting for MySQL too long already; failing." + exit 1 + fi; +done + +/bin/echo "* Starting cron service" +# start the cron service in teh container +/usr/sbin/service cron start +exec /usr/local/bin/docker-php-entrypoint apache2-foreground + diff --git a/php.ini b/build/php.ini similarity index 99% rename from php.ini rename to build/php.ini index 517925f..134bf82 100644 --- a/php.ini +++ b/build/php.ini @@ -70,3 +70,4 @@ url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry" [ldap] ldap.max_links = -1 + diff --git a/config/crontab b/config/crontab new file mode 100644 index 0000000..5f40952 --- /dev/null +++ b/config/crontab @@ -0,0 +1,5 @@ +#run phpipam cron jobs +#path for scripts in container: /var/www/html/functions/scripts +# update host status every 15 minutes +*/15 * * * * /usr/local/bin/php /var/www/html/functions/scripts/pingCheck.php +*/15 * * * * /usr/local/bin/php /var/www/html/functions/scripts/discoveryCheck.php diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3139e26 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,28 @@ +version: '2' + +services: + mysql: + image: mariadb + environment: + - MYSQL_ROOT_PASSWORD=my-password + restart: always + volumes: + - ./db_data/mysql:/var/lib/mysql + container_name: phpipam_mysql + ipam: + depends_on: + - mysql + build: ./build/ + restart: always + environment: + - MYSQL_ENV_MYSQL_USER=root + - MYSQL_ENV_MYSQL_PASSWORD=my-password + - MYSQL_ENV_MYSQL_HOST=mysql + container_name: phpipam + ports: + - "8080:80" + volumes: + - ./config:/config + + + From dcea974bc0f7afa0ceeb01273f8d90222010bf7b Mon Sep 17 00:00:00 2001 From: Stacy Olivas Date: Wed, 12 Dec 2018 21:51:50 -0800 Subject: [PATCH 2/6] Update README.md MariaDB and crontab support added --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 79b9a68..cf6225b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,12 @@ # docker-phpipam +--- + +Update: +12/12/18 - Modified to inlcude support for crontab and switched to using MariaDB from MySQL + +--- + phpIPAM is an open-source web IP address management application. Its goal is to provide light and simple IP address management application. phpIPAM is developed and maintained by Miha Petkovsek, released under the GPL v3 license, project source is [here](https://github.com/phpipam/phpipam) @@ -10,7 +17,9 @@ Learn more on [phpIPAM homepage](http://phpipam.net) ## How to use this Docker image -### Mysql +### MySQL + +Note: MariaDB is now used instead of MySQL. The same commands will work though as MariaDB is a mostly drop-in replacement for MySQL. Run a MySQL database, dedicated to phpipam @@ -56,6 +65,12 @@ For multi-host containers, expose ports, run etcd or consul to make service disc ![done](https://cloud.githubusercontent.com/assets/4225738/8746792/0d6fa34e-2c8d-11e5-8002-3793361ae34d.png) +### Crontab support + +Crontab support has been added. By default the scan and ping scripts are run every 15 minutes. + +You can modify this by making changes to the crontab file under the config directory and restating the container + ### Docker compose You can also create an all-in-one YAML deployment descriptor with Docker compose, like this: From bd0bbb216d826d068d36f434332341377f895996 Mon Sep 17 00:00:00 2001 From: Stacy Olivas Date: Wed, 12 Dec 2018 22:08:49 -0800 Subject: [PATCH 3/6] Update README.md typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cf6225b..bf9a8d2 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ --- Update: -12/12/18 - Modified to inlcude support for crontab and switched to using MariaDB from MySQL +12/12/18 - Modified to include support for crontab and switched to using MariaDB from MySQL --- From dec200614f6a2855bbc26f19acb8f16eb257e49b Mon Sep 17 00:00:00 2001 From: Stacy Olivas Date: Wed, 9 Jan 2019 11:14:00 -0800 Subject: [PATCH 4/6] minor fix --- config/crontab | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/crontab b/config/crontab index 5f40952..6ef90c4 100644 --- a/config/crontab +++ b/config/crontab @@ -1,5 +1,5 @@ #run phpipam cron jobs #path for scripts in container: /var/www/html/functions/scripts # update host status every 15 minutes -*/15 * * * * /usr/local/bin/php /var/www/html/functions/scripts/pingCheck.php -*/15 * * * * /usr/local/bin/php /var/www/html/functions/scripts/discoveryCheck.php +*/15 * * * * root /usr/local/bin/php /var/www/html/functions/scripts/pingCheck.php +*/15 * * * * root /usr/local/bin/php /var/www/html/functions/scripts/discoveryCheck.php From 06e93bd853e3a55dedaef6d29a759310ef685510 Mon Sep 17 00:00:00 2001 From: Stacy Olivas Date: Wed, 9 Jan 2019 11:14:46 -0800 Subject: [PATCH 5/6] minor fix --- build/crontab | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/crontab b/build/crontab index 5f40952..6ef90c4 100644 --- a/build/crontab +++ b/build/crontab @@ -1,5 +1,5 @@ #run phpipam cron jobs #path for scripts in container: /var/www/html/functions/scripts # update host status every 15 minutes -*/15 * * * * /usr/local/bin/php /var/www/html/functions/scripts/pingCheck.php -*/15 * * * * /usr/local/bin/php /var/www/html/functions/scripts/discoveryCheck.php +*/15 * * * * root /usr/local/bin/php /var/www/html/functions/scripts/pingCheck.php +*/15 * * * * root /usr/local/bin/php /var/www/html/functions/scripts/discoveryCheck.php From 881d3611ba12d0b6229c3e208456cccc4358cfdb Mon Sep 17 00:00:00 2001 From: Stacy Olivas Date: Fri, 11 Jan 2019 08:40:56 -0800 Subject: [PATCH 6/6] Update entrypoint.sh Minor fix - work around Debian 9 "bug" with cron and Docker. --- build/entrypoint.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/entrypoint.sh b/build/entrypoint.sh index 95db01b..72ed69e 100644 --- a/build/entrypoint.sh +++ b/build/entrypoint.sh @@ -22,6 +22,10 @@ while ! mysql --protocol TCP -u"$MYSQL_ENV_MYSQL_USER" -p"$MYSQL_ENV_MYSQL_PASSW fi; done +#Work around Debian 9 "bug" with cron and Docker +/bin/echo "* Setting up for cron" +/usr/bin/touch /etc/crontab /etc/cron.*/* + /bin/echo "* Starting cron service" # start the cron service in teh container /usr/sbin/service cron start