From 5427e1e1fc0ffd072c96cffda2c496b5c98c39a1 Mon Sep 17 00:00:00 2001 From: Peter Schiffer <3899107+pschiffe@users.noreply.github.com> Date: Tue, 19 Dec 2023 18:25:44 +0100 Subject: [PATCH] Replace envtpl with subvars for less deps Fixes #71 --- pdns-admin-base-ngoduykhanh/Dockerfile | 9 +++++++-- pdns-admin-base-ngoduykhanh/config.py.tpl | 17 ++++++++--------- .../docker-entrypoint.sh | 2 +- pdns-recursor/Dockerfile | 7 ++++--- pdns-recursor/Dockerfile.alpine | 9 +++++---- pdns-recursor/docker-entrypoint.sh | 2 +- pdns-recursor/recursor.conf.tpl | 5 +++-- pdns/Dockerfile | 7 ++++--- pdns/Dockerfile.alpine | 9 +++++---- pdns/docker-entrypoint.sh | 2 +- pdns/pdns.conf.tpl | 5 +++-- 11 files changed, 42 insertions(+), 32 deletions(-) diff --git a/pdns-admin-base-ngoduykhanh/Dockerfile b/pdns-admin-base-ngoduykhanh/Dockerfile index ea462c9..8919b4a 100644 --- a/pdns-admin-base-ngoduykhanh/Dockerfile +++ b/pdns-admin-base-ngoduykhanh/Dockerfile @@ -17,6 +17,11 @@ RUN curl -sSL -o /etc/yum.repos.d/yarn.repo https://dl.yarnpkg.com/rpm/yarn.repo yarn \ && dnf clean all +RUN arch=$([ "$(arch)" = 'aarch64' ] && echo -n 'arm64' || echo -n 'x86_64') \ + && curl -fsSL https://github.com/kha7iq/subvars/releases/download/v0.1.4/subvars_Linux_${arch}.tar.gz \ + | tar -xzf - -C /usr/local/bin subvars \ + && chmod +x /usr/local/bin/subvars + RUN mkdir -p /opt/powerdns-admin \ && curl -sSL https://github.com/PowerDNS-Admin/PowerDNS-Admin/archive/refs/tags/v0.4.1.tar.gz \ | tar -xzC /opt/powerdns-admin --strip 1 \ @@ -31,7 +36,7 @@ RUN mkdir -p /opt/powerdns-admin \ WORKDIR /opt/powerdns-admin -RUN pip3 install --no-cache-dir envtpl python-dotenv \ +RUN pip3 install --no-cache-dir python-dotenv \ && pip3 install -r requirements.txt --no-cache-dir ENV FLASK_APP=/opt/powerdns-admin/powerdnsadmin/__init__.py @@ -39,7 +44,7 @@ ENV FLASK_APP=/opt/powerdns-admin/powerdnsadmin/__init__.py COPY config.py.tpl / COPY run.py . -RUN envtpl < /config.py.tpl > /opt/powerdns-admin/config.py \ +RUN subvars --prefix 'PDNS_ADMIN_' < /config.py.tpl > /opt/powerdns-admin/config.py \ && sed -i '/SQLALCHEMY_DATABASE_URI/d' /opt/powerdns-admin/config.py RUN yarn install --pure-lockfile --production \ diff --git a/pdns-admin-base-ngoduykhanh/config.py.tpl b/pdns-admin-base-ngoduykhanh/config.py.tpl index b5a38b8..edd3658 100644 --- a/pdns-admin-base-ngoduykhanh/config.py.tpl +++ b/pdns-admin-base-ngoduykhanh/config.py.tpl @@ -19,15 +19,14 @@ SESSION_TYPE = 'sqlalchemy' SAML_ENABLED = False # Configuration from env vars -{%- for key, value in environment('PDNS_ADMIN_') %} -{%- set v = value | trim('"\'\\') %} -{%- if v in ['True', 'False', 'None', '0'] or v | int != 0 %} -{{ key }} = {{ v }} -{%- else %} -{{ key }} = '{{ v }}' -{%- endif %} -{%- endfor %} - +{{ range $key, $value := match "PDNS_ADMIN_" -}} +{{ $v := $value | trimAll "\"'\\" -}} +{{ if or (eq $v "True" "False" "None" "0") (ne ($v | int) 0) -}} +{{- $key | trimPrefix "PDNS_ADMIN_" }} = {{ $v }} +{{ else -}} +{{- $key | trimPrefix "PDNS_ADMIN_" }} = '{{ $v }}' +{{ end -}} +{{ end }} ### DATABASE CONFIG SQLALCHEMY_DATABASE_URI = 'mysql://' + SQLA_DB_USER + ':' + SQLA_DB_PASSWORD + '@' + SQLA_DB_HOST + ':' + str(SQLA_DB_PORT) + '/' + SQLA_DB_NAME SQLALCHEMY_TRACK_MODIFICATIONS = True diff --git a/pdns-admin-uwsgi-ngoduykhanh/docker-entrypoint.sh b/pdns-admin-uwsgi-ngoduykhanh/docker-entrypoint.sh index 33d4376..b3e2fd8 100755 --- a/pdns-admin-uwsgi-ngoduykhanh/docker-entrypoint.sh +++ b/pdns-admin-uwsgi-ngoduykhanh/docker-entrypoint.sh @@ -32,7 +32,7 @@ PDNS_ADMIN_SECRET_KEY="$(cat /root/secret-key)" export PDNS_ADMIN_SECRET_KEY -envtpl < /config.py.tpl > /opt/powerdns-admin/powerdnsadmin/default_config.py +subvars --prefix 'PDNS_ADMIN_' < /config.py.tpl > /opt/powerdns-admin/powerdnsadmin/default_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}" diff --git a/pdns-recursor/Dockerfile b/pdns-recursor/Dockerfile index c4b2572..de37ad9 100644 --- a/pdns-recursor/Dockerfile +++ b/pdns-recursor/Dockerfile @@ -2,11 +2,12 @@ FROM fedora:39 RUN dnf -y --setopt=install_weak_deps=False install \ pdns-recursor \ - python3-pip \ - python3-setuptools \ && dnf clean all -RUN pip3 install --no-cache-dir envtpl +RUN arch=$([ "$(arch)" = 'aarch64' ] && echo -n 'arm64' || echo -n 'x86_64') \ + && curl -fsSL https://github.com/kha7iq/subvars/releases/download/v0.1.4/subvars_Linux_${arch}.tar.gz \ + | tar -xzf - -C /usr/local/bin subvars \ + && chmod +x /usr/local/bin/subvars RUN mkdir -p /etc/pdns-recursor/api.d \ && chown -R pdns-recursor: /etc/pdns-recursor/api.d \ diff --git a/pdns-recursor/Dockerfile.alpine b/pdns-recursor/Dockerfile.alpine index b059753..4198b91 100644 --- a/pdns-recursor/Dockerfile.alpine +++ b/pdns-recursor/Dockerfile.alpine @@ -1,11 +1,12 @@ FROM alpine:3.19.0 RUN apk add --no-cache \ - pdns-recursor \ - py3-pip \ - python3 + pdns-recursor -RUN pip3 install --no-cache-dir --break-system-packages envtpl +RUN arch=$([ "$(arch)" = 'aarch64' ] && echo -n 'arm64' || echo -n 'x86_64') \ + && wget -qO- https://github.com/kha7iq/subvars/releases/download/v0.1.4/subvars_Linux_${arch}.tar.gz \ + | tar -xzf - -C /usr/local/bin subvars \ + && chmod +x /usr/local/bin/subvars RUN mkdir -p /etc/pdns/api.d \ && chown -R recursor: /etc/pdns/api.d \ diff --git a/pdns-recursor/docker-entrypoint.sh b/pdns-recursor/docker-entrypoint.sh index c0dfdc4..de307b1 100755 --- a/pdns-recursor/docker-entrypoint.sh +++ b/pdns-recursor/docker-entrypoint.sh @@ -18,7 +18,7 @@ elif [ -f /etc/alpine-release ]; then fi # Create config file from template -envtpl < /recursor.conf.tpl > $config_file +subvars --prefix 'PDNS_' < /recursor.conf.tpl > $config_file # Fix config file ownership chown ${pdns_user}: $config_file diff --git a/pdns-recursor/recursor.conf.tpl b/pdns-recursor/recursor.conf.tpl index 8330f43..e4e181e 100644 --- a/pdns-recursor/recursor.conf.tpl +++ b/pdns-recursor/recursor.conf.tpl @@ -1,2 +1,3 @@ -{% for key, value in environment('PDNS_') %}{{ key|replace('_', '-') }}={{ value }} -{% endfor %} +{{ range $key, $value := match "PDNS_" -}} +{{- $key | trimPrefix "PDNS_" | replace "_" "-" }} = {{ $value }} +{{ end -}} diff --git a/pdns/Dockerfile b/pdns/Dockerfile index 6d7123f..85a683c 100644 --- a/pdns/Dockerfile +++ b/pdns/Dockerfile @@ -6,11 +6,12 @@ RUN sed -i '/tsflags=nodocs/d' /etc/dnf/dnf.conf \ mariadb \ pdns \ pdns-backend-mysql \ - python3-pip \ - python3-setuptools \ && dnf clean all -RUN pip3 install --no-cache-dir envtpl +RUN arch=$([ "$(arch)" = 'aarch64' ] && echo -n 'arm64' || echo -n 'x86_64') \ + && curl -fsSL https://github.com/kha7iq/subvars/releases/download/v0.1.4/subvars_Linux_${arch}.tar.gz \ + | tar -xzf - -C /usr/local/bin subvars \ + && chmod +x /usr/local/bin/subvars ENV VERSION=4.8 \ PDNS_guardian=yes \ diff --git a/pdns/Dockerfile.alpine b/pdns/Dockerfile.alpine index aada50c..4766497 100644 --- a/pdns/Dockerfile.alpine +++ b/pdns/Dockerfile.alpine @@ -4,11 +4,12 @@ RUN apk add --no-cache \ mariadb-client \ pdns \ pdns-backend-mysql \ - pdns-doc \ - py3-pip \ - python3 + pdns-doc -RUN pip3 install --no-cache-dir --break-system-packages envtpl +RUN arch=$([ "$(arch)" = 'aarch64' ] && echo -n 'arm64' || echo -n 'x86_64') \ + && wget -qO- https://github.com/kha7iq/subvars/releases/download/v0.1.4/subvars_Linux_${arch}.tar.gz \ + | tar -xzf - -C /usr/local/bin subvars \ + && chmod +x /usr/local/bin/subvars ENV VERSION=4.8 \ PDNS_guardian=yes \ diff --git a/pdns/docker-entrypoint.sh b/pdns/docker-entrypoint.sh index 8621c87..00dcf45 100755 --- a/pdns/docker-entrypoint.sh +++ b/pdns/docker-entrypoint.sh @@ -85,6 +85,6 @@ if [ "${PDNS_superslave:-no}" == "yes" ]; then fi # Create config file from template -envtpl < /pdns.conf.tpl > /etc/pdns/pdns.conf +subvars --prefix 'PDNS_' < /pdns.conf.tpl > /etc/pdns/pdns.conf exec "$@" diff --git a/pdns/pdns.conf.tpl b/pdns/pdns.conf.tpl index 8330f43..e4e181e 100644 --- a/pdns/pdns.conf.tpl +++ b/pdns/pdns.conf.tpl @@ -1,2 +1,3 @@ -{% for key, value in environment('PDNS_') %}{{ key|replace('_', '-') }}={{ value }} -{% endfor %} +{{ range $key, $value := match "PDNS_" -}} +{{- $key | trimPrefix "PDNS_" | replace "_" "-" }} = {{ $value }} +{{ end -}}