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 6e2078b
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 120 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
46 changes: 0 additions & 46 deletions .github/workflows/docker-main.yml

This file was deleted.

45 changes: 0 additions & 45 deletions .github/workflows/docker-release.yml

This file was deleted.

81 changes: 81 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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 }}
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 6e2078b

Please sign in to comment.