From 8469c51c7d165711c79c58cdcbf345b84c65845d Mon Sep 17 00:00:00 2001 From: Peter Schiffer Date: Wed, 21 Nov 2018 01:31:02 +0100 Subject: [PATCH] Add ngoduykhanh version pdns admin --- ansible-playbook.yml | 18 ++++-- pdns-admin-static-ngoduykhanh/Dockerfile | 10 ++++ pdns-admin-static-ngoduykhanh/pdns-nginx.conf | 59 +++++++++++++++++++ pdns-admin-uwsgi-ngoduykhanh/Dockerfile | 18 ++++++ pdns-admin-uwsgi-ngoduykhanh/docker-cmd.sh | 55 +++++++++++++++++ pdns-admin-uwsgi-ngoduykhanh/pdns-admin.ini | 21 +++++++ 6 files changed, 177 insertions(+), 4 deletions(-) create mode 100644 pdns-admin-static-ngoduykhanh/Dockerfile create mode 100644 pdns-admin-static-ngoduykhanh/pdns-nginx.conf create mode 100644 pdns-admin-uwsgi-ngoduykhanh/Dockerfile create mode 100755 pdns-admin-uwsgi-ngoduykhanh/docker-cmd.sh create mode 100644 pdns-admin-uwsgi-ngoduykhanh/pdns-admin.ini diff --git a/ansible-playbook.yml b/ansible-playbook.yml index d40aaed..dfd2ad5 100644 --- a/ansible-playbook.yml +++ b/ansible-playbook.yml @@ -134,12 +134,22 @@ tags: - pdns + - name: build pdns-admin base + docker_image: + name: pschiffe/pdns-admin-base + tag: ngoduykhanh + state: '{{ i_state }}' + force: true + path: ./pdns-admin-base-ngoduykhanh + tags: + - pdns-admin + - name: build pdns-admin backend docker_image: name: my-pdns-admin-uwsgi state: '{{ i_state }}' force: true - path: ./pdns-admin-uwsgi + path: ./pdns-admin-uwsgi-ngoduykhanh tags: - pdns-admin @@ -148,7 +158,7 @@ name: my-pdns-admin-static state: '{{ i_state }}' force: true - path: ./pdns-admin-static + path: ./pdns-admin-static-ngoduykhanh tags: - pdns-admin @@ -167,8 +177,8 @@ - pdns-admin-upload:/opt/powerdns-admin/upload env: PDNS_ADMIN_SQLA_DB_PASSWORD: "'my-secret-pw'" - PDNS_ADMIN_PDNS_VERSION: "'4.0'" - PDNS_ADMIN_PDNS_API_KEY: "'secret'" + PDNS_VERSION: "4.1" + PDNS_API_KEY: "secret" tags: - pdns-admin diff --git a/pdns-admin-static-ngoduykhanh/Dockerfile b/pdns-admin-static-ngoduykhanh/Dockerfile new file mode 100644 index 0000000..ff6aa25 --- /dev/null +++ b/pdns-admin-static-ngoduykhanh/Dockerfile @@ -0,0 +1,10 @@ +FROM pschiffe/pdns-admin-base:ngoduykhanh +MAINTAINER "Peter Schiffer" + +RUN dnf -y --setopt=install_weak_deps=False install \ + nginx \ + && dnf clean all + +COPY pdns-nginx.conf /etc/nginx/nginx.conf + +CMD [ "/usr/sbin/nginx", "-g", "daemon off;" ] diff --git a/pdns-admin-static-ngoduykhanh/pdns-nginx.conf b/pdns-admin-static-ngoduykhanh/pdns-nginx.conf new file mode 100644 index 0000000..4643de7 --- /dev/null +++ b/pdns-admin-static-ngoduykhanh/pdns-nginx.conf @@ -0,0 +1,59 @@ +user nginx; +worker_processes auto; +error_log stderr; +pid /run/nginx.pid; + +# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. +include /usr/share/nginx/modules/*.conf; + +events { + worker_connections 1024; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /dev/stdout main; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 4096; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + # Load modular configuration files from the /etc/nginx/conf.d directory. + # See http://nginx.org/en/docs/ngx_core_module.html#include + # for more information. + include /etc/nginx/conf.d/*.conf; + + server { + listen 80 default_server; + server_name _; + + location /static/ { + alias /opt/powerdns-admin/app/static/; + } + + location / { + try_files $uri @pdns_admin; + } + + location @pdns_admin { + include uwsgi_params; + uwsgi_pass pdns-admin-uwsgi:9494; + } + + error_page 404 /404.html; + location = /40x.html { + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + } + } +} diff --git a/pdns-admin-uwsgi-ngoduykhanh/Dockerfile b/pdns-admin-uwsgi-ngoduykhanh/Dockerfile new file mode 100644 index 0000000..277ea8e --- /dev/null +++ b/pdns-admin-uwsgi-ngoduykhanh/Dockerfile @@ -0,0 +1,18 @@ +FROM pschiffe/pdns-admin-base:ngoduykhanh +MAINTAINER "Peter Schiffer" + +RUN dnf -y --setopt=install_weak_deps=False install \ + mariadb \ + uwsgi-plugin-python3 \ + && dnf clean all + +COPY docker-cmd.sh / + +EXPOSE 9494 + +VOLUME [ "/opt/powerdns-admin/upload" ] + +COPY pdns-admin.ini /etc/uwsgi.d/ +RUN chown uwsgi: /etc/uwsgi.d/pdns-admin.ini + +CMD [ "/docker-cmd.sh" ] diff --git a/pdns-admin-uwsgi-ngoduykhanh/docker-cmd.sh b/pdns-admin-uwsgi-ngoduykhanh/docker-cmd.sh new file mode 100755 index 0000000..6ede106 --- /dev/null +++ b/pdns-admin-uwsgi-ngoduykhanh/docker-cmd.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +set -euo pipefail + +# Configure mysql env vars +: "${PDNS_ADMIN_SQLA_DB_HOST:='mysql'}" +: "${PDNS_ADMIN_SQLA_DB_PORT:='3306'}" +: "${PDNS_ADMIN_SQLA_DB_USER:='${MYSQL_ENV_MYSQL_USER:-root}'}" +if [ "${PDNS_ADMIN_SQLA_DB_USER}" = "'root'" ]; then + : "${PDNS_ADMIN_SQLA_DB_PASSWORD:='$MYSQL_ENV_MYSQL_ROOT_PASSWORD'}" +fi +: "${PDNS_ADMIN_SQLA_DB_PASSWORD:='${MYSQL_ENV_MYSQL_PASSWORD:-powerdnsadmin}'}" +: "${PDNS_ADMIN_SQLA_DB_NAME:='${MYSQL_ENV_MYSQL_DATABASE:-powerdnsadmin}'}" + +export PDNS_ADMIN_SQLA_DB_HOST PDNS_ADMIN_SQLA_DB_PORT PDNS_ADMIN_SQLA_DB_USER PDNS_ADMIN_SQLA_DB_PASSWORD PDNS_ADMIN_SQLA_DB_NAME + +# Configure pdns server env vars +: "${PDNS_API_URL:=http://pdns:${PDNS_ENV_PDNS_webserver_port:-8081}/}" +: "${PDNS_API_KEY:=${PDNS_ENV_PDNS_api_key:-}}" +: "${PDNS_VERSION:=${PDNS_ENV_VERSION:-}}" + +# Generate secret key +[ -f /root/secret-key ] || tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 32 > /root/secret-key || true +PDNS_ADMIN_SECRET_KEY="'$(cat /root/secret-key)'" + +export PDNS_ADMIN_SECRET_KEY + +envtpl < /config.py.tpl > /opt/powerdns-admin/config.py + +# Initialize DB if needed +MYSQL_COMMAND="mysql -h ${PDNS_ADMIN_SQLA_DB_HOST//\'/} -P ${PDNS_ADMIN_SQLA_DB_PORT//\'/} -u ${PDNS_ADMIN_SQLA_DB_USER//\'/} -p${PDNS_ADMIN_SQLA_DB_PASSWORD//\'/}" + +until $MYSQL_COMMAND -e ';' ; do + >&2 echo 'MySQL is unavailable - sleeping' + sleep 1 +done + +$MYSQL_COMMAND -e "CREATE DATABASE IF NOT EXISTS ${PDNS_ADMIN_SQLA_DB_NAME//\'/}" + +flask db upgrade + +# initial settings if not available in the DB +$MYSQL_COMMAND ${PDNS_ADMIN_SQLA_DB_NAME//\'/} -e "INSERT INTO setting (name, value) SELECT * FROM (SELECT 'pdns_api_url', '${PDNS_API_URL}') AS tmp WHERE NOT EXISTS (SELECT name FROM setting WHERE name = 'pdns_api_url') LIMIT 1;" +$MYSQL_COMMAND ${PDNS_ADMIN_SQLA_DB_NAME//\'/} -e "INSERT INTO setting (name, value) SELECT * FROM (SELECT 'pdns_api_key', '${PDNS_API_KEY}') AS tmp WHERE NOT EXISTS (SELECT name FROM setting WHERE name = 'pdns_api_key') LIMIT 1;" +$MYSQL_COMMAND ${PDNS_ADMIN_SQLA_DB_NAME//\'/} -e "INSERT INTO setting (name, value) SELECT * FROM (SELECT 'pdns_version', '${PDNS_VERSION}') AS tmp WHERE NOT EXISTS (SELECT name FROM setting WHERE name = 'pdns_version') LIMIT 1;" + +# update pdns api settings if env changed +$MYSQL_COMMAND ${PDNS_ADMIN_SQLA_DB_NAME//\'/} -e "UPDATE setting SET value='${PDNS_API_URL}' WHERE name='pdns_api_url';" +$MYSQL_COMMAND ${PDNS_ADMIN_SQLA_DB_NAME//\'/} -e "UPDATE setting SET value='${PDNS_API_KEY}' WHERE name='pdns_api_key';" +$MYSQL_COMMAND ${PDNS_ADMIN_SQLA_DB_NAME//\'/} -e "UPDATE setting SET value='${PDNS_VERSION}' WHERE name='pdns_version';" + +mkdir -p /run/uwsgi +chown uwsgi: /run/uwsgi + +exec /usr/sbin/uwsgi --ini /etc/uwsgi.ini diff --git a/pdns-admin-uwsgi-ngoduykhanh/pdns-admin.ini b/pdns-admin-uwsgi-ngoduykhanh/pdns-admin.ini new file mode 100644 index 0000000..10986e7 --- /dev/null +++ b/pdns-admin-uwsgi-ngoduykhanh/pdns-admin.ini @@ -0,0 +1,21 @@ +[uwsgi] +plugins = python3 + +uid = uwsgi +gid = uwsgi + +chdir = /opt/powerdns-admin +pythonpath = /opt/powerdns-admin + +mount = /=run.py +manage-script-name = true +callable = app + +vacuum = true +harakiri = 20 +buffer-size = 8192 +post-buffering = 8192 +socket = 0.0.0.0:9494 +pidfile = /run/uwsgi/%n.pid + +enable-threads = true