Skip to content

Commit

Permalink
Fixed documentation and use multistage build instead of own dockerfil…
Browse files Browse the repository at this point in the history
…e for dist
  • Loading branch information
Hannes Giesenow committed Dec 18, 2023
1 parent 9f155d0 commit ae78ae0
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:
PHP_MAX: '8.3'
PHP_MIN: '7.4'

jobs:
xjobs:
tests:
strategy:
fail-fast: false
Expand Down
45 changes: 0 additions & 45 deletions .github/workflows/docker-release.yml

This file was deleted.

28 changes: 24 additions & 4 deletions .github/workflows/docker-main.yml → .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: Create and publish a Docker image
name: Create and publish a Docker images

on:
push:
branches: [main]
tags:
- "v*.*.*"
branches:
- "main"
- "docker-setup"

env:
REGISTRY: ghcr.io
Expand All @@ -11,6 +15,14 @@ env:
jobs:
build-and-push-image:
runs-on: ubuntu-latest
strategy:
matrix:
php-version:
- 7.4
- 8.0
- 8.1
- 8.2
- 8.3
permissions:
contents: read
packages: write
Expand All @@ -35,12 +47,20 @@ jobs:
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-version }}
type=semver,pattern={{version}},suffix=-${{ matrix.php-version }}
type=semver,pattern={{major}}.{{minor}},suffix=-${{ matrix.php-version }}
type=semver,pattern={{major}},suffix=-${{ matrix.php-version }}
- name: Build and push Docker image
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
with:
context: .
file: docker/Dockerfile
file: Dockerfile
build-args:
PHP_VERSION: ${{ matrix.platform }}
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}:latest
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion .github/workflows/sca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sphinx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/yaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 20 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<php-cs-fixer-version>-<php-version>`. 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/)
Expand Down
14 changes: 0 additions & 14 deletions docker/Dockerfile

This file was deleted.

0 comments on commit ae78ae0

Please sign in to comment.