Skip to content

Commit

Permalink
* Docker flow updated
Browse files Browse the repository at this point in the history
* Added docker compose examples to CONTRIBUTING.md
* eol should always be LF
  • Loading branch information
serbanghita committed Oct 20, 2024
1 parent 920c549 commit 912a6f4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
* text=auto eol=lf
.editorconfig export-ignore
.gitattributes export-ignore
/docs/ export-ignore
/scripts/ export-ignore
/tests/ export-ignore
/.* export-ignore
/.* export-ignore
43 changes: 43 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,81 @@ depending on your PHP version:

```bash
git checkout -b my-new-patch origin/x.x.x
```

### 3. Build

#### Local

```shell
composer install
```

#### With Docker CLI

```shell
DOCKER_BUILDKIT=0 docker build -f ./docker/Dockerfile -t build .
```

#### With `docker-compose.yml` (recommended)

```shell
docker compose build setup
```

### 3. Lint the code

Ensure the code is clean, just run the linters:

#### Local

```bash
./vendor/bin/phpcs
./vendor/bin/phpcbf
```

#### With `docker-compose.yml` (recommended)

```shell
docker compose build runLinting
```

### 4. Run unit and integration tests

If you add new methods or make structural changes to the library then you need to add unit tests
otherwise your PR will not be accepted.
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).
Now that your changes are done, **run the unit tests**:

#### Locally

```bash
vendor/bin/phpunit -v -c tests/phpunit.xml --coverage-html .coverage
```

#### With `docker-compose.yml` (recommended)

```shell
docker compose run runUnitTests
```

Make sure you check the `.coverage` folder and open the report. \
The coverage should be just like you first started (close to 100%).

### 5. Run performance tests

#### Local

```bash
./vendor/bin/phpbench run tests/Benchmark/MobileDetectBench.php --ref=baseline --retry-threshold=1 --iterations=10 --revs=1000 --report=aggregate
```

#### With `docker-compose.yml` (recommended)

```shell
docker compose run runPerfTests
```

Baseline re-creation:

```bash
Expand Down
42 changes: 22 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
services:
setup:
image: composer:latest
command: >
/bin/sh -c "
rm -rf vendor &&
rm -f composer.lock composer.phar &&
set -xe && composer install &&
composer -v &&
ls -al"
working_dir: /app
volumes:
- .:/app
build:
context: .
dockerfile: ./docker/Dockerfile

runUnitTests:
depends_on: ['setup']
depends_on:
setup:
condition: service_completed_successfully
image: php:8.3-rc-alpine3.18
working_dir: /app
command: >
Expand All @@ -22,33 +16,41 @@ services:
- .:/app

runPerfTests:
depends_on: ['setup']
depends_on:
setup:
condition: service_completed_successfully
image: php:8.3-rc-alpine3.18
working_dir: /app
command: >
/bin/sh -c "vendor/bin/phpbench run tests/Benchmark/MobileDetectBench.php --retry-threshold=1 --iterations=10 --revs=1000 --report=aggregate"
/bin/sh -c "vendor/bin/phpbench run tests/benchmark/MobileDetectBench.php --retry-threshold=1 --iterations=10 --revs=1000 --report=aggregate"
volumes:
- .:/app

runLinting:
depends_on: ['setup']
depends_on:
setup:
condition: service_completed_successfully
image: php:8.3-rc-alpine3.18
working_dir: /app
command: >
/bin/sh -c "vendor/bin/phpcs; vendor/bin/phpcbf"
ports:
- "8000:8000"
volumes:
- .:/app

generateModel:
depends_on: ['setup', 'runUnitTests', 'runPerfTests', 'runLinting']
depends_on:
setup:
condition: service_completed_successfully
runUnitTests:
condition: service_completed_successfully
runPerfTests:
condition: service_completed_successfully
runLinting:
condition: service_completed_successfully
image: php:8.3-rc-alpine3.18
working_dir: /app
command: >
/bin/sh -c "php ./scripts/export_to_json.php"
ports:
- "8000:8000"
volumes:
- .:/app

Expand Down
9 changes: 9 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM composer:latest AS build
WORKDIR /app
COPY ./ .
COPY ./docker/build.sh .
RUN pwd
RUN ls -al
# Make the script executable
RUN chmod +x build.sh
RUN ./build.sh
5 changes: 5 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
echo "Start building ..."
rm -rf vendor
rm -f composer.lock composer.phar
set -xe
composer install

0 comments on commit 912a6f4

Please sign in to comment.