From 70571c6158b56704f138f091a1472e5c6e6c3fb3 Mon Sep 17 00:00:00 2001 From: Arthur Wang Date: Thu, 25 Jul 2024 23:20:17 -0400 Subject: [PATCH] Redo add config variables on build --- Dockerfile | 5 ++++- entrypoint.sh | 56 ++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index dec0199..1a2384c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -108,7 +108,10 @@ RUN set -xe \ && NODE_OPTIONS=--openssl-legacy-provider npm run build \ # Create directories && mkdir -p /var/www/files /run/apache2 \ - && cp config.TEMPLATE.inc.php config.inc.php \ + && if test -f /home/config.inc.php; then \ + cp /home/config.inc.php config.inc.php; \ + else cp config.TEMPLATE.inc.php config.inc.php; \ + fi\ && chown -R apache:apache /var/www/* \ # Prepare freefont for captcha && ln -s /usr/share/fonts/TTF/FreeSerif.ttf /usr/share/fonts/FreeSerif.ttf \ diff --git a/entrypoint.sh b/entrypoint.sh index 7cca52d..d0ae265 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -11,22 +11,54 @@ chmod +x /usr/local/bin/ojs-variable # Temporary fix for error in ojs-variable (fixed here https://gitlab.com/pkp-org/docker/ojs/-/commit/f4f33f370e7c765b599868f0ca701898c875b47f, but not in stable-3_4_0 branch) sed -i 's:/tmp/ojs.config.inc.php:/tmp/config.inc.php:' /usr/local/bin/ojs-variable -# Set config variables using env variables https://github.com/pkp/ojs/blob/main/config.TEMPLATE.inc.php -echo "Updating OJS config based on env variables..." + +if ! test -f /home/files; then + mkdir /home/files; + chmod 755 /home/files; + chown apache /home/files; + chgrp apache /home/files; +fi + + declare -A configVariable -configVariable["installed"]="On" -configVariable["base_url"]=$WEBSITE_HOSTNAME -configVariable["restful_urls"]="On" -configVariable["host"]=$OJS_DB_HOST -configVariable["username"]=$OJS_DB_USER -configVariable["password"]=$OJS_DB_PASSWORD -configVariable["name"]=$OJS_DB_NAME -configVariable["locale"]="en_US" -configVariable["time_zone"]=$TIME_ZONE +if ! test -f /home/config.inc.php; then + # Set config variables using env variables https://github.com/pkp/ojs/blob/main/config.TEMPLATE.inc.php + echo "Updating OJS config based on env variables..." + # General + configVariable["installed"]="On" + configVariable["base_url"]=$WEBSITE_HOSTNAME + configVariable["time_zone"]=$TIME_ZONE + configVariable["restful_urls"]="On" + # Database + configVariable["host"]=$OJS_DB_HOST + configVariable["username"]=$OJS_DB_USER + configVariable["password"]=$OJS_DB_PASSWORD + configVariable["name"]=$OJS_DB_NAME + # Locatlization + configVariable["locale"]="en" + # Files + configVariable["files_dir"]="/home/files" + # Security + configVariable["force_ssl"]="On" + configVariable["salt"]=$SALT + configVariable["api_key_secret"]=$API_KEY_SECRET + # Email + configVariable["smtp_server"]="smtp-relay.gmail.com" + configVariable["smtp_port"]="587" + configVariable["smtp_auth"]="tls" + configVariable["smtp_username"]=$SMTP_USERNAME + configVariable["smtp_password"]=$SMTP_PASSWORD + configVariable["allow_envelope_sender"]="On" + configVariable["default_envelope_sender"]="no-reply@post45.org" + # OAI + configVariable["oai"]="Off" +fi for key in "${!configVariable[@]}"; do ojs-variable $key ${configVariable[$key]} done chmod +x /usr/local/bin/ojs-start -ojs-start \ No newline at end of file +ojs-start +# Note: Fresh installs are async, so /home/config.inc.php may not be correct +cp config.inc.php /home/config.inc.php \ No newline at end of file