From 9ac3918e95ed9e4e2d2957bd9eb534455c342e27 Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Sun, 19 Jan 2020 01:12:14 -0700 Subject: [PATCH] Refactored Docker configuration to allow running both apache and nginx containers for testing --- .docker/Dockerfile.apache | 9 +++++ .docker/Dockerfile.nginx | 7 ++++ .../config/000-default.conf} | 0 .docker/apache2/config/000-default.prd.conf | 9 ----- .docker/nginx/config/default.conf | 33 +++++++++++++++++++ .docker/php/config/{php.dev.ini => php.ini} | 0 .docker/php/config/php.prd.ini | 18 ---------- .dockerignore | 3 ++ Dockerfile | 30 ----------------- docker-compose.yaml | 29 +++++++++++++--- 10 files changed, 76 insertions(+), 62 deletions(-) create mode 100644 .docker/Dockerfile.apache create mode 100644 .docker/Dockerfile.nginx rename .docker/{apache2/config/000-default.dev.conf => apache/config/000-default.conf} (100%) delete mode 100644 .docker/apache2/config/000-default.prd.conf create mode 100644 .docker/nginx/config/default.conf rename .docker/php/config/{php.dev.ini => php.ini} (100%) delete mode 100644 .docker/php/config/php.prd.ini create mode 100644 .dockerignore delete mode 100644 Dockerfile diff --git a/.docker/Dockerfile.apache b/.docker/Dockerfile.apache new file mode 100644 index 0000000..f124a85 --- /dev/null +++ b/.docker/Dockerfile.apache @@ -0,0 +1,9 @@ +# Build apache image +FROM php:7.4-apache +LABEL maintainer="Chris Kankiewicz " + +COPY ./php/config/php.ini /usr/local/etc/php/php.ini +COPY ./apache/config/000-default.conf /etc/apache2/sites-available/000-default.conf + +RUN a2enmod rewrite +RUN pecl install xdebug && docker-php-ext-enable xdebug diff --git a/.docker/Dockerfile.nginx b/.docker/Dockerfile.nginx new file mode 100644 index 0000000..9f859bf --- /dev/null +++ b/.docker/Dockerfile.nginx @@ -0,0 +1,7 @@ +# Build php-fpm image +FROM php:7.4-fpm +LABEL maintainer="Chris Kankiewicz " + +COPY ./php/config/php.ini /usr/local/etc/php/php.ini + +RUN pecl install xdebug && docker-php-ext-enable xdebug diff --git a/.docker/apache2/config/000-default.dev.conf b/.docker/apache/config/000-default.conf similarity index 100% rename from .docker/apache2/config/000-default.dev.conf rename to .docker/apache/config/000-default.conf diff --git a/.docker/apache2/config/000-default.prd.conf b/.docker/apache2/config/000-default.prd.conf deleted file mode 100644 index b348485..0000000 --- a/.docker/apache2/config/000-default.prd.conf +++ /dev/null @@ -1,9 +0,0 @@ - - DocumentRoot /var/www/html - ServerAdmin Chris@ChrisKankiewicz.com - - LogLevel warn - - ErrorLog /dev/stderr - CustomLog /dev/stderr combined - diff --git a/.docker/nginx/config/default.conf b/.docker/nginx/config/default.conf new file mode 100644 index 0000000..bca3ba4 --- /dev/null +++ b/.docker/nginx/config/default.conf @@ -0,0 +1,33 @@ +server { + listen 80 default_server; + root /var/www/html; + index index.php; + + access_log /dev/stderr; + error_log /dev/stderr; + + client_max_body_size 0; + + location = /favicon.ico { access_log off; log_not_found off; } + location = /robots.txt { access_log off; log_not_found off; } + + location / { + try_files $uri /index.php$is_args$args; + } + + location ~ \.php { + try_files $uri =404; + + fastcgi_split_path_info ^(.+\.php)(.*)$; + + fastcgi_param HTTP_PROXY ""; + + fastcgi_pass php-fpm:9000; + fastcgi_index index.php; + + include fastcgi_params; + + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param SCRIPT_NAME $fastcgi_script_name; + } +} diff --git a/.docker/php/config/php.dev.ini b/.docker/php/config/php.ini similarity index 100% rename from .docker/php/config/php.dev.ini rename to .docker/php/config/php.ini diff --git a/.docker/php/config/php.prd.ini b/.docker/php/config/php.prd.ini deleted file mode 100644 index be3ec45..0000000 --- a/.docker/php/config/php.prd.ini +++ /dev/null @@ -1,18 +0,0 @@ -[PHP] -error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT -log_errors = On -memory_limit = -1 - -[opcache] -opcache.enable = 1 -opcache.fast_shutdown = 1 -opcache.interned_strings_buffer = 16 -opcache.max_accelerated_files = 10000 -opcache.memory_consumption = 128 -opcache.optimization_level = 0xffffffff -opcache.validate_timestamps = 0 - -[xdebug] -xdebug.profiler_enable = 0 -xdebug.remote_autostart = 0 -xdebug.remote_enable = 0 diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..dbbb540 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git +node_modules +vendor diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 0b0a213..0000000 --- a/Dockerfile +++ /dev/null @@ -1,30 +0,0 @@ -# Install PHP dependencies -FROM composer:1.9 AS php-dependencies -COPY . /application -RUN composer install --working-dir /application --ignore-platform-reqs \ - --no-cache --no-dev --no-interaction - -# Install and compile JavaScript assets -FROM node:13.6 AS js-dependencies -COPY --from=php-dependencies /application /application -RUN cd /application && npm install && npm run production - -# Build application image -FROM php:7.4-apache as application -LABEL maintainer="Chris Kankiewicz " - -COPY --from=js-dependencies /application /var/www/html - -RUN a2enmod rewrite - -# Build development image -FROM application as development -COPY ./.docker/php/config/php.dev.ini /usr/local/etc/php/php.ini -COPY ./.docker/apache2/config/000-default.dev.conf /etc/apache2/sites-available/000-default.conf -RUN pecl install xdebug && docker-php-ext-enable xdebug - -# Build production image -FROM application as production -COPY ./.docker/php/config/php.prd.ini /usr/local/etc/php/php.ini -COPY ./.docker/apache2/config/000-default.prd.conf /etc/apache2/sites-available/000-default.conf -RUN docker-php-ext-install opcache diff --git a/docker-compose.yaml b/docker-compose.yaml index 2ea7c0c..225bc49 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,13 +1,32 @@ version: '3.4' services: - app: - container_name: directory-lister-app + apache: + container_name: directory-lister-apache build: - context: . - target: development + context: .docker + dockerfile: Dockerfile.apache environment: - VIRTUAL_HOST: directory-lister.local + VIRTUAL_HOST: directory-lister.local,directory-lister.apache.local + volumes: + - ./:/var/www/html + restart: unless-stopped + + nginx: + container_name: directory-lister-nginx + image: nginx:1.17 + environment: + VIRTUAL_HOST: directory-lister.nginx.local + volumes: + - ./.docker/nginx/config/default.conf:/etc/nginx/conf.d/default.conf + - ./:/var/www/html + restart: unless-stopped + + php-fpm: + container_name: directory-lister-php-fpm + build: + context: .docker + dockerfile: Dockerfile.nginx volumes: - ./:/var/www/html restart: unless-stopped