Skip to content

Commit

Permalink
Replace envtpl with subvars for less deps
Browse files Browse the repository at this point in the history
Fixes #71
  • Loading branch information
pschiffe committed Dec 19, 2023
1 parent 3c7bada commit 5427e1e
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 32 deletions.
9 changes: 7 additions & 2 deletions pdns-admin-base-ngoduykhanh/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -31,15 +36,15 @@ 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

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 \
Expand Down
17 changes: 8 additions & 9 deletions pdns-admin-base-ngoduykhanh/config.py.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion pdns-admin-uwsgi-ngoduykhanh/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
7 changes: 4 additions & 3 deletions pdns-recursor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
9 changes: 5 additions & 4 deletions pdns-recursor/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion pdns-recursor/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pdns-recursor/recursor.conf.tpl
Original file line number Diff line number Diff line change
@@ -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 -}}
7 changes: 4 additions & 3 deletions pdns/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
9 changes: 5 additions & 4 deletions pdns/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion pdns/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
5 changes: 3 additions & 2 deletions pdns/pdns.conf.tpl
Original file line number Diff line number Diff line change
@@ -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 -}}

0 comments on commit 5427e1e

Please sign in to comment.