diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5900c333760..69957703537 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ env: PHP_MAX: '8.3' PHP_MIN: '7.4' -jobs: +xjobs: tests: strategy: fail-fast: false diff --git a/.github/workflows/docker-main.yml b/.github/workflows/docker-main.yml deleted file mode 100644 index 31c4799f31f..00000000000 --- a/.github/workflows/docker-main.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Create and publish a Docker image - -on: - push: - branches: [main] - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - -jobs: - build-and-push-image: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Log in to the Container registry - uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Make image lowercase - run: | - echo IMAGE_NAME_LOWER=$(echo ${{ env.IMAGE_NAME }} | tr '[:upper:]' '[:lower:]') >> ${GITHUB_ENV} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }} - - - name: Build and push Docker image - uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 - with: - context: . - file: docker/Dockerfile - push: true - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}:latest - labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml deleted file mode 100644 index 1e930426187..00000000000 --- a/.github/workflows/docker-release.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Create and publish a Docker image - -on: - - "release" - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - -jobs: - build-and-push-image: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Log in to the Container registry - uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Make image lowercase - run: | - echo IMAGE_NAME_LOWER=$(echo ${{ env.IMAGE_NAME }} | tr '[:upper:]' '[:lower:]') >> ${GITHUB_ENV} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }} - - - name: Build and push Docker image - uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 - with: - context: . - file: docker/Dockerfile - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000000..8b635bdd588 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,83 @@ +name: Create and publish a Docker images + +on: + push: + tags: + - "v*.*.*" + branches: + - "main" + - "docker-setup" + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + strategy: + matrix: + include: + - php-version: '7.4' + php-suffix: '-php7.4' + alpine-version: '3.16' + - php-version: '8.0' + php-suffix: '-php8.0' + alpine-version: '3.16' + - php-version: '8.1' + php-suffix: '-php8.1' + alpine-version: '3.18' + - php-version: '8.2' + php-suffix: '-php8.2' + alpine-version: '3.18' + - php-version: '8.3' + php-suffix: '-php8.3' + alpine-version: '3.18' + - php-version: '8.3' + php-suffix: '' + alpine-version: '3.18' + + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Make image lowercase + run: | + echo IMAGE_NAME_LOWER=$(echo ${{ env.IMAGE_NAME }} | tr '[:upper:]' '[:lower:]') >> ${GITHUB_ENV} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }} + #TODO change to "main" after testing + tags: | + type=edge,branch=docker-setup,suffix=${{ matrix.php-suffix }} + type=semver,pattern={{version}},suffix=${{ matrix.php-suffix }} + type=semver,pattern={{major}}.{{minor}},suffix=${{ matrix.php-suffix }} + type=semver,pattern={{major}},suffix=${{ matrix.php-suffix }} + type=semver,pattern=latest,suffix=${{ matrix.php-suffix }} + + - name: Build and push Docker image + uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 + with: + context: . + file: Dockerfile + target: dist + build-args: | + PHP_VERSION=${{ matrix.php-version }} + ALPINE_VERSION=${{ matrix.alpine-version }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/sca.yml b/.github/workflows/sca.yml index fe9759241a8..a3ffdda1402 100644 --- a/.github/workflows/sca.yml +++ b/.github/workflows/sca.yml @@ -11,7 +11,7 @@ concurrency: group: sca-${{ github.head_ref || github.run_id }} # will be canceled on subsequent pushes in pull requests but not branches cancel-in-progress: true -jobs: +xjobs: tests: strategy: fail-fast: false diff --git a/.github/workflows/sphinx.yml b/.github/workflows/sphinx.yml index 9524266c15e..fc25d30df53 100644 --- a/.github/workflows/sphinx.yml +++ b/.github/workflows/sphinx.yml @@ -15,7 +15,7 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true -jobs: +xjobs: sphinx: name: Sphinx reStructuredText validity runs-on: ubuntu-latest diff --git a/.github/workflows/yaml.yml b/.github/workflows/yaml.yml index 42cd6bd6386..0e193aef51e 100644 --- a/.github/workflows/yaml.yml +++ b/.github/workflows/yaml.yml @@ -13,7 +13,7 @@ on: permissions: contents: read # to fetch code (actions/checkout) -jobs: +xjobs: validate-yaml: name: Validate YAML runs-on: ubuntu-20.04 diff --git a/Dockerfile b/Dockerfile index 27b91435f9a..d58aee64234 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,31 @@ ARG PHP_VERSION ARG ALPINE_VERSION=3.18 -FROM php:${PHP_VERSION}-cli-alpine${ALPINE_VERSION} - -ARG DOCKER_USER_ID -ARG DOCKER_GROUP_ID -ARG PHP_XDEBUG_VERSION +FROM php:${PHP_VERSION}-cli-alpine${ALPINE_VERSION} as base # https://blog.codito.dev/2022/11/composer-binary-only-docker-images/ # https://github.com/composer/docker/pull/250 COPY --from=composer/composer:2-bin /composer /usr/local/bin/composer +FROM base as vendor +WORKDIR /var/www +COPY composer.json /var/www/composer.json +RUN composer install --prefer-dist --no-dev --optimize-autoloader --no-scripts + +FROM php:${PHP_VERSION}-cli-alpine${ALPINE_VERSION} as dist +WORKDIR /var/www +RUN rmdir /var/www/html +COPY src /usr/local/bin/src +COPY php-cs-fixer /usr/local/bin/php-cs-fixer +# Only take the dependencies (not composer itself) into the container +COPY --from=vendor /var/www/vendor /usr/local/bin/vendor +ENTRYPOINT ["/usr/local/bin/php-cs-fixer"] + +FROM php:${PHP_VERSION}-cli-alpine${ALPINE_VERSION} as dev +ARG DOCKER_USER_ID +ARG DOCKER_GROUP_ID +ARG PHP_XDEBUG_VERSION + RUN if [ ! -z "$DOCKER_GROUP_ID" ] && [ ! getent group "${DOCKER_GROUP_ID}" > /dev/null ]; \ then addgroup -S -g "${DOCKER_GROUP_ID}" devs; \ fi \ diff --git a/README.md b/README.md index d5bae90de5c..add46cf4be2 100644 --- a/README.md +++ b/README.md @@ -42,15 +42,23 @@ projects. This tool does not only detect them, but also fixes them for you. You can take a ready built docker image to run ``php-cs-fixer``. ```console -docker run ghcr.io/php-cs-fixer/php-cs-fixer:latest fix src +docker run -v $(pwd):/var/www ghcr.io/php-cs-fixer/php-cs-fixer:latest fix src ``` - -To use a custom config, just map it into the container - -```console -docker run -v $(pwd)/.php-cs-fixer.dist.php:/var/www/.php-cs-fixer.php ghcr.io/php-cs-fixer/php-cs-fixer:latest fix src +or integrate as check into gitlab-ci like this +```yaml +php-cs-fixer: + image: ghcr.io/php-cs-fixer/php-cs-fixer:latest + script: + php-cs-fixer fix --diff --dry-run --format=txt src ``` +There are different tags for each stability and php version with syntax `-`. For example +* `3.41.1-php8.1` +* `3.41-php8.2` +* `3-latest` +* `latest` (latest stable cs-fixer and latest stable php version) +* `dev` (current build from main) + ### Installation The recommended way to install PHP CS Fixer is to use [Composer](https://getcomposer.org/download/) diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 254aa15242e..00000000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -# Install composer dependencies first -FROM php:8.2-alpine as vendor -WORKDIR /var/www -COPY --from=composer/composer:2-bin /composer /usr/local/bin/composer -COPY composer.json /var/www/composer.json -RUN composer install --prefer-dist --no-dev --optimize-autoloader --no-scripts - -FROM php:8.2-alpine -WORKDIR /var/www -COPY src /var/www/src -COPY php-cs-fixer /var/www/php-cs-fixer -# Only take the dependencies (not composer itself) into the container -COPY --from=vendor /var/www/vendor /var/www/vendor -ENTRYPOINT ["/var/www/php-cs-fixer"]