Skip to content

Commit 912a6f4

Browse files
committed
* Docker flow updated
* Added docker compose examples to CONTRIBUTING.md * eol should always be LF
1 parent 920c549 commit 912a6f4

File tree

5 files changed

+81
-21
lines changed

5 files changed

+81
-21
lines changed

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
* text=auto eol=lf
12
.editorconfig export-ignore
23
.gitattributes export-ignore
34
/docs/ export-ignore
45
/scripts/ export-ignore
56
/tests/ export-ignore
6-
/.* export-ignore
7+
/.* export-ignore

CONTRIBUTING.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,81 @@ depending on your PHP version:
2222

2323
```bash
2424
git checkout -b my-new-patch origin/x.x.x
25+
```
26+
27+
### 3. Build
28+
29+
#### Local
30+
31+
```shell
2532
composer install
2633
```
2734

35+
#### With Docker CLI
36+
37+
```shell
38+
DOCKER_BUILDKIT=0 docker build -f ./docker/Dockerfile -t build .
39+
```
40+
41+
#### With `docker-compose.yml` (recommended)
42+
43+
```shell
44+
docker compose build setup
45+
```
46+
2847
### 3. Lint the code
2948

3049
Ensure the code is clean, just run the linters:
3150

51+
#### Local
52+
3253
```bash
3354
./vendor/bin/phpcs
3455
./vendor/bin/phpcbf
3556
```
3657

58+
#### With `docker-compose.yml` (recommended)
59+
60+
```shell
61+
docker compose build runLinting
62+
```
63+
3764
### 4. Run unit and integration tests
3865

3966
If you add new methods or make structural changes to the library then you need to add unit tests
4067
otherwise your PR will not be accepted.
4168
If you add new regexes make sure you commit the User-Agents in [`tests/providers/vendors`](https://github.com/serbanghita/Mobile-Detect/tree/master/tests/providers/vendors).
4269
Now that your changes are done, **run the unit tests**:
4370

71+
#### Locally
72+
4473
```bash
4574
vendor/bin/phpunit -v -c tests/phpunit.xml --coverage-html .coverage
4675
```
4776

77+
#### With `docker-compose.yml` (recommended)
78+
79+
```shell
80+
docker compose run runUnitTests
81+
```
82+
4883
Make sure you check the `.coverage` folder and open the report. \
4984
The coverage should be just like you first started (close to 100%).
5085

5186
### 5. Run performance tests
5287

88+
#### Local
89+
5390
```bash
5491
./vendor/bin/phpbench run tests/Benchmark/MobileDetectBench.php --ref=baseline --retry-threshold=1 --iterations=10 --revs=1000 --report=aggregate
5592
```
5693

94+
#### With `docker-compose.yml` (recommended)
95+
96+
```shell
97+
docker compose run runPerfTests
98+
```
99+
57100
Baseline re-creation:
58101

59102
```bash

docker-compose.yml

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
services:
22
setup:
3-
image: composer:latest
4-
command: >
5-
/bin/sh -c "
6-
rm -rf vendor &&
7-
rm -f composer.lock composer.phar &&
8-
set -xe && composer install &&
9-
composer -v &&
10-
ls -al"
11-
working_dir: /app
12-
volumes:
13-
- .:/app
3+
build:
4+
context: .
5+
dockerfile: ./docker/Dockerfile
146

157
runUnitTests:
16-
depends_on: ['setup']
8+
depends_on:
9+
setup:
10+
condition: service_completed_successfully
1711
image: php:8.3-rc-alpine3.18
1812
working_dir: /app
1913
command: >
@@ -22,33 +16,41 @@ services:
2216
- .:/app
2317

2418
runPerfTests:
25-
depends_on: ['setup']
19+
depends_on:
20+
setup:
21+
condition: service_completed_successfully
2622
image: php:8.3-rc-alpine3.18
2723
working_dir: /app
2824
command: >
29-
/bin/sh -c "vendor/bin/phpbench run tests/Benchmark/MobileDetectBench.php --retry-threshold=1 --iterations=10 --revs=1000 --report=aggregate"
25+
/bin/sh -c "vendor/bin/phpbench run tests/benchmark/MobileDetectBench.php --retry-threshold=1 --iterations=10 --revs=1000 --report=aggregate"
3026
volumes:
3127
- .:/app
3228

3329
runLinting:
34-
depends_on: ['setup']
30+
depends_on:
31+
setup:
32+
condition: service_completed_successfully
3533
image: php:8.3-rc-alpine3.18
3634
working_dir: /app
3735
command: >
3836
/bin/sh -c "vendor/bin/phpcs; vendor/bin/phpcbf"
39-
ports:
40-
- "8000:8000"
4137
volumes:
4238
- .:/app
4339

4440
generateModel:
45-
depends_on: ['setup', 'runUnitTests', 'runPerfTests', 'runLinting']
41+
depends_on:
42+
setup:
43+
condition: service_completed_successfully
44+
runUnitTests:
45+
condition: service_completed_successfully
46+
runPerfTests:
47+
condition: service_completed_successfully
48+
runLinting:
49+
condition: service_completed_successfully
4650
image: php:8.3-rc-alpine3.18
4751
working_dir: /app
4852
command: >
4953
/bin/sh -c "php ./scripts/export_to_json.php"
50-
ports:
51-
- "8000:8000"
5254
volumes:
5355
- .:/app
5456

docker/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM composer:latest AS build
2+
WORKDIR /app
3+
COPY ./ .
4+
COPY ./docker/build.sh .
5+
RUN pwd
6+
RUN ls -al
7+
# Make the script executable
8+
RUN chmod +x build.sh
9+
RUN ./build.sh

docker/build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
echo "Start building ..."
2+
rm -rf vendor
3+
rm -f composer.lock composer.phar
4+
set -xe
5+
composer install

0 commit comments

Comments
 (0)