Skip to content

Commit

Permalink
Update docker environment and CONTRIBUTING.md
Browse files Browse the repository at this point in the history
Use the docker environment in GitHub Actions too
  • Loading branch information
ajgarlag committed Nov 11, 2021
1 parent 2711479 commit 0ef9d1c
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 106 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ name: "coding standards"
on: ["pull_request", "push"]

jobs:
coding-standards:
name: "coding standards"
runs-on: "ubuntu-latest"
steps:
- name: "checkout"
uses: "actions/checkout@v2"
coding-standards:
name: "coding standards"
runs-on: "ubuntu-latest"
steps:
- name: "checkout"
uses: "actions/checkout@v2"

- name: "installing PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "7.4"
ini-values: memory_limit=-1
tools: composer:v2, cs2pr, php-cs-fixer
- name: "build the environment"
run: "dev/bin/docker-compose build"

- name: "checking coding standards"
run: "php-cs-fixer fix --dry-run --diff --ansi"
- name: "checking coding standards"
run: "dev/bin/php php-cs-fixer fix --dry-run --diff --ansi"

- name: Clear docker volumes
if: ${{ always() }}
run: dev/bin/docker-compose down --volumes
34 changes: 15 additions & 19 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@ name: "static analysis"
on: ["pull_request", "push"]

jobs:
static-analysis:
name: "static analysis"
runs-on: "ubuntu-latest"
steps:
- name: "checkout"
uses: "actions/checkout@v2"
static-analysis:
name: "static analysis"
runs-on: "ubuntu-latest"
steps:
- name: "checkout"
uses: "actions/checkout@v2"

- name: "installing PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "7.4"
ini-values: memory_limit=-1
tools: composer:v2, cs2pr
extensions: intl, bcmath, curl, openssl, mbstring, pdo, pdo_sqlite
- name: "build the environment"
run: "dev/bin/docker-compose build"

- name: "installing psalm"
run: "composer require vimeo/psalm:^4.6 psalm/plugin-symfony:^2.2 --dev --no-update && composer require --no-update"
- name: "install dependencies"
run: "dev/bin/php composer update --prefer-stable"

- name: "installing dependencies"
run: "composer update --no-interaction --no-progress"
- name: "running static analysis"
run: "dev/bin/php psalm --shepherd --stats"

- name: "running static analysis"
run: "vendor/bin/psalm --shepherd --stats"
- name: Clear docker volumes
if: ${{ always() }}
run: dev/bin/docker-compose down --volumes
64 changes: 25 additions & 39 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,45 @@ jobs:
strategy:
fail-fast: false
matrix:
#Stable supported versions
php: ['7.3', '7.4', '8.0']
symfony: ['5.3.*']
composer-flags: ['--prefer-stable']
can-fail: [false]
include:
# Lowest supported stable Symfony branches
# Lowest supported versions
- php: 7.2
symfony: 5.3.*
composer-flags: '--prefer-stable'
composer-flags: '--prefer-stable --prefer-lowest'
can-fail: false
# Development Symfony branches
- php: 7.3
symfony: 5.4.*@dev
composer-flags: '--prefer-stable' # Needed to force `lcobucci/jwt` to install a usable version
can-fail: false
- php: 7.4
symfony: 5.4.*@dev
composer-flags: ''
can-fail: false
- php: 8.0
symfony: 5.4.*@dev
# Development versions
- php: 8.1.0RC5
symfony: 5.4.x-dev
composer-flags: ''
can-fail: false
- php: 8.1
symfony: 6.0.*@dev
- php: 8.1.0RC5
symfony: 6.0.x-dev
composer-flags: ''
can-fail: false

name: "PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}"

env:
SYMFONY_REQUIRE: ${{ matrix.symfony }}

steps:
- name: "Checkout"
- name: "checkout"
uses: "actions/checkout@v2"
with:
fetch-depth: 2

- name: "Cache Composer packages"
uses: "actions/cache@v2"
with:
path: "~/.composer/cache"
key: "php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-composer-${{ hashFiles('composer.json') }}-flags-${{ matrix.composer-flags }}"
restore-keys: "php-"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php }}"
tools: "composer:v2,flex"
- name: "build the environment"
run: "dev/bin/docker-compose build --build-arg PHP_VERSION=${{ matrix.php }} php"

- name: "Set Composer stability"
if: "matrix.symfony == '5.4.*@dev' || matrix.symfony == '6.0.*@dev'"
run: "composer config minimum-stability dev"
- name: "install dependencies"
run: "dev/bin/php composer update --ansi ${{ matrix.composer-flags }}"

- name: "Install dependencies"
run: "composer update ${{ matrix.composer-flags }} --prefer-dist"
env:
SYMFONY_REQUIRE: "${{ matrix.symfony }}"
- name: "running unit tests"
run: "dev/bin/php-test vendor/bin/simple-phpunit --colors=always"

- name: "Run PHPUnit Tests"
run: "vendor/bin/simple-phpunit"
- name: Clear docker volumes
if: ${{ always() }}
run: dev/bin/docker-compose down --volumes
18 changes: 13 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ dev/bin/docker-compose build

> **NOTE:** You can target a different version of PHP during development by appending the `--build-arg PHP_VERSION=<version>` argument.
After that, install all the needed packages required to develop the project:
After that, download all the needed packages required to develop the project:

```sh
dev/bin/php composer install
dev/bin/php composer update --prefer-stable
```

### Debugging

You can run the debugger using the following command:

```sh
dev/bin/php-debug vendor/bin/phpunit
dev/bin/php-debug vendor/bin/simple-phpunit
```

Make sure your IDE is setup properly, for more information check out the [dedicated documentation](docs/debugging.md).
Expand All @@ -49,15 +49,23 @@ Make sure your IDE is setup properly, for more information check out the [dedica
This bundle enforces the PSR-2 and Symfony code standards during development by using the [PHP CS Fixer](https://cs.sensiolabs.org/) utility. Before committing any code, you can run the utility to fix any potential rule violations:

```sh
dev/bin/php composer lint
dev/bin/php php-cs-fixer fix
```

### Running static analysis

You can run static anaysis of code using the following command:

```sh
dev/bin/php psalm --shepherd --stats
```

### Testing

You can run the whole test suite using the following command:

```sh
dev/bin/php-test composer test
dev/bin/php-test vendor/bin/simple-phpunit
```

**Happy coding**!
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"require": {
"php": ">=7.2",
"doctrine/doctrine-bundle": "^2.0",
"doctrine/doctrine-bundle": "^2.0.8",
"doctrine/orm": "^2.7.1",
"league/oauth2-server": "^8.0",
"nyholm/psr7": "^1.4",
Expand Down
3 changes: 1 addition & 2 deletions dev/bin/php-debug
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ readonly BASE_DIR=$(cd "$(dirname "$0")"; pwd)

"${BASE_DIR}"/docker-compose run --rm --no-deps \
-e PHP_IDE_CONFIG=serverName="${PHP_IDE_CONFIG:-oauth}" \
-e XDEBUG_REMOTE_AUTOSTART=1 \
-e TIMECOP_FUNC_OVERRIDE=1 \
-e XDEBUG_START_WITH_REQUEST=1 \
php "$@"
1 change: 0 additions & 1 deletion dev/bin/php-test
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ set -e
readonly BASE_DIR=$(cd "$(dirname "$0")"; pwd)

"${BASE_DIR}"/docker-compose run --rm --no-deps \
-e TIMECOP_FUNC_OVERRIDE=1 \
php "$@"
46 changes: 23 additions & 23 deletions dev/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
ARG PHP_VERSION=7.4

FROM php:${PHP_VERSION}-cli-alpine3.10
FROM php:${PHP_VERSION}-cli-alpine
LABEL maintainer="Petar Obradović <[email protected]>"

ARG COMPOSER_VERSION=1.9.3
ARG FLEX_VERSION=1.6.2
ARG PHP_CS_FIXER_VERSION=2.16.2
ARG XDEBUG_VERSION=2.9.2

ENV XDEBUG_REMOTE_AUTOSTART 0

# This is where we're going to store all of our non-project specific binaries
RUN mkdir -p /app/bin
ENV PATH /app/bin:$PATH
Expand All @@ -24,18 +17,20 @@ RUN apk add --update --no-cache --virtual .build-deps \
xml \
zip \
&& pecl install \
xdebug-${XDEBUG_VERSION} \
xdebug \
&& docker-php-ext-enable \
xdebug \
&& apk del --purge .build-deps

RUN mv ${PHP_INI_DIR}/php.ini-development ${PHP_INI_DIR}/php.ini

ENV XDEBUG_START_WITH_REQUEST 0

RUN echo '[xdebug]' >> ${PHP_INI_DIR}/conf.d/docker-php-ext-xdebug.ini \
&& echo 'xdebug.remote_autostart = ${XDEBUG_REMOTE_AUTOSTART}' >> ${PHP_INI_DIR}/conf.d/docker-php-ext-xdebug.ini \
&& echo 'xdebug.remote_enable = 1' >> ${PHP_INI_DIR}/conf.d/docker-php-ext-xdebug.ini \
&& echo 'xdebug.remote_connect_back = 0' >> ${PHP_INI_DIR}/conf.d/docker-php-ext-xdebug.ini \
&& echo 'xdebug.remote_host = %XDEBUG_REMOTE_HOST%' >> ${PHP_INI_DIR}/conf.d/docker-php-ext-xdebug.ini
&& echo 'xdebug.start_with_request = ${XDEBUG_START_WITH_REQUEST}' >> ${PHP_INI_DIR}/conf.d/docker-php-ext-xdebug.ini \
&& echo 'xdebug.mode = debug' >> ${PHP_INI_DIR}/conf.d/docker-php-ext-xdebug.ini \
&& echo 'xdebug.discover_client_host = 0' >> ${PHP_INI_DIR}/conf.d/docker-php-ext-xdebug.ini \
&& echo 'xdebug.client_host = %XDEBUG_CLIENT_HOST%' >> ${PHP_INI_DIR}/conf.d/docker-php-ext-xdebug.ini

# Utilities needed to run this image
RUN apk add --update --no-cache \
Expand All @@ -46,21 +41,26 @@ RUN apk add --update --no-cache \
shadow

# Composer
RUN curl --show-error https://getcomposer.org/installer | php -- \
--install-dir=/app/bin \
--filename=composer \
--version=${COMPOSER_VERSION}

# PHP-CS-Fixer
RUN curl --location --output /app/bin/php-cs-fixer --show-error \
https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v${PHP_CS_FIXER_VERSION}/php-cs-fixer.phar \
&& chmod a+x /app/bin/php-cs-fixer
RUN curl --location --output /app/bin/composer --show-error \
https://github.com/composer/composer/releases/latest/download/composer.phar \
&& chmod a+x /app/bin/composer

# Create the user that's going to run our application
RUN useradd -ms /bin/sh app

# Composer bin plugin
RUN su-exec app composer global require --dev bamarni/composer-bin-plugin

# PHP-CS-Fixer
RUN su-exec app composer global bin php-cs-fixer require --dev friendsofphp/php-cs-fixer \
&& ln -s /home/app/.composer/vendor/bin/php-cs-fixer /app/bin/php-cs-fixer

# Psalm
RUN su-exec app composer global bin psalm require --dev vimeo/psalm psalm/plugin-symfony \
&& ln -s /home/app/.composer/vendor/bin/psalm /app/bin/psalm

# Enable parallel package installation for Composer
RUN su-exec app composer global require symfony/flex:${FLEX_VERSION}
RUN su-exec app composer global require symfony/flex

COPY entrypoint.sh /usr/local/bin/docker-entrypoint

Expand Down
2 changes: 1 addition & 1 deletion dev/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ groupmod -og "${HOST_GROUP_ID}" app &> /dev/null

HOST_IP="${HOST_IP:-$(ip route | grep ^default | awk '{ print $3 }')}"

sed -i "s/%XDEBUG_REMOTE_HOST%/$HOST_IP/" \
sed -i "s/%XDEBUG_CLIENT_HOST%/$HOST_IP/" \
/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

su-exec app docker-php-entrypoint "$@"
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
HOST_USER_ID: ${HOST_USER_ID}
HOST_GROUP_ID: ${HOST_GROUP_ID}
HOST_IP: ${HOST_IP:-}
SYMFONY_REQUIRE: ${SYMFONY_REQUIRE:-4.4.*}
SYMFONY_REQUIRE: ${SYMFONY_REQUIRE:-5.3.*}
image: league/oauth2-server-bundle
volumes:
- .:/app/src
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @internal
*
* @psalm-suppress UnrecognizedStatement
* @psalm-suppress MethodSignatureMismatch
*/
trait ForwardCompatAuthenticatorTrait
{
Expand Down

0 comments on commit 0ef9d1c

Please sign in to comment.