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

Local build: rely only on docker #1094

Open
wants to merge 1 commit into
base: 5.5.x
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
/*.dist export-ignore
/phpbench.json export-ignore
/composer.lock export-ignore
/docker-compose.yml export-ignore
/Dockerfile export-ignore
/README.md export-ignore
/Makefile export-ignore
/.roave-backward-compatibility-check.json export-ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ phpunit.xml
infection.txt
coverage
phpcs.xml
/.env
/.phpcs.cache
/.phpunit.result.cache
/.phpunit.cache
Expand Down
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM php:8.4

# git needed for Infection
RUN apt-get update \
&& apt-get -y install --no-install-recommends \
git

ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN install-php-extensions @composer pcov

# Mapping the host user to the docker one ensure
# files have the same permissions
ARG USER_ID
ARG GROUP_ID

RUN groupadd --gid ${GROUP_ID} code \
&& useradd --create-home --shell /bin/bash --uid ${USER_ID} --gid code code

USER code
41 changes: 23 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
ifdef CI
DOCKER_PHP_EXEC :=
else
DOCKER_PHP_EXEC := docker compose run --rm php
endif
PARALLELISM := $(shell nproc)

.PHONY: all
all: install phpcbf phpcs phpstan phpunit infection phpbench
all: phpcbf phpcs phpstan phpunit infection phpbench

.PHONY: install
install: vendor/composer/installed.json
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to remember to run make install, just add vendor/composer/installed.json as a prerequisit for every other target

.env: /etc/passwd /etc/group Makefile
printf "USER_ID=%s\nGROUP_ID=%s\n" `id --user "${USER}"` `id --group "${USER}"` > .env

vendor/composer/installed.json: composer.json composer.lock
@composer install $(INSTALL_FLAGS)
vendor/composer/installed.json: composer.json composer.lock .env docker-compose.yml Dockerfile
@$(DOCKER_PHP_EXEC) composer install $(INSTALL_FLAGS)
@touch -c composer.json composer.lock vendor/composer/installed.json

.PHONY: phpunit
phpunit:
@php -d assert.exception=1 -d zend.assertions=1 vendor/bin/phpunit $(PHPUNIT_FLAGS)
phpunit: vendor/composer/installed.json
@$(DOCKER_PHP_EXEC) php -d assert.exception=1 -d zend.assertions=1 vendor/bin/phpunit $(PHPUNIT_FLAGS)

.PHONY: infection
infection:
@php -d assert.exception=1 -d zend.assertions=1 -d xdebug.mode=coverage vendor/bin/phpunit --coverage-xml=build/coverage-xml --log-junit=build/junit.xml $(PHPUNIT_FLAGS)
@php -d assert.exception=1 -d zend.assertions=1 vendor/bin/infection -v -s --threads=$(PARALLELISM) --coverage=build --skip-initial-tests $(INFECTION_FLAGS)
infection: vendor/composer/installed.json
@$(DOCKER_PHP_EXEC) php -d assert.exception=1 -d zend.assertions=1 -d xdebug.mode=coverage vendor/bin/phpunit --coverage-xml=build/coverage-xml --log-junit=build/junit.xml $(PHPUNIT_FLAGS)
@$(DOCKER_PHP_EXEC) php -d assert.exception=1 -d zend.assertions=1 vendor/bin/infection -v -s --threads=$(PARALLELISM) --coverage=build --skip-initial-tests $(INFECTION_FLAGS)

.PHONY: phpcbf
phpcbf:
@vendor/bin/phpcbf --parallel=$(PARALLELISM) || true
phpcbf: vendor/composer/installed.json
@$(DOCKER_PHP_EXEC) vendor/bin/phpcbf --parallel=$(PARALLELISM) || true

.PHONY: phpcs
phpcs:
@vendor/bin/phpcs --parallel=$(PARALLELISM) $(PHPCS_FLAGS)
phpcs: vendor/composer/installed.json
@$(DOCKER_PHP_EXEC) vendor/bin/phpcs --parallel=$(PARALLELISM) $(PHPCS_FLAGS)

.PHONY: phpstan
phpstan:
@php -d xdebug.mode=off vendor/bin/phpstan analyse --memory-limit=-1
phpstan: vendor/composer/installed.json
@$(DOCKER_PHP_EXEC) php -d xdebug.mode=off vendor/bin/phpstan analyse --memory-limit=-1

ifndef PHPBENCH_REPORT
override PHPBENCH_REPORT = aggregate
endif

.PHONY: phpbench
phpbench:
@vendor/bin/phpbench run -l dots --retry-threshold=5 --report=$(PHPBENCH_REPORT) $(PHPBENCH_FLAGS)
phpbench: vendor/composer/installed.json
@$(DOCKER_PHP_EXEC) vendor/bin/phpbench run -l dots --retry-threshold=5 --report=$(PHPBENCH_REPORT) $(PHPBENCH_FLAGS)
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
php:
build:
context: .
args:
USER_ID: ${USER_ID}
GROUP_ID: ${GROUP_ID}
# Same paths mean stack traces from docker are usable in host too
volumes:
- .:${PWD}
working_dir: ${PWD}
Loading