Skip to content

Commit

Permalink
Merge pull request #590 from Slamdunk/docker_local_build
Browse files Browse the repository at this point in the history
Local build: require `docker compose` only
  • Loading branch information
Slamdunk authored Oct 28, 2024
2 parents 4957bd7 + 4712664 commit 8ae14f5
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 3 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
vendor
composer.phar
/vendor
.env
clover.xml
infectionlog.txt
.phpunit.result.cache
.phpcs-cache
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM php:8.2

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

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
50 changes: 50 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
ifdef CI
DOCKER_PHP_EXEC :=
else
DOCKER_PHP_EXEC := docker compose run --rm php
endif

SRCS := $(shell find ./src ./test -type f)

default: unit cs static-analysis coverage ## all the things

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

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

vendor: .env docker-compose.yml Dockerfile composer.json
docker compose build --pull
$(DOCKER_PHP_EXEC) composer update
$(DOCKER_PHP_EXEC) composer bump
touch --no-create $@

.PHONY: unit
unit: vendor ## run unit tests
$(DOCKER_PHP_EXEC) vendor/bin/phpunit

.PHONY: cs
cs: vendor ## verify code style rules
$(DOCKER_PHP_EXEC) vendor/bin/phpcbf -p || true
$(DOCKER_PHP_EXEC) vendor/bin/phpcs -p

.PHONY: static-analysis
static-analysis: vendor ## verify that no static analysis issues were introduced
$(DOCKER_PHP_EXEC) vendor/bin/psalm

.PHONY: bc-check
bc-check: vendor ## check for backwards compatibility breaks
mkdir -p /tmp/bc-check
$(DOCKER_PHP_EXEC) composer require --no-plugins -d/tmp/bc-check roave/backward-compatibility-check
$(DOCKER_PHP_EXEC) /tmp/bc-check/vendor/bin/roave-backward-compatibility-check
rm -Rf /tmp/bc-check

.PHONY: coverage
coverage: vendor ## generate code coverage reports
$(DOCKER_PHP_EXEC) vendor/bin/roave-infection-static-analysis-plugin --show-mutations

.PHONY: clean
clean:
git clean -dfX
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
php:
build:
context: .
args:
USER_ID: ${USER_ID}
GROUP_ID: ${GROUP_ID}
volumes:
- .:${PWD}
working_dir: ${PWD}

0 comments on commit 8ae14f5

Please sign in to comment.