From 2d6a37297e1620ed779071cf5eb5eb05f00d22ad Mon Sep 17 00:00:00 2001 From: Olusesan Ameye Date: Wed, 27 Aug 2025 04:44:52 +0000 Subject: [PATCH 1/2] CI envrionment handling --- .env | 2 +- .env.live | 3 ++- app/Config/Boot/production.php | 2 ++ app/Controllers/Home.php | 4 ++-- docker-compose.yml | 2 +- docker/apache/000-default.conf | 6 +++++- docker/apache/Dockerfile | 20 ++++++++++++++------ public/.htaccess | 2 ++ public/index.php | 1 + 9 files changed, 30 insertions(+), 12 deletions(-) diff --git a/.env b/.env index 875ceb1..7e0076d 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -CONFIG_NAME='This is development'; +CONFIG_NAME='This is NOT development. It is not how envrionment works in CodeIgniter!' CONTAINER_PORT=8094 UID=1000 diff --git a/.env.live b/.env.live index 1c5e89e..587e8f1 100644 --- a/.env.live +++ b/.env.live @@ -1,6 +1,7 @@ -CONFIG_NAME='This is live'; +CONFIG_NAME='This is live' CONTAINER_PORT=8094 UID=1000 +CI_ENVIRONMENT=production SERVER_PATH = production diff --git a/app/Config/Boot/production.php b/app/Config/Boot/production.php index 1822cf5..679b341 100644 --- a/app/Config/Boot/production.php +++ b/app/Config/Boot/production.php @@ -23,3 +23,5 @@ ini_set('display_errors', '0'); | release of the framework. */ defined('CI_DEBUG') || define('CI_DEBUG', false); + +$_ENV['CONFIG_NAME']='

I beleive you are doing CI envrionment handling wrong. You should define CI_ENVIRONMENT environment variable and utilize the respective app/Config/Boot/...php file


'; diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 7cc3f29..892beb3 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -11,8 +11,8 @@ class Home extends BaseController public function what_env(): string { - $curr_env = $_ENV['CONFIG_NAME']; - echo $curr_env; + $curr_env = env('CONFIG_NAME','undefined?'); + echo env('CI_ENVIRONMENT'); return $curr_env; } public function provision(): string diff --git a/docker-compose.yml b/docker-compose.yml index aa9f573..cffe20e 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: environment: - APACHE_RUN_USER=#${UID} - APACHE_RUN_GROUP=#${UID} - #- CI_ENV + - CI_ENVIRONMENT=${CI_ENVIRONMENT:-development} - CI_CONFIG restart: unless-stopped image: registry.chiefsoft.net/mermsprovision:latest diff --git a/docker/apache/000-default.conf b/docker/apache/000-default.conf index 613ea1f..8d40f33 100644 --- a/docker/apache/000-default.conf +++ b/docker/apache/000-default.conf @@ -8,4 +8,8 @@ AllowOverride All Require all granted - \ No newline at end of file + + # pass system env CI_ENVIRONMENT to Apache + PassEnv CI_ENVIRONMENT + + diff --git a/docker/apache/Dockerfile b/docker/apache/Dockerfile index 40867de..c856b9c 100644 --- a/docker/apache/Dockerfile +++ b/docker/apache/Dockerfile @@ -1,31 +1,39 @@ # Use an official PHP runtime as a base image FROM php:8.1-apache +# Build args +ARG CI_ENVIRONMENT + +ENV CI_ENVIRONMENT=$CI_ENVIRONMENT + RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf #RUN apt-get update +#RUN apt-get update && apt-get install --yes --force-yes libc-client-dev libkrb5-dev + +RUN apt-get update && apt-cache search libc-client RUN apt-get update && \ apt-get install --yes --force-yes \ cron g++ gettext libicu-dev openssl \ - libc-client-dev libkrb5-dev \ + libkrb5-dev \ libxml2-dev libfreetype6-dev \ libgd-dev libmcrypt-dev bzip2 \ libbz2-dev libtidy-dev libcurl4-openssl-dev \ libz-dev libmemcached-dev libxslt-dev git-core libpq-dev \ - libzip4 libzip-dev libwebp-dev - + libzip5 libzip-dev libwebp-dev +# libc-client-dev => libc-client2007e-dev # PHP Configuration RUN docker-php-ext-install bcmath bz2 calendar dba exif gettext iconv intl soap tidy xsl zip&&\ docker-php-ext-install mysqli pgsql pdo pdo_mysql pdo_pgsql &&\ docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp &&\ docker-php-ext-install gd &&\ - docker-php-ext-configure imap --with-kerberos --with-imap-ssl &&\ - docker-php-ext-install imap &&\ docker-php-ext-configure hash --with-mhash &&\ pecl install xdebug && docker-php-ext-enable xdebug &&\ pecl install mongodb && docker-php-ext-enable mongodb &&\ pecl install redis && docker-php-ext-enable redis +# docker-php-ext-configure imap --with-kerberos --with-imap-ssl &&\ +# docker-php-ext-install imap &&\ # 2. set up document root for apache COPY docker/apache/000-default.conf /etc/apache2/sites-available/000-default.conf @@ -56,4 +64,4 @@ RUN mkdir -p /var/www/html/ANSIBLE && \ RUN composer install -EXPOSE 80 \ No newline at end of file +EXPOSE 80 diff --git a/public/.htaccess b/public/.htaccess index abac3cb..56d3f7b 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -1,6 +1,8 @@ # Disable directory browsing Options -Indexes +PassEnv CI_ENVIRONMENT + # ---------------------------------------------------------------------- # Rewrite engine # ---------------------------------------------------------------------- diff --git a/public/index.php b/public/index.php index 5ec58a7..8674b01 100644 --- a/public/index.php +++ b/public/index.php @@ -5,6 +5,7 @@ * CHECK PHP VERSION *--------------------------------------------------------------- */ +var_dump(getenv('CI_ENVIRONMENT')); $minPhpVersion = '8.1'; // If you update this, don't forget to update `spark`. if (version_compare(PHP_VERSION, $minPhpVersion, '<')) { From 7518f02a6e88d0bf32c54ad5f2dbdbf9bcc18cc2 Mon Sep 17 00:00:00 2001 From: Olusesan Ameye Date: Wed, 27 Aug 2025 04:49:10 +0000 Subject: [PATCH 2/2] Remove debug --- public/index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/public/index.php b/public/index.php index 8674b01..5ec58a7 100644 --- a/public/index.php +++ b/public/index.php @@ -5,7 +5,6 @@ * CHECK PHP VERSION *--------------------------------------------------------------- */ -var_dump(getenv('CI_ENVIRONMENT')); $minPhpVersion = '8.1'; // If you update this, don't forget to update `spark`. if (version_compare(PHP_VERSION, $minPhpVersion, '<')) {