diff --git a/README.md b/README.md index 79b9a68..bf9a8d2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,12 @@ # docker-phpipam +--- + +Update: +12/12/18 - Modified to include 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: 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..6ef90c4 --- /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 * * * * 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 diff --git a/build/entrypoint.sh b/build/entrypoint.sh new file mode 100644 index 0000000..72ed69e --- /dev/null +++ b/build/entrypoint.sh @@ -0,0 +1,33 @@ +#!/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 + +#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 +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..6ef90c4 --- /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 * * * * 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 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 + + +