diff --git a/docker-compose.yml b/docker-compose.yml index 4c9ec5c..08925ec 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,6 +30,7 @@ services: - PDA_DB_PASSWORD=${PDA_DB_PASSWORD} - PDNS_HOST=${PDNS_HOST} - PDNS_API_KEY=${PDNS_API_KEY} + - FLASK_APP=/powerdns-admin/app/__init__.py depends_on: powerdns-admin-mysql: condition: service_healthy diff --git a/docker/PowerDNS-Admin/Dockerfile b/docker/PowerDNS-Admin/Dockerfile index bb6c51f..09b37dc 100644 --- a/docker/PowerDNS-Admin/Dockerfile +++ b/docker/PowerDNS-Admin/Dockerfile @@ -1,11 +1,17 @@ FROM ubuntu:latest -MAINTAINER Khanh Ngo "ngokhanhit@gmail.com" +MAINTAINER Khanh Ngo "k@ndk.name" ARG ENVIRONMENT=development ENV ENVIRONMENT=${ENVIRONMENT} WORKDIR /powerdns-admin RUN apt-get update -y + +RUN apt-get install -y locales locales-all +ENV LC_ALL en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US.UTF-8 + RUN apt-get install -y python3-pip python3-dev supervisor # lib for building mysql db driver diff --git a/docker/PowerDNS-Admin/entrypoint.sh b/docker/PowerDNS-Admin/entrypoint.sh index f041308..7bdb0b0 100755 --- a/docker/PowerDNS-Admin/entrypoint.sh +++ b/docker/PowerDNS-Admin/entrypoint.sh @@ -1,3 +1,14 @@ #!/bin/sh -cd /powerdns-admin && ./create_db.py + +if [ ! -d "/powerdns-admin/migrations" ]; then + /usr/local/bin/flask db init --directory /powerdns-admin/migrations + /usr/local/bin/flask db migrate -m "Init DB" --directory /powerdns-admin/migrations + /usr/local/bin/flask db upgrade --directory /powerdns-admin/migrations + cd /powerdns-admin && ./init_data.py + +else + /usr/local/bin/flask db migrate -m "Upgrade BD Schema" --directory /powerdns-admin/migrations + /usr/local/bin/flask db upgrade --directory /powerdns-admin/migrations +fi + /usr/bin/supervisord -c /etc/supervisord.conf diff --git a/init_data.py b/init_data.py new file mode 100755 index 0000000..dbd3277 --- /dev/null +++ b/init_data.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +from app import app, db +from app.models import Role, Setting, DomainTemplate + +admin_role = Role(name='Administrator', description='Administrator') +user_role = Role(name='User', description='User') + +setting_1 = Setting(name='maintenance', value='False') +setting_2 = Setting(name='fullscreen_layout', value='True') +setting_3 = Setting(name='record_helper', value='True') +setting_4 = Setting(name='login_ldap_first', value='True') +setting_5 = Setting(name='default_record_table_size', value='15') +setting_6 = Setting(name='default_domain_table_size', value='10') +setting_7 = Setting(name='auto_ptr', value='False') + +template_1 = DomainTemplate(name='basic_template_1', description='Basic Template #1') +template_2 = DomainTemplate(name='basic_template_2', description='Basic Template #2') +template_3 = DomainTemplate(name='basic_template_3', description='Basic Template #3') + +db.session.add(admin_role) +db.session.add(user_role) + +db.session.add(setting_1) +db.session.add(setting_2) +db.session.add(setting_3) +db.session.add(setting_4) +db.session.add(setting_5) +db.session.add(setting_6) +db.session.add(setting_7) + +db.session.add(template_1) +db.session.add(template_2) +db.session.add(template_3) + +db.session.commit()