major rewite to remove HEREDOC
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 2m13s

This commit is contained in:
2025-08-12 10:51:56 -05:00
parent b4a6caa179
commit 5de5a2bf48
4 changed files with 37 additions and 29 deletions

View File

@@ -13,7 +13,7 @@ RUN apk add --no-cache git && \
# Stage 2: runtime (PHP 8, Apache) # Stage 2: runtime (PHP 8, Apache)
############################################ ############################################
FROM php:8.3-apache FROM php:8.3-apache
ENV TZ=UTC ENV TZ=UTC DBPORT=3306
# System deps # System deps
RUN apt-get update && apt-get -y upgrade && \ RUN apt-get update && apt-get -y upgrade && \
@@ -42,38 +42,22 @@ RUN curl -fsSL https://pear.php.net/install-pear-nozlib.phar -o /tmp/pear.phar \
COPY --from=source /src/app/ /var/www/html/daloradius/ 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/app/common/includes/daloradius.conf.php.sample /opt/daloradius.conf.php.tmpl
# Our Apache vhost (replace default) # Our Apache vhost (serve operators UI at /)
COPY apache/000-default.conf /etc/apache2/sites-available/000-default.conf COPY apache/000-default.conf /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite && apache2ctl -t RUN a2enmod rewrite && apache2ctl -t && \
printf 'ServerName localhost\n' > /etc/apache2/conf-available/servername.conf && a2enconf servername
# (Optional) silence ServerName warning # DB override snippet + entrypoint
RUN printf 'ServerName localhost\n' > /etc/apache2/conf-available/servername.conf && a2enconf servername COPY config/override-db.php /opt/override-db.php
COPY entrypoint.sh /entrypoint.sh
# Entry script: seed/refresh config from env only when needed
COPY <<'EOF' /entrypoint.sh
#!/usr/bin/env bash
set -euo pipefail
CFG="/var/www/html/daloradius/common/includes/daloradius.conf.php"
TMPL="/opt/daloradius.conf.php.tmpl"
# Seed if missing
if [ ! -f "$CFG" ]; then cp "$TMPL" "$CFG"; fi
# Render if forced or empty
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" \
"$CFG"
fi
exec apachectl -DFOREGROUND
EOF
RUN chmod +x /entrypoint.sh RUN chmod +x /entrypoint.sh
# Permissions (readable by Apache)
RUN chown -R www-data:www-data /var/www/html && \
find /var/www/html -type d -exec chmod 755 {} \; && \
find /var/www/html -type f -exec chmod 644 {} \;
EXPOSE 80 EXPOSE 80
HEALTHCHECK --interval=30s --timeout=5s --retries=5 CMD curl -fsS http://localhost/ || exit 1 HEALTHCHECK --interval=30s --timeout=5s --retries=5 CMD curl -fsS http://localhost/ || exit 1
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -7,4 +7,6 @@
Require all granted Require all granted
</Directory> </Directory>
DirectoryIndex index.php DirectoryIndex index.php
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost> </VirtualHost>

8
config/override-db.php Normal file
View File

@@ -0,0 +1,8 @@
<?php
// ---- overrides injected at runtime ----
$configValues['CONFIG_DB_ENGINE'] = 'mysqli';
$configValues['CONFIG_DB_HOST'] = getenv('DBHOST') ?: 'db';
$configValues['CONFIG_DB_PORT'] = getenv('DBPORT') ?: '3306';
$configValues['CONFIG_DB_USER'] = getenv('DBUSER') ?: 'radius';
$configValues['CONFIG_DB_PASS'] = getenv('DBPASS') ?: '';
$configValues['CONFIG_DB_NAME'] = getenv('DBNAME') ?: 'radius';

14
entrypoint.sh Normal file
View File

@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail
CFG="/var/www/html/daloradius/common/includes/daloradius.conf.php"
TMPL="/opt/daloradius.conf.php.tmpl"
OVR="/opt/override-db.php"
# Always (re)seed from upstream sample, then append our override
mkdir -p "$(dirname "$CFG")"
cp -f "$TMPL" "$CFG"
cat "$OVR" >> "$CFG"
# Start Apache in foreground
exec apachectl -DFOREGROUND