Add ngoduykhanh version pdns admin

This commit is contained in:
Peter Schiffer 2018-11-21 01:31:02 +01:00
parent 52a425c3a5
commit 8469c51c7d
No known key found for this signature in database
GPG key ID: 6CCC5046E2B0B44B
6 changed files with 177 additions and 4 deletions

View file

@ -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

View file

@ -0,0 +1,10 @@
FROM pschiffe/pdns-admin-base:ngoduykhanh
MAINTAINER "Peter Schiffer" <peter@rfv.sk>
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;" ]

View file

@ -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 {
}
}
}

View file

@ -0,0 +1,18 @@
FROM pschiffe/pdns-admin-base:ngoduykhanh
MAINTAINER "Peter Schiffer" <peter@rfv.sk>
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" ]

View file

@ -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

View file

@ -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