From cdc910f4efa190936410a67713200d8fac21e6c4 Mon Sep 17 00:00:00 2001 From: Sarah Savage Date: Sun, 13 Oct 2024 00:26:22 -0400 Subject: [PATCH 1/3] Improving the developer experience and preparing for eventual launch * Breaking the build into stages consisting of a base layer that has most of the PHP components we need, and a dev/prod layer that contain specific elements required for those aspects. * Updating the components that depend upon our dev builds (e.g docker-compose.yml and GH actions) * Provide a Makefile command for building a production-ready container --- Makefile | 7 ++--- docker-compose.override.yml.dist | 5 ++-- docker-compose.yml | 5 +--- docker/webapp/Dockerfile | 44 +++++++++++++++++++------------- docker/webapp/php.ini | 2 +- 5 files changed, 35 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 33e61c5..473b514 100644 --- a/Makefile +++ b/Makefile @@ -112,8 +112,6 @@ _empty-testing-database: # internal target to empty database reset-database: _empty-database migrate seed ## Clean database, run migrations and seeds - - reset-testing-database: _empty-testing-database migrate-testing seed-testing run-pgsql: ## Runs Postgres on the command line using the .env file variables @@ -123,4 +121,7 @@ network: ## Create application docker network @bin/create-external-network.sh rm-network: ## Remove application docker network - @bin/remove-external-network.sh \ No newline at end of file + @bin/remove-external-network.sh + +build-prod: + docker build --target prodphp -t aspirepress/aspirecloud-php -f ./docker/webapp/Dockerfile . \ No newline at end of file diff --git a/docker-compose.override.yml.dist b/docker-compose.override.yml.dist index 8541821..2bee1b8 100644 --- a/docker-compose.override.yml.dist +++ b/docker-compose.override.yml.dist @@ -1,5 +1,6 @@ services: webapp: environment: - - XDEBUG_CONFIG=idekey=PHPSTORM start_with_request=true var_display_max_depth=-1 max_nesting_level=3000 client_host=docker.for.mac.localhost - - XDEBUG_MODE=develop,debug,coverage + - XDEBUG_CONFIG=idekey=PHPSTORM start_with_request=true var_display_max_depth=-1 max_nesting_level=3000 client_host=docker.for.mac.localhost + - PHP_IDE_CONFIG=serverName=application.local + - XDEBUG_MODEl=develop,debug,coverage diff --git a/docker-compose.yml b/docker-compose.yml index 244eb87..e0ad919 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,10 +20,7 @@ services: build: context: . dockerfile: docker/webapp/Dockerfile - environment: - - XDEBUG_CONFIG=idekey=PHPSTORM start_with_request=true var_display_max_depth=-1 max_nesting_level=3000 client_host=docker.for.mac.localhost - - PHP_IDE_CONFIG=serverName=application.local - - XDEBUG_MODEl=develop,debug,coverage + target: devphp volumes: - .:/var/www/html env_file: diff --git a/docker/webapp/Dockerfile b/docker/webapp/Dockerfile index 519b72e..6502da3 100644 --- a/docker/webapp/Dockerfile +++ b/docker/webapp/Dockerfile @@ -1,30 +1,38 @@ -FROM php:8.3-fpm-alpine +FROM php:8.3-fpm-alpine AS basephp -MAINTAINER Sarah Savage - - -RUN export DEBIAN_FRONTEND=noninteractive \ - && apk update \ - && apk add \ - bash \ - linux-headers \ - libpq-dev \ - git \ - zip \ - libzip-dev \ - icu-dev \ - postgresql-client \ - $PHPIZE_DEPS +RUN apk add \ + bash \ + linux-headers \ + libpq-dev \ + git \ + zip \ + libzip-dev \ + icu-dev \ + postgresql-client \ + $PHPIZE_DEPS RUN docker-php-ext-install pdo \ && docker-php-ext-install pdo_pgsql \ && docker-php-ext-install zip \ && docker-php-ext-install intl \ - && pecl install xdebug-3.3.0 \ - && docker-php-ext-enable xdebug \ && docker-php-ext-enable pdo_pgsql \ && pecl install redis \ && docker-php-ext-enable redis COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +FROM basephp AS devphp + +RUN pecl install xdebug-3.3.0 \ +&& docker-php-ext-enable xdebug + +COPY ./docker/webapp/php.ini /usr/local/etc/php/php.ini + +FROM basephp AS prodphp + +COPY . /var/www/html + +RUN composer install -n --no-dev -q + + diff --git a/docker/webapp/php.ini b/docker/webapp/php.ini index f8cc1ec..539bb35 100644 --- a/docker/webapp/php.ini +++ b/docker/webapp/php.ini @@ -2,4 +2,4 @@ error_reporting=E_ALL & ~E_DEPRECATED [xdebug] xdebug.client_host=host.docker.internal -xdebug.mode=debug +xdebug.mode=develop From 789df182ca8f58da400419081f6b70fdca34fd96 Mon Sep 17 00:00:00 2001 From: Sarah Savage Date: Sun, 13 Oct 2024 00:28:36 -0400 Subject: [PATCH 2/3] Committing missing file for GH actions --- .github/workflows/run-checks.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-checks.yaml b/.github/workflows/run-checks.yaml index 82e0c03..28cf1cf 100644 --- a/.github/workflows/run-checks.yaml +++ b/.github/workflows/run-checks.yaml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v4 - name: Build container - run: docker build -t aspirepress/aspirecloud-php -f ./docker/webapp/Dockerfile . + run: docker build --target devphp -t aspirepress/aspirecloud-php -f ./docker/webapp/Dockerfile . - name: Install Composer dependencies run: docker run --rm -v $(pwd):/var/www/html aspirepress/aspirecloud-php sh -c "composer install" From 8928a0e6376ec3c1a71336b4a849985d0f83f308 Mon Sep 17 00:00:00 2001 From: Sarah Savage Date: Sun, 13 Oct 2024 09:53:33 -0400 Subject: [PATCH 3/3] Updating the client_host in response to feedback --- docker-compose.override.yml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.override.yml.dist b/docker-compose.override.yml.dist index 2bee1b8..d08e412 100644 --- a/docker-compose.override.yml.dist +++ b/docker-compose.override.yml.dist @@ -1,6 +1,6 @@ services: webapp: environment: - - XDEBUG_CONFIG=idekey=PHPSTORM start_with_request=true var_display_max_depth=-1 max_nesting_level=3000 client_host=docker.for.mac.localhost + - XDEBUG_CONFIG=idekey=PHPSTORM start_with_request=true var_display_max_depth=-1 max_nesting_level=3000 client_host=172.17.0.1 - PHP_IDE_CONFIG=serverName=application.local - XDEBUG_MODEl=develop,debug,coverage