Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize Docker services: use only FrankenPHP, add cli service #21

Merged
merged 6 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,3 @@ DB_USER=postgres
DB_PASS=password
DB_PORT=5432
DB_SCHEMA=public

# Default web service is nginx+fpm. Set to 'frankenphp' to use a frankenphp server instead.
# AP_COMPOSE_STACK=frankenphp
AP_COMPOSE_STACK=nginx
2 changes: 1 addition & 1 deletion .github/workflows/run-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v4

- name: Build container
run: docker build --target dev -t aspirepress/aspirecloud-php -f ./docker/webapp-frankenphp/Dockerfile .
run: docker build --target dev -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"
Expand Down
67 changes: 30 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,111 +17,104 @@ ifneq (,$(wildcard ./.env))
export
endif

ifeq ($(AP_COMPOSE_STACK),frankenphp)
COMPOSE_FILE := docker-compose.frankenphp.yml
else
COMPOSE_FILE := docker-compose.yml
endif

list:
@grep -E '^[a-zA-Z%_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

init: down clean build network up install-composer reset-database devmode-enable ## Initial configuration tasks

build: ## Builds the Docker containers
docker compose -f $(COMPOSE_FILE) build
docker compose build

clean: ## Remove all Docker containers, volumes, etc
docker compose -f $(COMPOSE_FILE) down -v --remove-orphans
docker compose -f $(COMPOSE_FILE) rm -f
docker compose down -v --remove-orphans
docker compose rm -f
rm -fr ./vendor

up: ## Starts the Docker containers
docker compose -f $(COMPOSE_FILE) up -d
docker compose up -d

down: ## Stops the Docker containers
docker compose -f $(COMPOSE_FILE) down
docker compose down

unit: ## Run unit tests
docker compose -f $(COMPOSE_FILE) run --rm webapp bash -c "vendor/bin/phpunit --testsuite=unit ${OPTS}"
bin/dcrun vendor/bin/phpunit --testsuite=unit ${OPTS}

functional: ## Run functional tests
docker compose -f $(COMPOSE_FILE) run --rm webapp bash -c "vendor/bin/phpunit --testsuite=functional ${OPTS}"
bin/dcrun vendor/bin/phpunit --testsuite=functional ${OPTS}

test: unit functional acceptance ## Run all tests

acceptance: ## Run acceptance tests
docker compose -f $(COMPOSE_FILE) run --rm webapp bash -c "vendor/bin/behat -vvv ${OPTS}"
bin/dcrun vendor/bin/behat -vvv ${OPTS}

quality: ## Run all quality checks
docker compose -f $(COMPOSE_FILE) run --rm webapp bash -c "vendor/bin/phpstan ${OPTS}"
bin/dcrun vendor/bin/phpstan ${OPTS}

quality-baseline: ## Run all static analysis checks with baseline
docker compose -f $(COMPOSE_FILE) run --rm webapp vendor/bin/phpstan analyse -b baseline.neon $(PHPSTAN_XDEBUG) src tests
bin/dcrun vendor/bin/phpstan analyse -b baseline.neon $(PHPSTAN_XDEBUG) src tests

install-composer: ## Install composer dependencies
docker compose -f $(COMPOSE_FILE) run --rm webapp bash -c "composer install"
bin/dcrun composer install

logs-%: ## View logs (follow mode) for the container where % is a service name (webapp, postgres, node, nginx, smtp, rabbitmq)
docker compose -f $(COMPOSE_FILE) logs -f $*
docker compose logs -f $*

sh-webapp: # webapp is alpine, so we need to use sh, not sh
docker compose -f $(COMPOSE_FILE) exec webapp sh
docker compose exec webapp sh

sh-%: ## Execute shell for the container where % is a service name (webapp, postgres, node, nginx, smtp, rabbitmq)
docker compose -f $(COMPOSE_FILE) exec $* sh || docker compose -f $(COMPOSE_FILE) run --rm $* sh
docker compose exec $* sh || docker compose run --rm $* sh

clear-cache: ## Clear cache
docker compose -f $(COMPOSE_FILE) run --rm webapp rm -f data/cache/config-cache.php
rm -rf public/build/
rm -f data/cache/config-cache.php public/build

check: cs-fix quality test ## Check all quality and test elements

cs: ## Run code style checks
docker compose -f $(COMPOSE_FILE) run --rm webapp bash -c "vendor/bin/phpcs ${OPTS}"
bin/dcrun vendor/bin/phpcs ${OPTS}

cs-fix: ## Fix code style issues
docker compose -f $(COMPOSE_FILE) run --rm webapp bash -c "vendor/bin/phpcbf ${OPTS} && vendor/bin/phpcs ${OPTS}"
bin/dcrun vendor/bin/phpcbf ${OPTS} && vendor/bin/phpcs ${OPTS}

create-migration: ## Create a new database migration
docker compose -f $(COMPOSE_FILE) run --rm webapp vendor/bin/phinx create ${OPTS} -c vendor/aspirepress/aspirecloud-migrations/phinx.php
bin/dcrun vendor/bin/phinx create ${OPTS} -c vendor/aspirepress/aspirecloud-migrations/phinx.php

create-seed: ## Create a new database seed
docker compose -f $(COMPOSE_FILE) run --rm webapp vendor/bin/phinx seed:create ${OPTS} -c vendor/aspirepress/aspirecloud-migrations/phinx.php
bin/dcrun vendor/bin/phinx seed:create ${OPTS} -c vendor/aspirepress/aspirecloud-migrations/phinx.php

migrate: ## Run database migrations
docker compose -f $(COMPOSE_FILE) run --rm webapp vendor/bin/phinx migrate -c vendor/aspirepress/aspirecloud-migrations/phinx.php
bin/dcrun vendor/bin/phinx migrate -c vendor/aspirepress/aspirecloud-migrations/phinx.php

migration-rollback: ## Rollback database migrations
docker compose -f $(COMPOSE_FILE) run --rm webapp vendor/bin/phinx rollback -e development -c vendor/aspirepress/aspirecloud-migrations/phinx.php
bin/dcrun vendor/bin/phinx rollback -e development -c vendor/aspirepress/aspirecloud-migrations/phinx.php

seed: ## Run database seeds
docker compose -f $(COMPOSE_FILE) run --rm webapp vendor/bin/phinx seed:run -c vendor/aspirepress/aspirecloud-migrations/phinx.php
bin/dcrun vendor/bin/phinx seed:run -c vendor/aspirepress/aspirecloud-migrations/phinx.php

devmode-enable: ## Enable the PHP development mode
docker compose -f $(COMPOSE_FILE) run --rm webapp composer development-enable
bin/dcrun composer development-enable

devmode-disable: ## Disable the PHP development mode
docker compose -f $(COMPOSE_FILE) run --rm webapp composer development-disable
bin/dcrun composer development-disable

_empty-database: # internal target to empty database
docker compose -f $(COMPOSE_FILE) run --rm webapp vendor/bin/phinx migrate -c vendor/aspirepress/aspirecloud-migrations/phinx.php -t 0
bin/dcrun vendor/bin/phinx migrate -c vendor/aspirepress/aspirecloud-migrations/phinx.php -t 0

migrate-testing: ## Run database migrations
docker compose -f $(COMPOSE_FILE) run --rm webapp vendor/bin/phinx migrate -e testing -c vendor/aspirepress/aspirecloud-migrations/phinx.php
bin/dcrun vendor/bin/phinx migrate -e testing -c vendor/aspirepress/aspirecloud-migrations/phinx.php

seed-testing: ## Run database seeds
docker compose -f $(COMPOSE_FILE) run --rm webapp vendor/bin/phinx seed:run -e testing -c vendor/aspirepress/aspirecloud-migrations/phinx.php
bin/dcrun vendor/bin/phinx seed:run -e testing -c vendor/aspirepress/aspirecloud-migrations/phinx.php

_empty-testing-database: # internal target to empty database
docker compose -f $(COMPOSE_FILE) run --rm webapp vendor/bin/phinx migrate -e testing -c vendor/aspirepress/aspirecloud-migrations/phinx.php -t 0
bin/dcrun vendor/bin/phinx migrate -e testing -c vendor/aspirepress/aspirecloud-migrations/phinx.php -t 0

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
docker compose -f $(COMPOSE_FILE) run --rm webapp sh -c "export PGPASSWORD=${DB_PASS} && psql -U ${DB_USER} -h ${DB_HOST} -d ${DB_NAME}"
bin/dcrun sh -c "export PGPASSWORD=${DB_PASS} && psql -U ${DB_USER} -h ${DB_HOST} -d ${DB_NAME}"

network: ## Create docker networks for app and traefik proxy (if they don't exist already)
bin/create-external-network.sh wp-services
Expand All @@ -131,7 +124,7 @@ rm-network: ## Remove application docker network. (traefik
-bin/remove-external-network.sh wp-services

build-prod:
docker build --target prod -t aspirepress/aspirecloud-php -f ./docker/webapp-frankenphp/Dockerfile .
docker build --target prod -t aspirepress/aspirecloud-php -f ./docker/webapp/Dockerfile .

traefik-up: network
docker compose -f docker/traefik/docker-compose.yml up -d
Expand Down
8 changes: 8 additions & 0 deletions bin/dcexec
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

cd $(dirname $0)/..
base=$(pwd)

svc=${APP_SERVICE:-webapp}

exec docker compose exec $svc "$@"
8 changes: 8 additions & 0 deletions bin/dcrun
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

cd $(dirname $0)/..
base=$(pwd)

svc=${CLI_SERVICE:-cli}

exec docker compose run --rm $svc "$@"
55 changes: 0 additions & 55 deletions docker-compose.frankenphp.yml

This file was deleted.

42 changes: 23 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
services:
nginx:
webapp:
build:
context: .
dockerfile: ./docker/nginx/Dockerfile
dockerfile: docker/webapp/Dockerfile
target: dev
ports:
- ${LOCAL_HTTP_PORT:-8099}:80
- ${LOCAL_HTTPS_PORT:-8100}:443
volumes:
- .:/var/www/html
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
env_file:
- .env.dist
- .env
networks:
traefik: ~
aspirepress-cdn: ~
Expand All @@ -21,20 +23,6 @@ services:
- "traefik.http.routers.ap-api-https.rule=Host(`api.aspirepress.local`)"
- "traefik.http.routers.ap-api-https.tls=true"

webapp:
build:
context: .
dockerfile: docker/webapp-fpm/Dockerfile
target: devphp
volumes:
- .:/var/www/html
env_file:
- .env.dist
- .env
networks:
- aspirepress-cdn
- application

redis:
image: redis:latest
networks:
Expand All @@ -47,13 +35,29 @@ services:
- PGDATA=/opt/pgdata
- POSTGRES_DB=aspirepress_cdn
ports:
- ${LOCAL_POSTGRES_PORT:-5432}:5432
- "${LOCAL_POSTGRES_PORT:-5432}:5432"
volumes:
- postgresdata:/opt/pgdata
networks:
- aspirepress-cdn
- application

cli:
build:
context: .
dockerfile: docker/cli/Dockerfile
target: dev
volumes:
- .:/var/www/html
env_file:
- .env.dist
- .env
networks:
aspirepress-cdn: ~
application:
aliases:
- 'cdn.aspirepress.local'

networks:
aspirepress-cdn: ~
application:
Expand Down
23 changes: 23 additions & 0 deletions docker/cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM php:8.3-cli-alpine AS base

COPY --from=composer:2.7 /usr/bin/composer /usr/bin/composer
ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/download/2.5.2/install-php-extensions /usr/local/bin/

RUN install-php-extensions pdo pdo_pgsql zip intl redis

RUN apk add bash git postgresql-client zip

COPY ./docker/cli/php.ini /usr/local/etc/php/php.ini

WORKDIR /var/www/html

################
FROM base AS dev

# Xdebug exists, but is explicitly disabled for cli. Use docker-compose.override.yml to enable.
RUN install-php-extensions xdebug
RUN sed -i 's/^/#/' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

################
# FROM base AS prod
# The cli container is strictly for dev at this time.
File renamed without changes.
15 changes: 0 additions & 15 deletions docker/nginx/Dockerfile

This file was deleted.

36 changes: 0 additions & 36 deletions docker/nginx/default.conf

This file was deleted.

Loading