Skip to content

Commit 45b3192

Browse files
committed
Local build: rely only on docker
1 parent 71e0960 commit 45b3192

File tree

5 files changed

+57
-18
lines changed

5 files changed

+57
-18
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
/*.dist export-ignore
99
/phpbench.json export-ignore
1010
/composer.lock export-ignore
11+
/docker-compose.yml export-ignore
12+
/Dockerfile export-ignore
1113
/README.md export-ignore
1214
/Makefile export-ignore
1315
/.roave-backward-compatibility-check.json export-ignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ phpunit.xml
33
infection.txt
44
coverage
55
phpcs.xml
6+
/.env
67
/.phpcs.cache
78
/.phpunit.result.cache
89
/.phpunit.cache

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM php:8.4
2+
3+
# git needed for Infection
4+
RUN apt-get update \
5+
&& apt-get -y install --no-install-recommends \
6+
git
7+
8+
ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
9+
10+
RUN install-php-extensions @composer pcov
11+
12+
# Mapping the host user to the docker one ensure
13+
# files have the same permissions
14+
ARG USER_ID
15+
ARG GROUP_ID
16+
17+
RUN groupadd --gid ${GROUP_ID} code \
18+
&& useradd --create-home --shell /bin/bash --uid ${USER_ID} --gid code code
19+
20+
USER code

Makefile

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,45 @@
1+
ifdef CI
2+
DOCKER_PHP_EXEC :=
3+
else
4+
DOCKER_PHP_EXEC := docker compose run --rm php
5+
endif
16
PARALLELISM := $(shell nproc)
27

38
.PHONY: all
4-
all: install phpcbf phpcs phpstan phpunit infection phpbench
9+
all: phpcbf phpcs phpstan phpunit infection phpbench
510

6-
.PHONY: install
7-
install: vendor/composer/installed.json
11+
.env: /etc/passwd /etc/group Makefile
12+
printf "USER_ID=%s\nGROUP_ID=%s\n" `id --user "${USER}"` `id --group "${USER}"` > .env
813

9-
vendor/composer/installed.json: composer.json composer.lock
10-
@composer install $(INSTALL_FLAGS)
14+
vendor/composer/installed.json: composer.json composer.lock .env docker-compose.yml Dockerfile
15+
@$(DOCKER_PHP_EXEC) composer install $(INSTALL_FLAGS)
1116
@touch -c composer.json composer.lock vendor/composer/installed.json
1217

1318
.PHONY: phpunit
14-
phpunit:
15-
@php -d assert.exception=1 -d zend.assertions=1 vendor/bin/phpunit $(PHPUNIT_FLAGS)
19+
phpunit: vendor/composer/installed.json
20+
@$(DOCKER_PHP_EXEC) php -d assert.exception=1 -d zend.assertions=1 vendor/bin/phpunit $(PHPUNIT_FLAGS)
1621

1722
.PHONY: infection
18-
infection:
19-
@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)
20-
@php -d assert.exception=1 -d zend.assertions=1 vendor/bin/infection -v -s --threads=$(PARALLELISM) --coverage=build --skip-initial-tests $(INFECTION_FLAGS)
23+
infection: vendor/composer/installed.json
24+
@$(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)
25+
@$(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)
2126

2227
.PHONY: phpcbf
23-
phpcbf:
24-
@vendor/bin/phpcbf --parallel=$(PARALLELISM) || true
28+
phpcbf: vendor/composer/installed.json
29+
@$(DOCKER_PHP_EXEC) vendor/bin/phpcbf --parallel=$(PARALLELISM) || true
2530

2631
.PHONY: phpcs
27-
phpcs:
28-
@vendor/bin/phpcs --parallel=$(PARALLELISM) $(PHPCS_FLAGS)
32+
phpcs: vendor/composer/installed.json
33+
@$(DOCKER_PHP_EXEC) vendor/bin/phpcs --parallel=$(PARALLELISM) $(PHPCS_FLAGS)
2934

3035
.PHONY: phpstan
31-
phpstan:
32-
@php -d xdebug.mode=off vendor/bin/phpstan analyse --memory-limit=-1
36+
phpstan: vendor/composer/installed.json
37+
@$(DOCKER_PHP_EXEC) php -d xdebug.mode=off vendor/bin/phpstan analyse --memory-limit=-1
3338

3439
ifndef PHPBENCH_REPORT
3540
override PHPBENCH_REPORT = aggregate
3641
endif
3742

3843
.PHONY: phpbench
39-
phpbench:
40-
@vendor/bin/phpbench run -l dots --retry-threshold=5 --report=$(PHPBENCH_REPORT) $(PHPBENCH_FLAGS)
44+
phpbench: vendor/composer/installed.json
45+
@$(DOCKER_PHP_EXEC) vendor/bin/phpbench run -l dots --retry-threshold=5 --report=$(PHPBENCH_REPORT) $(PHPBENCH_FLAGS)

docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
services:
2+
php:
3+
build:
4+
context: .
5+
args:
6+
USER_ID: ${USER_ID}
7+
GROUP_ID: ${GROUP_ID}
8+
# Same paths mean stack traces from docker are usable in host too
9+
volumes:
10+
- .:${PWD}
11+
working_dir: ${PWD}

0 commit comments

Comments
 (0)