From f4aaf4c0b4e6efd93fba8d4e236d34e90a05a021 Mon Sep 17 00:00:00 2001 From: Mitchell Rysavy Date: Sun, 1 Sep 2024 13:01:00 +0000 Subject: [PATCH] Refactor start-blis.sh and Dockerfile --- Dockerfile | 9 ++++--- docker/bin/get-https-cert.sh | 13 ---------- docker/bin/set-apache2-servername.py | 37 --------------------------- docker/bin/start-blis.sh | 38 +++------------------------- htdocs/includes/composer.php | 10 ++++---- 5 files changed, 15 insertions(+), 92 deletions(-) delete mode 100755 docker/bin/get-https-cert.sh delete mode 100755 docker/bin/set-apache2-servername.py diff --git a/Dockerfile b/Dockerfile index 1c840ac2b..f8b8f4b72 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,10 +31,12 @@ RUN echo "column-statistics = 0" | tee -a /etc/mysql/conf.d/mysqldump.cnf # Copy the custom Apache2 config (blis.conf) into the # Apache2 configuration directory. This will be enabled by the start-blis.sh -COPY docker/config/blis-release.conf /etc/apache2/blis-release.conf +COPY docker/config/blis-release.conf /etc/apache2/sites-available/blis-release.conf # Enable Apache2 modules needed by application and disable default site -RUN a2enmod rewrite socache_shmcb ssl && a2dissite 000-default +RUN a2enmod rewrite socache_shmcb ssl && \ + a2dissite 000-default && \ + a2ensite blis* # Copy custom PHP config into the container COPY docker/config/php.ini /etc/php/5.6/apache2/php.ini @@ -47,7 +49,8 @@ RUN mkdir /var/www/blis COPY . /var/www/blis RUN chown -R www-data:www-data /var/www && \ chmod +x /var/log/apache2 && \ - chmod +r /var/log/apache2/* + chmod +r /var/log/apache2/* && \ + echo ". /var/www/apache2_blis.env" | tee -a /etc/apache2/envvars # Inject the current git commit SHA as a build parameter # This isn't foolproof, but will help when someone is using the diff --git a/docker/bin/get-https-cert.sh b/docker/bin/get-https-cert.sh deleted file mode 100755 index 4238a3737..000000000 --- a/docker/bin/get-https-cert.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -if [[ -z "$BLIS_SERVER_NAME" ]]; then - echo "You need to set BLIS_SERVER_NAME as an environment variable in the docker-compose.yml file." - exit 1 -fi - -if ! set-apache2-servername.py; then - echo "Could not set Apache2 ServerName." - exit 1 -fi - -certbot --apache \ No newline at end of file diff --git a/docker/bin/set-apache2-servername.py b/docker/bin/set-apache2-servername.py deleted file mode 100755 index 7c3bb7924..000000000 --- a/docker/bin/set-apache2-servername.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python3 - -########## -# Sets the Apache2 ServerName property based on the environment. - -import os, re - -if 'BLIS_APACHE2_CONFIG' not in os.environ: - print('BLIS_APACHE2_CONFIG environment variable is not set.') - exit(1) - -if 'BLIS_SERVER_NAME' not in os.environ: - print('BLIS_SERVER_NAME environment variable is not set; skipping update.') - exit(0) - -apache2_cfg = os.environ['BLIS_APACHE2_CONFIG'] -servername = os.environ['BLIS_SERVER_NAME'] - -# read entire apache2 config file into memory -with open(apache2_cfg) as file: - lines = file.readlines() - -# search for the ServerName directive, -# and when it is found, replace the value with whatever we want it to be. -server_name_regex = re.compile('(\s*)(#?)ServerName(.*)') -for l in range(0, len(lines)): - line = lines[l] - match = server_name_regex.match(line) - if match: - lines[l] = match.group(1) + f'ServerName {servername}\n' - break - -# write the result lines back to disk. -with open(apache2_cfg, 'w') as file: - file.writelines(lines) - -print(f'ServerName updated to {servername}') \ No newline at end of file diff --git a/docker/bin/start-blis.sh b/docker/bin/start-blis.sh index 47e7dc2c0..af79f7cec 100755 --- a/docker/bin/start-blis.sh +++ b/docker/bin/start-blis.sh @@ -1,16 +1,13 @@ #!/bin/bash echo "Dumping environment variables to environment file..." + A2ENVVARS="$(env | grep -E "(^DB_|^BLIS_)" | sed -e 's/^/export /')" -echo "$A2ENVVARS" | sudo tee /etc/apache2/apache2_blis.env > /dev/null +echo "$A2ENVVARS" > /var/www/apache2_blis.env + GIT_COMMIT_SHA="$(cat /etc/blis_git_commit_sha 2>/dev/null)" if [[ -n "$GIT_COMMIT_SHA" ]]; then - echo "export GIT_COMMIT_SHA=\"$GIT_COMMIT_SHA\"" | sudo tee -a /etc/apache2/apache2_blis.env -fi - -if ! grep -q 'apache2_blis.env' /etc/apache2/envvars; then - echo "Adding BLIS environment variables to Apache2 configuration..." - echo ". /etc/apache2/apache2_blis.env" | sudo tee -a /etc/apache2/envvars + echo "export GIT_COMMIT_SHA=\"$GIT_COMMIT_SHA\"" >> /var/www/apache2_blis.env fi if [[ -d "/workspace" ]]; then @@ -18,33 +15,6 @@ if [[ -d "/workspace" ]]; then find /workspace -type d -exec sudo chmod ug+s {} \; fi -# This is a little funky... -# The container build puts the config in /etc/apache2, but this is not the correct place for it. -# The reason for this is so you can mount a volume to /etc/apache2/sites-available to persist your changes. -# When the container starts, it will only overwrite the configuration with the default if the file doesn't -# exist already. -if [[ ! -f "/etc/apache2/sites-available/blis-release.conf" ]]; then - if [[ -f "/etc/apache2/blis-release.conf" ]]; then - echo -e "Thanks for setting up BLIS! Just getting some things in place..." - sudo mv /etc/apache2/blis-release.conf /etc/apache2/sites-available/blis-release.conf - # Set the ServerName properly, according to the environment - BLIS_APACHE2_CONFIG="/etc/apache2/sites-available/blis-release.conf" set-apache2-servername.py - else - if [[ ! -f "/etc/apache2/sites-available/blis.conf" ]]; then - echo "The blis-release.conf Apache2 configuration is not present. Did the container build correctly?" - exit 1 - else - echo "Found blis.conf apache2 configuration - must be a dev container!" - fi - fi -fi - -if [[ -f "/etc/apache2/sites-available/blis-release-le-ssl.conf" ]]; then - echo "Detected an SSL configuration!" -fi - -sudo a2ensite blis* - sudo service apache2 start echo "BLIS is running!" diff --git a/htdocs/includes/composer.php b/htdocs/includes/composer.php index 54566754d..4c1d072bb 100644 --- a/htdocs/includes/composer.php +++ b/htdocs/includes/composer.php @@ -1,6 +1,6 @@ pushHandler(new StreamHandler(dirname(__FILE__).'/../../log/application.log', Logger::DEBUG)); +$log = new Logger("application"); +$log->pushHandler(new StreamHandler(__DIR__."/../../log/application.log", Logger::DEBUG)); -$db_log = new Logger('database'); -$db_log->pushHandler(new StreamHandler(dirname(__FILE__).'/../../log/database.log', Logger::DEBUG)); +$db_log = new Logger("database"); +$db_log->pushHandler(new StreamHandler(__DIR__."/../../log/database.log", Logger::DEBUG)); # Check for other folders needed by application if (!file_exists(__DIR__."/../../files")) {