Skip to content

Commit ab08efa

Browse files
committed
Refactor docker container to be able to run any PHP version from 7.4
Thanks AI for 😄: - update Dockerfile - update docker-compose - create Makefile Update code with: - CS Fixer - Rector
1 parent 10240e5 commit ab08efa

43 files changed

Lines changed: 222 additions & 55 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.docker/Dockerfile

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
1-
FROM splitbrain/phpfarm:jessie
1+
FROM debian:trixie-slim
22

3-
RUN apt-get update && apt-get install -y git zip
3+
# Prevent interactive prompts
4+
ENV DEBIAN_FRONTEND=noninteractive
45

6+
# Install dependencies
7+
RUN apt-get update && apt-get install -y \
8+
apt-transport-https \
9+
ca-certificates \
10+
curl \
11+
git \
12+
lsb-release \
13+
unzip \
14+
zip \
15+
&& curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg \
16+
&& echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list \
17+
&& apt-get update
18+
19+
# Supported PHP Versions
20+
ENV PHP_VERSIONS="7.4 8.0 8.1 8.2 8.3 8.4 8.5"
21+
22+
# Install all PHP versions using a loop
23+
RUN for ver in $PHP_VERSIONS; do \
24+
apt-get install -y \
25+
php${ver}-cli php${ver}-xml php${ver}-mbstring php${ver}-soap; \
26+
done \
27+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
28+
29+
# Create symlinks (php-X.Y) using the same list
30+
RUN for ver in $PHP_VERSIONS; do \
31+
ln -s /usr/bin/php${ver} /usr/bin/php-${ver}; \
32+
done
33+
34+
# Install Composer
535
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
36+
37+
# Set working directory
38+
WORKDIR /var/www
39+
40+
# Copy project files
641
COPY . /var/www/
742

8-
WORKDIR /var/www/
43+
# Default command
44+
CMD ["bash"]

.github/workflows/sonars.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
- release/*
99
pull_request:
1010
types: [ opened, synchronize, reopened ]
11+
concurrency: sonars
1112
jobs:
1213
sonarcloud:
1314
name: Sonars
@@ -46,7 +47,7 @@ jobs:
4647
run: sed -i 's@'$GITHUB_WORKSPACE/'@''@g' coverage.xml report.xml
4748

4849
- name: SonarCloud Scan
49-
uses: SonarSource/sonarcloud-github-action@master
50+
uses: SonarSource/sonarqube-scan-action@v7
5051
env:
5152
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5253
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule ".docker"]
2+
path = .docker
3+
url = git@github.com:WsdlToPhp/DockerCommonImage.git

.php-cs-fixer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
->setRules(array(
1111
'@PhpCsFixer' => true,
1212
'phpdoc_separation' => false,
13+
'single_line_empty_body' => false,
1314
))
1415
->setFinder($finder);

Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
PHP_VERSION ?= php-7.4
2+
CONTAINER_NAME ?= package_generator
3+
COMPOSER ?= /usr/bin/composer
4+
DOCKER_COMPOSE ?= docker compose
5+
DOCKER_EXEC_CONTAINER ?= docker exec -t $(CONTAINER_NAME)
6+
7+
.PHONY: bash build cs-fixer down install phpstan phpunit rector up update
8+
9+
bash:
10+
$(DOCKER_EXEC_CONTAINER) bash
11+
12+
build:
13+
$(DOCKER_COMPOSE) build
14+
15+
cs-fixer:
16+
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) vendor/bin/php-cs-fixer fix --ansi --diff --verbose
17+
18+
down:
19+
$(DOCKER_COMPOSE) down
20+
21+
install:
22+
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) $(COMPOSER) install
23+
24+
phpstan:
25+
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) vendor/bin/phpstan analyze src --level=2
26+
27+
phpunit:
28+
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) vendor/bin/phpunit
29+
30+
rector:
31+
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) vendor/bin/rector process
32+
33+
up:
34+
$(DOCKER_COMPOSE) up -d
35+
36+
update:
37+
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) $(COMPOSER) update

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ Thanks to the [Docker image](https://hub.docker.com/r/splitbrain/phpfarm) of [ph
128128

129129
First of all, you need to create your container which you can do using [docker-compose](https://docs.docker.com/compose/) by running the below command line from the root directory of the project:
130130
```bash
131-
$ docker-compose up -d --build
131+
$ make build up
132132
```
133133

134134
You then have a container named `package_generator` in which you can run `composer` commands and `php cli` commands such as:
135135
```bash
136136
# install deps in container (using update ensure it does use the composer.lock file if there is any)
137-
$ docker exec -it package_generator php-7.4 /usr/bin/composer update
137+
$ make update
138138
# run tests in container
139-
$ docker exec -it package_generator php-7.4 -dmemory_limit=-1 vendor/bin/phpunit
139+
$ make phpunit
140140
```
141141

142142
## Contributing

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@
129129
},
130130
"require-dev": {
131131
"friendsofphp/php-cs-fixer": "^3.0",
132-
"phpstan/phpstan": "^1.3",
132+
"phpstan/phpstan": "^2",
133133
"phpunit/phpunit": "^9",
134-
"rector/rector": "^0.15.17"
134+
"rector/rector": "^2"
135135
},
136136
"autoload": {
137137
"psr-4": {

docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3.4'
2-
31
services:
42
php:
53
build:
@@ -8,3 +6,4 @@ services:
86
volumes:
97
- .:/var/www:rw
108
container_name: package_generator
9+
tty: true

rector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
declare(strict_types=1);
44

55
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
6-
use Rector\CodeQuality\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector;
76
use Rector\Config\RectorConfig;
7+
use Rector\Php84\Rector\Param\ExplicitNullableParamTypeRector;
88
use Rector\Set\ValueObject\LevelSetList;
99
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNativeCallRector;
1010
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedPropertyRector;
@@ -30,6 +30,6 @@
3030
// register a single rule
3131
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
3232
$rectorConfig->rule(ReturnTypeFromStrictNativeCallRector::class);
33-
$rectorConfig->rule(ReturnTypeFromStrictScalarReturnExprRector::class);
3433
$rectorConfig->rule(ReturnTypeFromStrictTypedPropertyRector::class);
34+
$rectorConfig->rule(ExplicitNullableParamTypeRector::class);
3535
};

src/ConfigurationReader/AbstractYamlReader.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ abstract protected function __construct(string $filename);
1616

1717
abstract public static function getDefaultConfigurationPath(): string;
1818

19+
/**
20+
* @throws \InvalidArgumentException
21+
*/
1922
public static function instance(?string $filename = null): self
2023
{
2124
$loadFilename = empty($filename) ? static::getDefaultConfigurationPath() : $filename;
@@ -46,6 +49,9 @@ protected function loadYaml(string $filename)
4649
return $ymlParser->parse(file_get_contents($filename));
4750
}
4851

52+
/**
53+
* @throws \InvalidArgumentException
54+
*/
4955
protected function parseSimpleArray(string $filename, string $mainKey): array
5056
{
5157
$values = $this->loadYaml($filename);

0 commit comments

Comments
 (0)