Replace envtpl with subvars for less deps

Fixes #71
This commit is contained in:
Peter Schiffer 2023-12-19 18:25:44 +01:00
parent 3c7bada92b
commit 5427e1e1fc
11 changed files with 42 additions and 32 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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