Merge pull request #250 from ngoduykhanh/docker

Use new docker compose file
This commit is contained in:
Khanh Ngo 2018-04-18 10:51:13 +07:00 committed by GitHub
commit 6a91a8e114
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 150 additions and 369 deletions

15
.env Normal file
View File

@ -0,0 +1,15 @@
ENVIRONMENT=development
PDA_DB_HOST=powerdns-admin-mysql
PDA_DB_NAME=powerdns_admin
PDA_DB_USER=powerdns_admin
PDA_DB_PASSWORD=changeme
PDNS_DB_HOST=pdns-mysql
PDNS_DB_NAME=pdns
PDNS_DB_USER=pdns
PDNS_DB_PASSWORD=changeme
PDNS_HOST=pdns-server
PDNS_API_KEY=changeme
PDNS_WEBSERVER_ALLOW_FROM=0.0.0.0

View File

@ -1,26 +0,0 @@
FROM ubuntu:latest
MAINTAINER Khanh Ngo "ngokhanhit@gmail.com"
ARG ENVIRONMENT=development
ENV ENVIRONMENT=${ENVIRONMENT}
WORKDIR /powerdns-admin
RUN apt-get update -y
RUN apt-get install -y python3-pip python3-dev supervisor
# lib for building mysql db driver
RUN apt-get install -y libmysqlclient-dev
# lib for buiding ldap and ssl-based application
RUN apt-get install -y libsasl2-dev libldap2-dev libssl-dev
# lib for building python3-saml
RUN apt-get install -y libxml2-dev libxslt1-dev libxmlsec1-dev libffi-dev pkg-config
COPY ./requirements.txt /powerdns-admin/requirements.txt
RUN pip3 install -r requirements.txt
ADD ./supervisord.conf /etc/supervisord.conf
ADD . /powerdns-admin/
COPY ./configs/${ENVIRONMENT}.py /powerdns-admin/config.py

View File

@ -17,57 +17,23 @@ A PowerDNS web interface with advanced features.
- DynDNS 2 protocol support
- Edit IPv6 PTRs using IPv6 addresses directly (no more editing of literal addresses!)
## Setup
### PowerDNS Version Support:
PowerDNS-Admin supports PowerDNS autoritative server versions **3.4.2** and higher.
### pdns Service
I assume that you have already installed pdns service. Make sure that your `pdns.conf` config file has these contents
PowerDNS 4.0.0 and later
```
api=yes
api-key=your-powerdns-api-key
webserver=yes
```
PowerDNS before 4.0.0
```
experimental-json-interface=yes
experimental-api-key=your-powerdns-api-key
webserver=yes
```
This will enable API access in pdns service so PowerDNS-Admin can intergrate with it.
### Create Database
We will create a database which used by this web application. Please note that this database is difference from pdns database itself.
PowerDNS-Admin supports MySQL server, Maria DB, PostgresQL and SQL Lite.
```
MariaDB [(none)]> CREATE DATABASE powerdnsadmin;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON powerdnsadmin.* TO powerdnsadmin@'%' IDENTIFIED BY 'your-password';
```
### Running PowerDNS-Admin
There are several ways to run PowerDNS-Admin. Following is a simple way to start PowerDNS-Admin with docker in development environment.
There are several ways to run PowerDNS-Admin. Following is a simple way to start PowerDNS-Admin with docker in development environment which has PowerDNS-Admin, PowerDNS server and MySQL Back-End Database.
Firstly, let's edit `configs/developments.py` configuration file.
Step 1: Changing configuration
The configuration file for developement environment is located at `configs/development.py`, you can override some configs by editing `.env` file.
Secondly, build the docker image of PowerDNS-Admin
Step 2: Build docker images
``` $docker-compose -f docker-compose.dev.yml build```
```$ docker-compose build```
Finally, start it
Step 3: Start docker containers
```$ docker-compose -f docker-compose.dev.yml up```
```$ docker-compose up```
You can now access PowerDNS-Admin at url http://localhost:9191
NOTE: For other methods to run PowerDNS-Admin, please take look at WIKI pages.
**NOTE:** For other methods to run PowerDNS-Admin, please take look at WIKI pages.
### Screenshots
![login page](https://github.com/ngoduykhanh/PowerDNS-Admin/wiki/images/readme_screenshots/fullscreen-login.png?raw=true)

View File

@ -14,10 +14,10 @@ TIMEOUT = 10
UPLOAD_DIR = os.path.join(basedir, 'upload')
# DATABASE CONFIG FOR MYSQL
DB_USER = 'powerdnsadmin'
DB_PASSWORD = 'powerdnsadminpassword'
DB_HOST = 'docker.for.mac.localhost'
DB_NAME = 'powerdnsadmin'
DB_HOST = os.environ.get('PDA_DB_HOST')
DB_NAME = os.environ.get('PDA_DB_NAME')
DB_USER = os.environ.get('PDA_DB_USER')
DB_PASSWORD = os.environ.get('PDA_DB_PASSWORD')
#MySQL
SQLALCHEMY_DATABASE_URI = 'mysql://'+DB_USER+':'+DB_PASSWORD+'@'+DB_HOST+'/'+DB_NAME
@ -106,8 +106,8 @@ SAML_LOGOUT = False
# POWERDNS CONFIG
PDNS_STATS_URL = 'http://192.168.100.100:8081/'
PDNS_API_KEY = 'changeme'
PDNS_STATS_URL = 'http://{0}:8081'.format(os.environ.get('PDNS_HOST'))
PDNS_API_KEY = os.environ.get('PDNS_API_KEY')
PDNS_VERSION = '4.1.1'
# RECORDS ALLOWED TO EDIT

View File

@ -1,21 +0,0 @@
version: "2.1"
services:
powerdns-admin:
build:
context: .
dockerfile: Dockerfile
image: powerdns-admin
container_name: powerdns-admin
mem_limit: 256M
memswap_limit: 256M
command: /usr/bin/supervisord -c /etc/supervisord.conf
ports:
- "9191:9191"
volumes:
- .:/powerdns-admin/
- "./configs/development.py:/powerdns-admin/config.py"
logging:
driver: json-file
options:
max-size: 50m

97
docker-compose.yml Normal file
View File

@ -0,0 +1,97 @@
version: "2.1"
services:
powerdns-admin:
build:
context: .
dockerfile: docker/PowerDNS-Admin/Dockerfile
args:
- ENVIRONMENT=${ENVIRONMENT}
image: powerdns-admin
container_name: powerdns-admin
mem_limit: 256M
memswap_limit: 256M
ports:
- "9191:9191"
volumes:
- .:/powerdns-admin/
- "./configs/${ENVIRONMENT}.py:/powerdns-admin/config.py"
logging:
driver: json-file
options:
max-size: 50m
networks:
- default
environment:
- ENVIRONMENT=${ENVIRONMENT}
- PDA_DB_HOST=${PDA_DB_HOST}
- PDA_DB_NAME=${PDA_DB_NAME}
- PDA_DB_USER=${PDA_DB_USER}
- PDA_DB_PASSWORD=${PDA_DB_PASSWORD}
- PDNS_HOST=${PDNS_HOST}
- PDNS_API_KEY=${PDNS_API_KEY}
depends_on:
powerdns-admin-mysql:
condition: service_healthy
powerdns-admin-mysql:
image: mysql/mysql-server:5.7
hostname: ${PDA_DB_HOST}
container_name: powerdns-admin-mysql
mem_limit: 256M
memswap_limit: 256M
ports:
- "3306:3306"
networks:
- default
environment:
- MYSQL_DATABASE=${PDA_DB_NAME}
- MYSQL_USER=${PDA_DB_USER}
- MYSQL_PASSWORD=${PDA_DB_PASSWORD}
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 10s
retries: 5
pdns-server:
image: psitrax/powerdns
hostname: ${PDNS_HOST}
ports:
- "53:53"
networks:
- default
command: --api=yes --api-key=${PDNS_API_KEY} --webserver-address=0.0.0.0 --webserver-allow-from=0.0.0.0/0
environment:
- MYSQL_HOST=${PDNS_DB_HOST}
- MYSQL_USER=${PDNS_DB_USER}
- MYSQL_PASS=${PDNS_DB_PASSWORD}
- PDNS_API_KEY=${PDNS_API_KEY}
- PDNS_WEBSERVER_ALLOW_FROM=${PDNS_WEBSERVER_ALLOW_FROM}
depends_on:
pdns-mysql:
condition: service_healthy
pdns-mysql:
image: mysql/mysql-server:5.7
hostname: ${PDNS_DB_HOST}
container_name: ${PDNS_DB_HOST}
mem_limit: 256M
memswap_limit: 256M
ports:
- "3307:3306"
networks:
- default
environment:
- MYSQL_DATABASE=${PDNS_DB_NAME}
- MYSQL_USER=${PDNS_DB_USER}
- MYSQL_PASSWORD=${PDNS_DB_PASSWORD}
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 10s
retries: 5
networks:
default:
volumes:
powerdns-mysql-data:

View File

@ -1,29 +0,0 @@
# 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 udp/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```

View File

@ -1,42 +1,28 @@
# PowerDNS-Admin
# Original from:
# https://github.com/ngoduykhanh/PowerDNS-Admin
#
# Initial image by winggundamth(/powerdns-mysql:trusty)
#
#
FROM alpine
MAINTAINER Jeroen Boonstra <jeroen [at] provider.nl>
FROM ubuntu:latest
MAINTAINER Khanh Ngo "ngokhanhit@gmail.com"
ARG ENVIRONMENT=development
ENV ENVIRONMENT=${ENVIRONMENT}
ENV APP_USER=web APP_NAME=powerdns-admin
ENV APP_PATH=/home/$APP_USER/$APP_NAME
WORKDIR /powerdns-admin
RUN apt-get update -y
RUN apt-get install -y python3-pip python3-dev supervisor
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
# lib for building mysql db driver
RUN apt-get install -y libmysqlclient-dev
RUN sudo -u $APP_USER -H git clone --depth=1 \
https://github.com/thomasDOTde/PowerDNS-Admin $APP_PATH
# lib for buiding ldap and ssl-based application
RUN apt-get install -y libsasl2-dev libldap2-dev libssl-dev
RUN pip install -r $APP_PATH/requirements.txt
COPY docker-entrypoint.sh /docker-entrypoint.sh
# lib for building python3-saml
RUN apt-get install -y libxml2-dev libxslt1-dev libxmlsec1-dev libffi-dev pkg-config
COPY ./requirements.txt /powerdns-admin/requirements.txt
RUN pip3 install -r requirements.txt
USER $APP_USER
WORKDIR $APP_PATH
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["python", "run.py"]
EXPOSE 9393
VOLUME ["/var/log"]
ADD ./supervisord.conf /etc/supervisord.conf
ADD . /powerdns-admin/
COPY ./configs/${ENVIRONMENT}.py /powerdns-admin/config.py
COPY ./docker/PowerDNS-Admin/entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

View File

@ -1,12 +0,0 @@
#!/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 "$@"

View File

@ -0,0 +1,3 @@
#!/bin/sh
cd /powerdns-admin && ./create_db.py
/usr/bin/supervisord -c /etc/supervisord.conf

View File

@ -1,40 +0,0 @@
# 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 <w [at] winginfotech.net>
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"]

View File

@ -1,3 +0,0 @@
Package: pdns-*
Pin: origin repo.powerdns.com
Pin-Priority: 600

View File

@ -1,6 +0,0 @@
launch+=gmysql
gmysql-port=3306
gmysql-host=172.17.0.1
gmysql-password=CHANGEME
gmysql-user=powerdns
gmysql-dbname=powerdns

View File

@ -1,89 +0,0 @@
#!/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 "$@"

View File

@ -1,10 +0,0 @@
#!/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

View File

@ -1,50 +0,0 @@
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