Skip to content

Commit

Permalink
Local build: rely only on docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk committed Dec 10, 2024
1 parent 18ffde8 commit fadd502
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 18 deletions.
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
.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}

0 comments on commit fadd502

Please sign in to comment.