From 18d390eceabdda629034155f684316a5a9b3dd4d Mon Sep 17 00:00:00 2001 From: Jeroen Boonstra Date: Wed, 28 Mar 2018 11:27:49 +0200 Subject: [PATCH 1/7] Moved to seperate directory --- docker-compose.yml | 50 ---------------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index c9271b5..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,50 +0,0 @@ -version: '2' - -services: - - powerdns-authoritative: - image: winggundamth/powerdns-mysql:trusty - hostname: powerdns-authoritative - depends_on: - - powerdns-authoritative-mariadb - links: - - powerdns-authoritative-mariadb:mysqldb - ports: - - 172.17.0.1:53:53/udp - - 8081:8081 - environment: - - PDNS_DB_HOST=mysqldb - - PDNS_DB_USERNAME=root - - PDNS_DB_NAME=powerdns - - PDNS_DB_PASSWORD=PowerDNSPassword - - PDNS_API_KEY=PowerDNSAPIKey - - powerdns-authoritative-mariadb: - image: mariadb:10.1.15 - hostname: powerdns-authoritative-mariadb - environment: - - MYSQL_DATABASE=powerdns - - MYSQL_ROOT_PASSWORD=PowerDNSPassword - - powerdns-admin: - image: winggundamth/powerdns-admin:trusty - hostname: powerdns-admin - depends_on: - - powerdns-admin-mariadb - - powerdns-authoritative - links: - - powerdns-admin-mariadb:mysqldb - - powerdns-authoritative:powerdns-server - volumes: - - ./:/home/web/powerdns-admin - ports: - - 9393:9393 - environment: - - WAITFOR_DB=60 - - powerdns-admin-mariadb: - image: mariadb:10.1.15 - hostname: powerdns-admin-mariadb - environment: - - MYSQL_DATABASE=powerdns-admin - - MYSQL_ROOT_PASSWORD=PowerDNSAdminPassword From 7bceb1262fc0aa2e8d1bf477e6e7ff3b5726ed77 Mon Sep 17 00:00:00 2001 From: Jeroen Boonstra Date: Wed, 28 Mar 2018 11:29:17 +0200 Subject: [PATCH 2/7] Added from upstream repo. Fixed missing Mysql client. --- docker/PowerDNS-MySQL/Dockerfile | 40 +++++++++ docker/PowerDNS-MySQL/build-files/pdns-pin | 3 + .../build-files/pdns.mysql.conf | 6 ++ docker/PowerDNS-MySQL/docker-entrypoint.sh | 89 +++++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 docker/PowerDNS-MySQL/Dockerfile create mode 100644 docker/PowerDNS-MySQL/build-files/pdns-pin create mode 100644 docker/PowerDNS-MySQL/build-files/pdns.mysql.conf create mode 100755 docker/PowerDNS-MySQL/docker-entrypoint.sh diff --git a/docker/PowerDNS-MySQL/Dockerfile b/docker/PowerDNS-MySQL/Dockerfile new file mode 100644 index 0000000..a79ea40 --- /dev/null +++ b/docker/PowerDNS-MySQL/Dockerfile @@ -0,0 +1,40 @@ +# PowerDNS Authoritative Server with MySQL backend +# https://www.powerdns.com +# +# The PowerDNS Authoritative Server is the only solution that enables +# authoritative DNS service from all major databases, including but not limited +# to MySQL, PostgreSQL, SQLite3, Oracle, Sybase, Microsoft SQL Server, LDAP and +# plain text files. + +FROM winggundamth/ubuntu-base:trusty +MAINTAINER Jirayut Nimsaeng +ENV FROM_BASE=trusty-20160503.1 + +# 1) Add PowerDNS repository https://repo.powerdns.com +# 2) Install PowerDNS server +# 3) Clean to reduce Docker image size +ARG APT_CACHER_NG +COPY build-files /build-files +RUN [ -n "$APT_CACHER_NG" ] && \ + echo "Acquire::http::Proxy \"$APT_CACHER_NG\";" \ + > /etc/apt/apt.conf.d/11proxy || true; \ + apt-get update && \ + apt-get install -y curl && \ + curl https://repo.powerdns.com/FD380FBB-pub.asc | apt-key add - && \ + echo 'deb [arch=amd64] http://repo.powerdns.com/ubuntu trusty-auth-40 main' \ + > /etc/apt/sources.list.d/pdns-$(lsb_release -cs).list && \ + mv /build-files/pdns-pin /etc/apt/preferences.d/pdns && \ + apt-get update && \ + apt-get install -y pdns-server pdns-backend-mysql mysql-client && \ + mv /build-files/pdns.mysql.conf /etc/powerdns/pdns.d/pdns.mysql.conf && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /etc/apt/apt.conf.d/11proxy /build-files \ + /etc/powerdns/pdns.d/pdns.simplebind.conf + +# 1) Copy Docker entrypoint script +COPY docker-entrypoint.sh /docker-entrypoint.sh + +EXPOSE 53/udp 53 8081 +VOLUME ["/var/log", "/etc/powerdns"] +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["/usr/sbin/pdns_server", "--guardian=yes"] diff --git a/docker/PowerDNS-MySQL/build-files/pdns-pin b/docker/PowerDNS-MySQL/build-files/pdns-pin new file mode 100644 index 0000000..24d2bea --- /dev/null +++ b/docker/PowerDNS-MySQL/build-files/pdns-pin @@ -0,0 +1,3 @@ +Package: pdns-* +Pin: origin repo.powerdns.com +Pin-Priority: 600 diff --git a/docker/PowerDNS-MySQL/build-files/pdns.mysql.conf b/docker/PowerDNS-MySQL/build-files/pdns.mysql.conf new file mode 100644 index 0000000..42a99c8 --- /dev/null +++ b/docker/PowerDNS-MySQL/build-files/pdns.mysql.conf @@ -0,0 +1,6 @@ +launch+=gmysql +gmysql-port=3306 +gmysql-host=172.17.0.1 +gmysql-password=CHANGEME +gmysql-user=powerdns +gmysql-dbname=powerdns diff --git a/docker/PowerDNS-MySQL/docker-entrypoint.sh b/docker/PowerDNS-MySQL/docker-entrypoint.sh new file mode 100755 index 0000000..e508511 --- /dev/null +++ b/docker/PowerDNS-MySQL/docker-entrypoint.sh @@ -0,0 +1,89 @@ +#!/bin/sh +# Author: Jirayut 'Dear' Nimsaeng +# +set -e + +PDNS_CONF_PATH="/etc/powerdns/pdns.conf" +PDNS_MYSQL_CONF_PATH="/etc/powerdns/pdns.d/pdns.mysql.conf" +PDNS_MYSQL_HOST="localhost" +PDNS_MYSQL_PORT="3306" +PDNS_MYSQL_USERNAME="powerdns" +PDNS_MYSQL_PASSWORD="$PDNS_DB_PASSWORD" +PDNS_MYSQL_DBNAME="powerdns" + +if [ -z "$PDNS_DB_PASSWORD" ]; then + echo 'ERROR: PDNS_DB_PASSWORD environment variable not found' + exit 1 +fi + +# Configure variables +if [ "$PDNS_DB_HOST" ]; then + PDNS_MYSQL_HOST="$PDNS_DB_HOST" +fi +if [ "$PDNS_DB_PORT" ]; then + PDNS_MYSQL_PORT="$PDNS_DB_PORT" +fi +if [ "$PDNS_DB_USERNAME" ]; then + PDNS_MYSQL_USERNAME="$PDNS_DB_USERNAME" +fi +if [ "$PDNS_DB_NAME" ]; then + PDNS_MYSQL_DBNAME="$PDNS_DB_NAME" +fi + +# Configure mysql backend +sed -i \ + -e "s/^gmysql-host=.*/gmysql-host=$PDNS_MYSQL_HOST/g" \ + -e "s/^gmysql-port=.*/gmysql-port=$PDNS_MYSQL_PORT/g" \ + -e "s/^gmysql-user=.*/gmysql-user=$PDNS_MYSQL_USERNAME/g" \ + -e "s/^gmysql-password=.*/gmysql-password=$PDNS_MYSQL_PASSWORD/g" \ + -e "s/^gmysql-dbname=.*/gmysql-dbname=$PDNS_MYSQL_DBNAME/g" \ + $PDNS_MYSQL_CONF_PATH + +if [ "$PDNS_SLAVE" != "1" ]; then + # Configure to be master + sed -i \ + -e "s/^#\?\smaster=.*/master=yes/g" \ + -e "s/^#\?\sslave=.*/slave=no/g" \ + $PDNS_CONF_PATH +else + # Configure to be slave + sed -i \ + -e "s/^#\?\smaster=.*/master=no/g" \ + -e "s/^#\?\sslave=.*/slave=yes/g" \ + $PDNS_CONF_PATH +fi + +if [ "$PDNS_API_KEY" ]; then + # Enable API + sed -i \ + -e "s/^#\?\sapi=.*/api=yes/g" \ + -e "s!^#\?\sapi-logfile=.*!api-logfile=/dev/stdout!g" \ + -e "s/^#\?\sapi-key=.*/api-key=$PDNS_API_KEY/g" \ + -e "s/^#\?\swebserver=.*/webserver=yes/g" \ + -e "s/^#\?\swebserver-address=.*/webserver-address=0.0.0.0/g" \ + $PDNS_CONF_PATH +fi + +if [ "$PDNS_WEBSERVER_ALLOW_FROM" ]; then + sed -i \ + "s/^#\?\swebserver-allow-from=.*/webserver-allow-from=$PDNS_WEBSERVER_ALLOW_FROM/g" \ + $PDNS_CONF_PATH +fi + + +MYSQL_COMMAND="mysql -h $PDNS_MYSQL_HOST -P $PDNS_MYSQL_PORT -u $PDNS_MYSQL_USERNAME -p$PDNS_MYSQL_PASSWORD" + +until $MYSQL_COMMAND -e ";" ; do + >&2 echo "MySQL is unavailable - sleeping" + sleep 1 +done + +>&2 echo "MySQL is up - initial database if not exists" +MYSQL_CHECK_IF_HAS_TABLE="SELECT COUNT(DISTINCT table_name) FROM information_schema.columns WHERE table_schema = '$PDNS_MYSQL_DBNAME';" +MYSQL_NUM_TABLE=$($MYSQL_COMMAND --batch --skip-column-names -e "$MYSQL_CHECK_IF_HAS_TABLE") +if [ "$MYSQL_NUM_TABLE" -eq 0 ]; then + $MYSQL_COMMAND -D $PDNS_MYSQL_DBNAME < /usr/share/doc/pdns-backend-mysql/schema.mysql.sql +fi + +# Start PowerDNS +exec "$@" From 71faaf4d17ce085579473c10b8cd580baf060200 Mon Sep 17 00:00:00 2001 From: Jeroen Boonstra Date: Wed, 28 Mar 2018 11:30:14 +0200 Subject: [PATCH 3/7] Updated version of the compose file. New image names, Port allocation. --- docker/docker-compose.yml | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 docker/docker-compose.yml diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..a110c27 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,50 @@ +version: '2' + +services: + + powerdns-authoritative: + image: powerdns-mysql + hostname: powerdns-authoritative + depends_on: + - powerdns-authoritative-mariadb + links: + - powerdns-authoritative-mariadb:mysqldb + ports: + - 5553:53/udp + - 8081:8081 + environment: + - PDNS_DB_HOST=mysqldb + - PDNS_DB_USERNAME=root + - PDNS_DB_NAME=powerdns + - PDNS_DB_PASSWORD=PowerDNSPassword + - PDNS_API_KEY=PowerDNSAPIKey + + powerdns-authoritative-mariadb: + image: mariadb:10.1.15 + hostname: powerdns-authoritative-mariadb + environment: + - MYSQL_DATABASE=powerdns + - MYSQL_ROOT_PASSWORD=PowerDNSPassword + + powerdns-admin: + image: powerdns-admin + hostname: powerdns-admin + depends_on: + - powerdns-admin-mariadb + - powerdns-authoritative + links: + - powerdns-admin-mariadb:mysqldb + - powerdns-authoritative:powerdns-server + volumes: + - ../:/home/web/powerdns-admin + ports: + - 9393:9393 + environment: + - WAITFOR_DB=60 + + powerdns-admin-mariadb: + image: mariadb:10.1.15 + hostname: powerdns-admin-mariadb + environment: + - MYSQL_DATABASE=powerdns-admin + - MYSQL_ROOT_PASSWORD=PowerDNSAdminPassword From be4afd5ca64ee27ede614367e545a2534d5abf0a Mon Sep 17 00:00:00 2001 From: Jeroen Boonstra Date: Wed, 28 Mar 2018 11:31:04 +0200 Subject: [PATCH 4/7] New docker image based on Alpine Linux --- docker/PowerDNS-Admin/Dockerfile | 42 ++++++++++++++++++++++ docker/PowerDNS-Admin/docker-entrypoint.sh | 12 +++++++ 2 files changed, 54 insertions(+) create mode 100644 docker/PowerDNS-Admin/Dockerfile create mode 100755 docker/PowerDNS-Admin/docker-entrypoint.sh diff --git a/docker/PowerDNS-Admin/Dockerfile b/docker/PowerDNS-Admin/Dockerfile new file mode 100644 index 0000000..133b709 --- /dev/null +++ b/docker/PowerDNS-Admin/Dockerfile @@ -0,0 +1,42 @@ +# PowerDNS-Admin +# Original from: +# https://github.com/ngoduykhanh/PowerDNS-Admin +# +# Initial image by winggundamth(/powerdns-mysql:trusty) +# +# +FROM alpine +MAINTAINER Jeroen Boonstra + +ENV APP_USER=web APP_NAME=powerdns-admin +ENV APP_PATH=/home/$APP_USER/$APP_NAME + + +RUN apk add --update \ + sudo \ + python \ + libxml2 \ + xmlsec \ + git \ + python-dev \ + py-pip \ + build-base \ + libxml2-dev \ + xmlsec-dev \ + libffi-dev \ + openldap-dev \ + && adduser -S web + +RUN sudo -u $APP_USER -H git clone --depth=1 \ + https://github.com/thomasDOTde/PowerDNS-Admin $APP_PATH + +RUN pip install -r $APP_PATH/requirements.txt +COPY docker-entrypoint.sh /docker-entrypoint.sh + + +USER $APP_USER +WORKDIR $APP_PATH +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["python", "run.py"] +EXPOSE 9393 +VOLUME ["/var/log"] diff --git a/docker/PowerDNS-Admin/docker-entrypoint.sh b/docker/PowerDNS-Admin/docker-entrypoint.sh new file mode 100755 index 0000000..58daa7a --- /dev/null +++ b/docker/PowerDNS-Admin/docker-entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +set -e + +if [ "$WAITFOR_DB" -a ! -f "$APP_PATH/config.py" ]; then + cp "$APP_PATH/config_template_docker.py" "$APP_PATH/config.py" +fi + +cd $APP_PATH && python create_db.py + +# Start PowerDNS Admin +exec "$@" From 41b51733c8ab65a0cc17693d1a2d35e8b909b1ec Mon Sep 17 00:00:00 2001 From: Jeroen Boonstra Date: Wed, 28 Mar 2018 11:31:18 +0200 Subject: [PATCH 5/7] Basic build script for containers. --- docker/build-images.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 docker/build-images.sh diff --git a/docker/build-images.sh b/docker/build-images.sh new file mode 100755 index 0000000..a9f759f --- /dev/null +++ b/docker/build-images.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +IMAGES=(PowerDNS-MySQL PowerDNS-Admin) +for IMAGE in "${IMAGES[@]}" + do + echo building $(basename $IMAGE | tr '[A-Z]' '[a-z]') + cd $IMAGE + docker build -t $(basename $IMAGE | tr '[A-Z]' '[a-z]') . + cd .. +done From cc12ae20ee848759e6d2df2d34fbf5f6cfaa0658 Mon Sep 17 00:00:00 2001 From: Jeroen Boonstra Date: Wed, 28 Mar 2018 11:33:13 +0200 Subject: [PATCH 6/7] Add basic readme. --- docker/DOCKER.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 docker/DOCKER.md diff --git a/docker/DOCKER.md b/docker/DOCKER.md new file mode 100644 index 0000000..c5dd6f0 --- /dev/null +++ b/docker/DOCKER.md @@ -0,0 +1,29 @@ +# Docker support +This is a updated version of the current docker support. +Container support is only for development purposes and should not be used in production without your own modificatins. + +It's not needed to reload the container after you make changes in your current branch. + +Images are currently not available in docker hub or other repository, so you have to build them yourself. + +After a successful launch PowerDNS-Admin is reachable at http://localhost:9393 + +PowerDNS runs op port localhost upd/5353 + + +## Basic commands: +### Build images +cd to this directory + +```# ./build-images.sh``` + +### Run containers +Build the images before you run this command. + +```# docker-compose up``` + +### Stop containers +```# docker-compose stop``` + +### Remove containers +```# docker-compose rm``` From 8b8d0420e2049039852b72a8124ed75f885f9a97 Mon Sep 17 00:00:00 2001 From: Jeroen Boonstra Date: Wed, 28 Mar 2018 12:10:12 +0200 Subject: [PATCH 7/7] fixed typo udp --- docker/DOCKER.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/DOCKER.md b/docker/DOCKER.md index c5dd6f0..196beba 100644 --- a/docker/DOCKER.md +++ b/docker/DOCKER.md @@ -8,7 +8,7 @@ Images are currently not available in docker hub or other repository, so you hav After a successful launch PowerDNS-Admin is reachable at http://localhost:9393 -PowerDNS runs op port localhost upd/5353 +PowerDNS runs op port localhost udp/5353 ## Basic commands: