From eddef82460434cd51bdf939300f487db2e474c79 Mon Sep 17 00:00:00 2001 From: Marc Aschmann Date: Tue, 1 Oct 2024 22:19:33 +0200 Subject: [PATCH] add more useful standard build, add makefile --- .docker/Dockerfile => Dockerfile | 2 + Makefile | 66 ++++++++++++++++++++++++++++++ README.md | 9 ++-- docker-compose.yml => compose.yaml | 4 +- psalm.xml | 2 +- 5 files changed, 75 insertions(+), 8 deletions(-) rename .docker/Dockerfile => Dockerfile (98%) create mode 100644 Makefile rename docker-compose.yml => compose.yaml (59%) diff --git a/.docker/Dockerfile b/Dockerfile similarity index 98% rename from .docker/Dockerfile rename to Dockerfile index 1b1e8db..b6aff1b 100644 --- a/.docker/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ FROM php:8.3-cli +WORKDIR /app + ENV ANSIBLE_VERSION 2.9.17 # composer diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ad88589 --- /dev/null +++ b/Makefile @@ -0,0 +1,66 @@ +# Executables (local) +DOCKER_COMP = docker compose + +# Docker containers +PHP_CONT = $(DOCKER_COMP) exec php-ansible + +# Executables +PHP = $(PHP_CONT) php +COMPOSER = $(PHP_CONT) composer + +# Misc +.DEFAULT_GOAL = help + +## —— php-ansible Makefile 🎵 —————————————————————————————————— +help: ## Outputs this help screen + @grep -E '(^[a-zA-Z0-9\./_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/' + +## —— Docker 🐳 ———————————————————————————————————————————————————————————————— +build: ## Builds the Docker images + @$(DOCKER_COMP) build --pull --no-cache + +up: ## Start the docker hub in detached mode (no logs) + @$(DOCKER_COMP) up --detach + +start: build up ## Build and start the containers + +down: ## Stop the docker hub + @$(DOCKER_COMP) down --remove-orphans + +logs: ## Show live logs + @$(DOCKER_COMP) logs --tail=0 --follow + +sh: ## Connect to the php-fpm container + @$(PHP_CONT) sh + +bash: ## Connect to the php-fpm container via bash so up and down arrows go to previous commands + @$(PHP_CONT) bash + +test: ## Start tests with phpunit, pass the parameter "c=" to add options to phpunit, example: make test c="--group e2e --stop-on-failure" + @$(eval c ?=) + @$(PHP_CONT) vendor/bin/phpunit -c phpunit.xml.dist $(c) + +analyze: ## Start analysis with phpstan, pass the parameter "c=" to add options to phpstan. Default config ist always used, example: make analyze c="--group e2e" + @$(eval c ?=) + @$(PHP_CONT) vendor/bin/phpstan --configuration=phpstan.neon $(c) + +codestyle: ## Start codestyle analysis with phpcs, pass the parameter "c=" to add options to phpcs. Default config ist always used. Example: make codestyle c="--parallel=2" + @$(eval c ?=) + @$(PHP_CONT) vendor/bin/phpcs --standard=phpcs.xml.dist $(c) + +codestyle-fix: ## Start codestyle analysis with phpcbf, pass the parameter "c=" to add options to phpcbf. Default config ist always used. Example: make codestyle c="--parallel=2" + @$(eval c ?=) + @$(PHP_CONT) vendor/bin/phpcbf --standard=phpcs.xml.dist $(c) + +psalm: ## Start code analysis with psalm, pass the parameter "c=" to add options to psalm. Default config ist always used. Example: make codestyle c="--level=2" + @$(eval c ?=) + @$(DOCKER_COMP) exec -e APP_ENV=dev php vendor/bin/psalm --config=psalm.xml $(c) + +## —— Composer 🧙 —————————————————————————————————————————————————————————————— +composer: ## Run composer, pass the parameter "c=" to run a given command, example: make composer c='req phpstan/phpstan' + @$(eval c ?=) + @$(COMPOSER) $(c) + +vendor: ## Install vendors according to the current composer.lock file +vendor: c=install --prefer-dist --no-dev --no-progress --no-scripts --no-interaction +vendor: composer \ No newline at end of file diff --git a/README.md b/README.md index 243e4ca..44d619d 100644 --- a/README.md +++ b/README.md @@ -164,11 +164,10 @@ $ansible ## Development -You can use the provided docker image with ```docker compose up``` which uses a default php-cli docker image and ansible 2.x. See the ```.docker/Dockerfile``` for more info. - -Composer install: ```docker exec -u -w /var/php-ansible -it php-ansible composer install``` - -You can run code or the tests within the container: ```docker exec -u -w /var/php-ansible -it php-ansible php ./vendor/bin/phpunit --testdox``` +You can use the provided docker image with ```make build``` which uses a default php-cli docker image and ansible 2.x. See the ```Dockerfile``` for more info. +Start the container with ```make up```. +Composer install: ```make vendor``` +You can run code or the tests within the container: ```make test c="--testdox"``` ## Thank you for your contributions! diff --git a/docker-compose.yml b/compose.yaml similarity index 59% rename from docker-compose.yml rename to compose.yaml index bff0a05..2f0ea52 100644 --- a/docker-compose.yml +++ b/compose.yaml @@ -1,6 +1,6 @@ services: php-ansible: - build: ./.docker + build: . container_name: php-ansible volumes: - - ./:/var/php-ansible \ No newline at end of file + - ./:/app \ No newline at end of file diff --git a/psalm.xml b/psalm.xml index 8b0757c..b220368 100644 --- a/psalm.xml +++ b/psalm.xml @@ -2,7 +2,7 @@