From c4ad0a1291ef10df7095595466c80aac41c5c388 Mon Sep 17 00:00:00 2001 From: Noel Palo Date: Thu, 27 Nov 2025 00:45:06 +0800 Subject: [PATCH 1/4] DWDT-2-fix-base-structure - Update php/Dockerfile --- docker/containers/php/Dockerfile | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/docker/containers/php/Dockerfile b/docker/containers/php/Dockerfile index 5d59e88..8e1bdc1 100644 --- a/docker/containers/php/Dockerfile +++ b/docker/containers/php/Dockerfile @@ -1,11 +1,19 @@ -# Install PHP +# Start from the official base image FROM php:8.2-fpm-alpine -# Copy PHP configuration -#COPY ./containers/php/config/php-$SYS_ENV-$HOST_SECRET.ini /usr/local/etc/php/php.ini +# Set the working directory to the standard web root +WORKDIR /var/www/html -# Install PHP Extension -RUN apk --no-cache add zip libzip-dev \ +# Install common system dependencies and PHP extensions in a single layer +# 1. Install system packages (git, zip dependencies) +# 2. Configure and install required PHP extensions (opcache for speed) +RUN apk add --no-cache git zip libzip-dev \ && docker-php-ext-configure zip \ - && docker-php-ext-install zip mysqli pdo pdo_mysql \ - && docker-php-ext-enable pdo_mysql \ + && docker-php-ext-install mysqli pdo pdo_mysql opcache zip \ + && rm -rf /var/cache/apk/* # Clean up cache to minimize image size + +# Copy PHP configuration +# COPY ./containers/php/config/php-$SYS_ENV.ini /usr/local/etc/php/php.ini + +# Default command to start PHP-FPM +CMD ["php-fpm"] \ No newline at end of file From 3589464fecf273889dacb4989938986d9faaf83e Mon Sep 17 00:00:00 2001 From: Noel Palo Date: Thu, 27 Nov 2025 00:46:46 +0800 Subject: [PATCH 2/4] DWDT-2-fix-base-structure - Update composer/Dockerfile --- docker/containers/composer/Dockerfile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/docker/containers/composer/Dockerfile b/docker/containers/composer/Dockerfile index 4a23036..272519b 100644 --- a/docker/containers/composer/Dockerfile +++ b/docker/containers/composer/Dockerfile @@ -1,10 +1,15 @@ -# Pull from PHP from previous Dockerfile - php/Dockerfile -# - use the image tag for php - php:php--fpm-alpine -# - see docker/docker-compose.yml for more info -FROM php:php-8.2-fpm-alpine +# CRITICAL FIX: +# The FROM instruction now uses the alias 'base'. +# This alias is defined in docker-compose.yml's 'additional_contexts' +# and explicitly tells Docker to use the result of the 'php' service build +# as the base image, fixing the build order dependency. +FROM base # Install Composer +# This curl command fetches the installer and pipes it to PHP, installing the +# Composer executable (named 'composer') directly into /usr/local/bin. RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=2.6.1 +# Since the executable is in /usr/local/bin, it is automatically available in the container's PATH. # Add composer bin path to environment variable RUN export PATH=$PATH":/usr/bin" From f4d5817717c1c5195d6be643a8e21f973dc73874 Mon Sep 17 00:00:00 2001 From: Noel Palo Date: Thu, 27 Nov 2025 00:47:34 +0800 Subject: [PATCH 3/4] DWDT-2-fix-base-structure - Update docker/environments/config.env - Add COMPOSE_PROJECT_NAME variable --- docker/environments/config.env | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/environments/config.env b/docker/environments/config.env index 050c83a..16bf5a8 100644 --- a/docker/environments/config.env +++ b/docker/environments/config.env @@ -5,6 +5,7 @@ # SYSTEM VARIABLES # values: local | test | prod SYS_ENV=local +COMPOSE_PROJECT_NAME=my_web_app # PATHS / DIRECTORIES / VOLUMES PATH_CONTAINERS=./containers From 2ca4a5d608058cc8cc3b454d5f65944b3ad066cc Mon Sep 17 00:00:00 2001 From: Noel Palo Date: Thu, 27 Nov 2025 01:24:38 +0800 Subject: [PATCH 4/4] DWDT-2-fix-base-structure - Update docker/docker-compose.yml - Fix issue with build dependency - Add volumes, vendor_data and node_modules_data - Add volume overlay - Add additional_contexts for build dependency - Explicitly names the network --- docker/docker-compose.yml | 44 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index ff8943d..c5b4bcb 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,8 +1,16 @@ -version: '3.8' +# Dockerize Web Development Template (DWDT) +# ===================================================================== +# 1. NETWORKS +# ===================================================================== networks: web-app: + # Explicitly names the network using the COMPOSE_PROJECT_NAME variable + name: ${COMPOSE_PROJECT_NAME}_app_net +# ===================================================================== +# 2. SERVICES +# ===================================================================== services: # +----------------------+ # # | Container: NginX | # @@ -21,6 +29,10 @@ services: - "${PATH_CONFIGS_NGINX}:/etc/nginx/conf.d/default.conf" - "${PATH_VOLUMES_LOGS}/nginx:/var/log/nginx" - "${PATH_SOURCE_LOCAL}:${PATH_SOURCE_LIVE}" + # Vendor volume overlay + - vendor_data:/var/www/html/vendor + # Node Modules volume overlay + - node_modules_data:/var/www/html/node_modules depends_on: - php - database @@ -83,11 +95,18 @@ services: build: context: . dockerfile: containers/composer/Dockerfile + # FIX: This crucial block forces the 'php' service to be built first, + # and makes the resulting image available to the composer Dockerfile + # under the alias 'base'. + additional_contexts: + base: service:php image: composer:composer-2.6.1 working_dir: /var/www/html volumes: - "${PATH_CONFIGS_PHP}:/usr/local/etc/php/php.ini" - "${PATH_SOURCE_LOCAL}:${PATH_SOURCE_LIVE}" + # CRITICAL: Composer installs dependencies directly into this fast volume + - vendor_data:/var/www/html/vendor depends_on: - php entrypoint: ['composer'] @@ -103,10 +122,12 @@ services: working_dir: /var/www/html volumes: - "${PATH_SOURCE_LOCAL}:${PATH_SOURCE_LIVE}" + # NEW: Overlays the node_modules directory with a fast Docker volume + - node_modules_data:/var/www/html/node_modules depends_on: - php entrypoint: ['npm'] -# + # # +----------------------+ # # # | Container: Artisan | # # # +----------------------+ # @@ -117,7 +138,11 @@ services: # build: # context: . # dockerfile: containers/php/Dockerfile -# image: artisan:laravel-9 +# # FIX: This crucial block forces the 'php' service to be built first, +# # and makes the resulting image available to artisan container +# additional_contexts: +# base: service:php +# image: artisan:laravel-XXX # name it with whatever that makes sense for you # links: # - php # - database @@ -126,7 +151,20 @@ services: # working_dir: /var/www/html # volumes: # - "${PATH_SOURCE_LOCAL}:${PATH_SOURCE_LIVE}" +# # Must include vendor data so Artisan can execute PHP dependencies +# - vendor_data:/var/www/html/vendor # depends_on: # - php # - database # entrypoint: ['php', '/var/www/html/artisan'] + +# ===================================================================== +# 3. VOLUMES +# ===================================================================== +volumes: + # Dedicated volume for Composer dependencies (vendor folder) + vendor_data: + driver: local + # Dedicated volume for NPM/Node dependencies (node_modules folder) + node_modules_data: + driver: local \ No newline at end of file