Skip to content

Commit

Permalink
feat: docker update (#52)
Browse files Browse the repository at this point in the history
* feat: docker update

* feat: sonar cube review
  • Loading branch information
Benoit382 authored May 7, 2024
1 parent c2d5f3d commit 10d9aa9
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 130 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
5 changes: 0 additions & 5 deletions .env.example

This file was deleted.

8 changes: 4 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ updates:
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2']
php: ['8.1', '8.2', '8.3']
name: Tests - PHP ${{ matrix.php }}
concurrency:
group: ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}-${{ matrix.php }}
Expand Down
21 changes: 9 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
# Created by .ignore support plugin (hsz.mobi)
### Example user template template
### Example user template
# Folder use for the coverage
/build/
/bin/

# IntelliJ project files
# IntelliJ project files (should on developer pc not here)
.idea
*.iml
out
gen### Composer template
composer.phar

## Never send vendor
/vendor/
/log/
/tests/tmp/*
.env
/xdebug_profile/

# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file https://getcomposer.org/doc/02-libraries.md#lock-file
composer.lock

## Temporary test files

/tests/tmp/*
## Phpunit and cs-fixer cache file
.phpunit.result.cache
.php-cs-fixer.cache
28 changes: 15 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@

php-setup:
test -e .env || cp .env.example .env
docker compose down
docker compose rm
docker compose build
docker compose up -d --force-recreate
make composer install
docker build -t openfoodfacts-php -f ./docker/Dockerfile .

install:
docker compose exec php-fpm bash -c 'XDEBUG_MODE=off composer install'
.PHONY: ci
ci: cs-check phpstan test

fix:
docker compose exec php-fpm bash -c 'XDEBUG_MODE=off ./vendor/bin/php-cs-fixer fix'
.PHONY: cs-check
cs-check:
docker run -v ${PWD}/src:/opt/app/src -v ${PWD}/tests:/opt/app/tests openfoodfacts-php php ./vendor/bin/php-cs-fixer check

.PHONY: cs-fix
cs-fix:
docker run -v ${PWD}/src:/opt/app/src -v ${PWD}/tests:/opt/app/tests openfoodfacts-php php ./vendor/bin/php-cs-fixer fix

.PHONY: test
test:
docker compose exec php-fpm bash -c 'XDEBUG_MODE=off ./vendor/bin/phpunit'
docker run -v ${PWD}/src:/opt/app/src -v ${PWD}/tests:/opt/app/tests -v ${PWD}/build:/opt/app/build -u $(id -u ${USER}):$(id -g ${USER}) openfoodfacts-php php ./vendor/bin/phpunit

composer:
docker compose exec php-fpm bash -c "XDEBUG_MODE=off composer $(filter-out $@,$(MAKECMDGOALS))"
.PHONY: phpstan
phpstan:
docker run -v ${PWD}/src:/opt/app/src -v ${PWD}/tests:/opt/app/tests -v ${PWD}/build:/opt/app/build openfoodfacts-php php ./vendor/bin/phpstan
25 changes: 0 additions & 25 deletions docker-compose.yml

This file was deleted.

29 changes: 29 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# syntax=docker/dockerfile:experimental
FROM composer:2 AS COMPOSER
WORKDIR /opt/app
COPY composer.json .
RUN composer install --no-scripts --ignore-platform-reqs

#no need php-fpm when all command use php-cli
FROM php:8-bookworm
WORKDIR /opt/app
# Install php-src extensions
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq update && \
apt-get -qq --no-install-recommends install libpng-dev libjpeg-dev
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
RUN docker-php-ext-install -j$(nproc) gd bcmath
RUN rm -rf /tmp/pear /var/lib/apt/lists/*
RUN mkdir /tmp/profile; chmod 755 /tmp/profile

USER nobody
COPY ./docker/xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

COPY --from=COMPOSER /opt/app /opt/app
# Not permited by Sonar cube even though there is .dockerignore to remove sensitive data
#COPY . .
COPY src .
COPY tests .
COPY .php-cs-fixer.dist.php .
COPY phpunit.xml .
COPY phpstan.neon.dist .
50 changes: 0 additions & 50 deletions docker/php/Dockerfile

This file was deleted.

6 changes: 0 additions & 6 deletions docker/php/docker-php-ext-xdebug.ini

This file was deleted.

7 changes: 0 additions & 7 deletions docker/php/fpm_additional.conf

This file was deleted.

4 changes: 0 additions & 4 deletions docker/php/php.ini

This file was deleted.

3 changes: 3 additions & 0 deletions docker/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
zend_extension=xdebug

xdebug.mode=coverage
6 changes: 3 additions & 3 deletions examples/01-basic_api_usage/cached_example.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

<?php

use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Psr16Cache;

include '../../vendor/autoload.php';
include_once '../../vendor/autoload.php';
$logger = new \Psr\Log\NullLogger;
$httpClient = new \GuzzleHttp\Client();
// the PSR-6 cache object that you want to use (you might also use a PSR-16 Interface Object directly)
$psr6Cache = new FilesystemAdapter();
$psr16Cache = new Psr16Cache($psr6Cache);
$api = new \OpenFoodFacts\Api('food', 'world', $logger, $httpClient, $psr16Cache);
$product = $api->getProduct(rand(1, 50));
$product = $api->getProduct(random_int(1, 50));
Empty file removed xdebug_profile/.gitkeep
Empty file.

0 comments on commit 10d9aa9

Please sign in to comment.