From b9f32dd3b45e9e0dde47c1dfbce0b25d71016c37 Mon Sep 17 00:00:00 2001 From: Ryan Hamilton Date: Tue, 12 Aug 2025 08:24:45 -0500 Subject: [PATCH] fix Apache configuration and entrypoint script logic --- Dockerfile | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 36815a2..b1bbe1c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,33 +44,42 @@ COPY --from=source /src/app/ /var/www/html/daloradius/ COPY --from=source /src/app/common/includes/daloradius.conf.php.sample /opt/daloradius.conf.php.tmpl COPY --from=source /src/contrib/scripts/apache-config.sh /usr/local/bin/apache-config.sh -# Apache + perms +# Apache + perms (+ run helper to set DocumentRoot=/var/www/html/daloradius) RUN chown -R www-data:www-data /var/www/html && \ chmod +x /usr/local/bin/apache-config.sh && \ - a2enmod rewrite + a2enmod rewrite && \ + /usr/local/bin/apache-config.sh && \ + printf 'ServerName localhost\n' > /etc/apache2/conf-available/servername.conf && a2enconf servername -# Entry script renders config from env + +# Entry script renders config from env only if not bind-mounted or if forced COPY <<'EOF' /entrypoint.sh #!/usr/bin/env bash set -euo pipefail -: "${DBHOST:?set DBHOST}" -: "${DBNAME:?set DBNAME}" -: "${DBUSER:?set DBUSER}" -: "${DBPASS:?set DBPASS}" +CFG="/var/www/html/daloradius/common/includes/daloradius.conf.php" +TMPL="/opt/daloradius.conf.php.tmpl" -sed -e "s|\$configValues\['CONFIG_DB_HOST'\].*|\$configValues['CONFIG_DB_HOST'] = '${DBHOST}';|g" \ +# If no config present, seed from template +if [ ! -f "$CFG" ]; then + cp "$TMPL" "$CFG" +fi + +# Only edit if envs are provided and not explicitly skipped +if [ "${FORCE_RENDER:-0}" = "1" ] || [ ! -s "$CFG" ]; then + : "${DBHOST:?set DBHOST}"; : "${DBNAME:?set DBNAME}"; : "${DBUSER:?set DBUSER}"; : "${DBPASS:?set DBPASS}" + sed -i \ + -e "s|\$configValues\['CONFIG_DB_HOST'\].*|\$configValues['CONFIG_DB_HOST'] = '${DBHOST}';|g" \ -e "s|\$configValues\['CONFIG_DB_USER'\].*|\$configValues['CONFIG_DB_USER'] = '${DBUSER}';|g" \ -e "s|\$configValues\['CONFIG_DB_PASS'\].*|\$configValues['CONFIG_DB_PASS'] = '${DBPASS}';|g" \ -e "s|\$configValues\['CONFIG_DB_NAME'\].*|\$configValues['CONFIG_DB_NAME'] = '${DBNAME}';|g" \ - /opt/daloradius.conf.php.tmpl > /var/www/html/daloradius/common/includes/daloradius.conf.php + "$CFG" +fi -[ -x /usr/local/bin/apache-config.sh ] && /usr/local/bin/apache-config.sh || true exec apachectl -DFOREGROUND EOF +HEALTHCHECK --interval=30s --timeout=5s --retries=5 CMD curl -fsS http://localhost/ || exit 1 + RUN chmod +x /entrypoint.sh -EXPOSE 80 -HEALTHCHECK --interval=30s --timeout=5s --retries=5 CMD curl -fsS http://localhost/ || exit 1 -ENTRYPOINT ["/entrypoint.sh"]