Skip to content

Commit 9e17002

Browse files
committed
Add PHP 8 flavour and Github Action
1 parent 79f0380 commit 9e17002

File tree

4 files changed

+243
-11
lines changed

4 files changed

+243
-11
lines changed

.github/workflows/docker.yml

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
name: Docker
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
on:
10+
# schedule:
11+
# - cron: '44 18 * * *'
12+
push:
13+
branches:
14+
- "master"
15+
# pull_request:
16+
# branches: [ "main" ]
17+
18+
env:
19+
# Use docker.io for Docker Hub if empty
20+
REGISTRY: ghcr.io
21+
# github.repository as <account>/<repo>
22+
IMAGE_NAME: ${{ github.repository }}
23+
24+
jobs:
25+
build:
26+
27+
runs-on: ubuntu-latest
28+
permissions:
29+
contents: read
30+
packages: write
31+
# This is used to complete the identity challenge
32+
# with sigstore/fulcio when running outside of PRs.
33+
id-token: write
34+
35+
strategy:
36+
matrix:
37+
include:
38+
- os_release: bullseye
39+
php_version: 7
40+
- os_release: bookworm
41+
php_version: 8
42+
43+
steps:
44+
- name: Checkout repository
45+
uses: actions/checkout@v3
46+
47+
48+
- name: Setup Docker buildx
49+
uses: docker/setup-buildx-action@v3
50+
51+
# Install the cosign tool except on PR
52+
# https://github.com/sigstore/cosign-installer
53+
- name: Install cosign
54+
if: github.event_name != 'pull_request'
55+
uses: sigstore/[email protected]
56+
with:
57+
cosign-release: 'v2.2.2'
58+
59+
# Login against a Docker registry except on PR
60+
# https://github.com/docker/login-action
61+
- name: Log into registry ${{ env.REGISTRY }}
62+
if: github.event_name != 'pull_request'
63+
uses: docker/login-action@v3
64+
with:
65+
registry: ${{ env.REGISTRY }}
66+
username: ${{ github.actor }}
67+
password: ${{ secrets.GITHUB_TOKEN }}
68+
69+
# Login against a Docker registry except on PR
70+
# https://github.com/docker/login-action
71+
- name: Log into remote registry ${{ vars.REMOTE_REGISTRY }}
72+
if: ${{ vars.REMOTE_REGISTRY != '' && github.event_name != 'pull_request' }}
73+
uses: docker/login-action@v3
74+
with:
75+
registry: ${{ vars.REMOTE_REGISTRY != 'index.docker.io' && vars.REMOTE_REGISTRY || null }}
76+
username: ${{ secrets.REGISTRY_USER }}
77+
password: ${{ secrets.REGISTRY_PASS }}
78+
79+
# Extract metadata (tags, labels) for Docker
80+
# https://github.com/docker/metadata-action
81+
- name: Extract Docker metadata
82+
id: meta
83+
uses: docker/[email protected]
84+
with:
85+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
86+
tags: ${{ matrix.php_version }}-${{ matrix.os_release }}
87+
88+
# Extract metadata (tags, labels) for Docker
89+
# https://github.com/docker/metadata-action
90+
- name: Extract Docker metadata for ${{ vars.REMOTE_REGISTRY }}
91+
id: meta-remote
92+
if: ${{ vars.REMOTE_REGISTRY != '' }}
93+
uses: docker/[email protected]
94+
with:
95+
images: ${{ vars.REMOTE_REGISTRY }}/${{ vars.REMOTE_IMAGE_NAME }}
96+
tags: ${{ matrix.php_version }}-${{ matrix.os_release }}
97+
98+
# Build and push Docker image with Buildx (don't push on PR)
99+
# https://github.com/docker/build-push-action
100+
- name: Build and push Docker image
101+
id: build-and-push
102+
uses: docker/build-push-action@v5
103+
with:
104+
file: Dockerfile.${{ matrix.os_release }}
105+
context: .
106+
push: ${{ github.event_name != 'pull_request' }}
107+
tags: |
108+
${{ steps.meta.outputs.tags}}
109+
${{ steps.meta-remote.outputs.tags }}
110+
labels: ${{ steps.meta.outputs.labels }}
111+
cache-from: type=gha
112+
cache-to: type=gha,mode=max
113+
114+
# Sign the resulting Docker image digest except on PRs.
115+
# This will only write to the public Rekor transparency log when the Docker
116+
# repository is public to avoid leaking data. If you would like to publish
117+
# transparency data even for private images, pass --force to cosign below.
118+
# https://github.com/sigstore/cosign
119+
- name: Sign the published Docker image
120+
if: ${{ github.event_name != 'pull_request' }}
121+
env:
122+
COSIGN_EXPERIMENTAL: "true"
123+
# This step uses the identity token to provision an ephemeral certificate
124+
# against the sigstore community Fulcio instance.
125+
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }}

Dockerfile.bookworm

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Choose the desired PHP version
2+
# Choices available at https://hub.docker.com/_/php/ stick to "-cli" versions recommended
3+
ARG PHP_VERSION=8
4+
ARG FLAVOUR=cli-bookworm
5+
ARG BASE_IMAGE=${PHP_VERSION}-${FLAVOUR}
6+
7+
FROM php:${BASE_IMAGE}
8+
# Re-load needed ARGS. See https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
9+
ARG FLAVOUR
10+
11+
12+
LABEL maintainer="Sbit.io <[email protected]>"
13+
14+
ENV TARGET_DIR="/usr/local/lib/php-qa" \
15+
COMPOSER_ALLOW_SUPERUSER=1 \
16+
TIMEZONE=Europe/Madrid \
17+
LOCALE=es_ES.UTF-8 \
18+
LOCALE_CHARSET=UTF-8 \
19+
PHP_MEMORY_LIMIT=1G
20+
21+
ENV PATH=$PATH:$TARGET_DIR/vendor/bin
22+
23+
RUN mkdir -p $TARGET_DIR
24+
25+
WORKDIR $TARGET_DIR
26+
27+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
28+
RUN echo "deb http://deb.debian.org/debian ${FLAVOUR#*-}-backports main contrib non-free" > /etc/apt/sources.list.d/backports.list \
29+
&& apt-get update -qq \
30+
&& echo "locales locales/default_environment_locale select $LOCALE" | debconf-set-selections \
31+
&& echo "locales locales/locales_to_be_generated select $LOCALE $LOCALE_CHARSET" | debconf-set-selections \
32+
&& DEBIAN_FRONTEND=noninteractive \
33+
apt-get install -yqq -o=Dpkg::Use-Pty=0 --no-install-recommends \
34+
-V \
35+
locales=2.* \
36+
wget=1.* \
37+
gpg=2.* gpg-agent=2.* dirmngr=2.* \
38+
zip=3.* \
39+
unzip=6.* \
40+
python3-pkg-resources=66.* \
41+
git=1:2.39.* \
42+
libxml2-dev=2.* \
43+
libxslt1-dev=1.* \
44+
yamllint=1.* \
45+
&& docker-php-ext-install xml xsl \
46+
&& docker-php-ext-install "-j$(nproc)" intl \
47+
&& docker-php-ext-install "-j$(nproc)" mysqli \
48+
&& docker-php-ext-install "-j$(nproc)" pdo_mysql \
49+
&& rm -rf /var/lib/apt/lists/* \
50+
&& apt-get clean -yqq
51+
52+
53+
ENV LANG=$LOCALE
54+
ENV LANGUAGE=$LOCALE
55+
ENV LC_ALL=$LOCALE
56+
57+
RUN printf '[PHP]\nmemory_limit=%s' "${PHP_MEMORY_LIMIT}" >> "$PHP_INI_DIR/conf.d/overrides.ini"
58+
59+
COPY --from=composer /usr/bin/composer /usr/bin/composer
60+
61+
# Run composer installation of needed tools
62+
RUN composer config --no-plugins --global allow-plugins.dealerdirect/phpcodesniffer-composer-installer true \
63+
&& composer require --prefer-stable --prefer-dist \
64+
"squizlabs/php_codesniffer:^3.0" \
65+
"phpunit/phpunit:^10.0" \
66+
"phploc/phploc:^8.0.x-dev" \
67+
"pdepend/pdepend:^2.5" \
68+
"phpmd/phpmd:^2.6" \
69+
#"sebastian/phpcpd:^6.0" \
70+
"friendsofphp/php-cs-fixer:^2.14" \
71+
"phpcompatibility/php-compatibility:^9.0" \
72+
"phpmetrics/phpmetrics:^2.4" \
73+
"phpstan/phpstan:^0.11" \
74+
"drupal/coder:^8.3.1 !=8.3.16" \
75+
"dealerdirect/phpcodesniffer-composer-installer" \
76+
"mglaman/phpstan-drupal" \
77+
"edgedesign/phpqa" \
78+
# phpqa suggested tools
79+
# See https://github.com/EdgedesignCZ/phpqa/blob/master/bin/suggested-tools.sh#L16
80+
"php-parallel-lint/php-parallel-lint" \
81+
"php-parallel-lint/php-console-highlighter" \
82+
"phpstan/phpstan" \
83+
# phpstan dependency
84+
"nette/neon" \
85+
"qossmic/deptrac-shim" \
86+
"friendsofphp/php-cs-fixer:>=2" \
87+
"vimeo/psalm:>=2" \
88+
"enlightn/security-checker"
89+
90+
# Phive installs, needed since phpcpd is archived and somewhat incompatible
91+
RUN wget -O phive.phar https://phar.io/releases/phive.phar \
92+
&& wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc \
93+
&& gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79 \
94+
&& gpg --verify phive.phar.asc phive.phar \
95+
&& chmod +x phive.phar \
96+
&& mv phive.phar /usr/local/bin/phive

Dockerfile renamed to Dockerfile.bullseye

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Choose the desired PHP version
22
# Choices available at https://hub.docker.com/_/php/ stick to "-cli" versions recommended
3-
FROM php:7.4-cli-bullseye
3+
ARG PHP_VERSION=7
4+
ARG FLAVOUR=cli-bullseye
5+
ARG BASE_IMAGE=${PHP_VERSION}-${FLAVOUR}
6+
7+
FROM php:${BASE_IMAGE}
8+
# Re-load needed ARGS. See https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
9+
ARG FLAVOUR
410

511
LABEL maintainer="Sbit.io <[email protected]>"
612

@@ -18,7 +24,7 @@ RUN mkdir -p $TARGET_DIR
1824
WORKDIR $TARGET_DIR
1925

2026
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
21-
RUN echo "deb http://deb.debian.org/debian bullseye-backports main contrib non-free" > /etc/apt/sources.list.d/backports.list \
27+
RUN echo "deb http://deb.debian.org/debian ${FLAVOUR#*-}-backports main contrib non-free" > /etc/apt/sources.list.d/backports.list \
2228
&& apt-get update -qq \
2329
&& echo "locales locales/default_environment_locale select $LOCALE" | debconf-set-selections \
2430
&& echo "locales locales/locales_to_be_generated select $LOCALE $LOCALE_CHARSET" | debconf-set-selections \

README.md

+14-9
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@ More specifically this includes:
1919
- phpstan/phpstan
2020
- edgedesign/phpqa
2121

22+
There are curently 3 flavours [published in Docker Hub](https://hub.docker.com/r/sbitio/php-qa/):
23+
- 8-bookworm: Based on PHP's `8-cli-bookworm` tag
24+
- 7-bulleye: Based on PHP's `7-cli-bullseye` tag
25+
- latest: Previous version to be deprecated in the future
26+
2227
## Usage
2328

2429
Note: This image does nothing when invoking it without a followup command, such as:
2530

2631
```bash
2732
cd </path/to/desired/directory>
28-
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:latest <desired-command-with-arguments>
33+
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:8-cli-bookworm <desired-command-with-arguments>
2934
```
3035

3136
Windows users: The use of "$PWD" for present working directory will not work as expected, instead use the full path.
@@ -74,7 +79,7 @@ php -d memory_limit=1G
7479
See https://github.com/EdgedesignCZ/phpqa for more usage details of this tool, its a very convenient wrapper for most of the tools included.
7580

7681
```bash
77-
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:latest \
82+
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:8-cli-bookworm \
7883
phpqa --report offline
7984
```
8085

@@ -83,7 +88,7 @@ docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:latest \
8388
See https://github.com/sebastianbergmann/phploc for more usage details of this tool.
8489

8590
```bash
86-
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:latest \
91+
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:8-cli-bookworm \
8792
phploc -v --names "*.php" \
8893
--exclude "vendor" . > ./php_code_quality/phploc.txt
8994
```
@@ -93,7 +98,7 @@ docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:latest \
9398
See https://phpmd.org/download/index.html for more usage details of this tool.
9499

95100
```bash
96-
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:latest \
101+
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:8-cli-bookworm \
97102
phpmd . xml codesize --exclude 'vendor' \
98103
--reportfile './php_code_quality/phpmd_results.xml'
99104
```
@@ -103,7 +108,7 @@ docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:latest \
103108
See https://pdepend.org/ for more usage details of this tool.
104109

105110
```bash
106-
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:latest \
111+
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:8-cli-bookworm \
107112
pdepend --ignore='vendor' \
108113
--summary-xml='./php_code_quality/pdepend_output.xml' \
109114
--jdepend-chart='./php_code_quality/pdepend_chart.svg' \
@@ -115,7 +120,7 @@ docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:latest \
115120
See https://github.com/sebastianbergmann/phpcpd for more usage details of this tool.
116121

117122
```bash
118-
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:latest \
123+
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:8-cli-bookworm \
119124
phpcpd . \
120125
--exclude 'vendor' > ./php_code_quality/phpcpd_results.txt
121126
```
@@ -125,7 +130,7 @@ docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:latest \
125130
See http://www.phpmetrics.org/ for more usage details of this tool.
126131

127132
```bash
128-
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:latest \
133+
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:8-cli-bookworm \
129134
phpmetrics --excluded-dirs 'vendor' \
130135
--report-html=./php_code_quality/metrics_results .
131136
```
@@ -135,7 +140,7 @@ docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:latest \
135140
See https://github.com/squizlabs/PHP_CodeSniffer/wiki for more usage details of this tool.
136141

137142
```bash
138-
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:latest \
143+
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:8-cli-bookworm \
139144
phpcs -sv --extensions=php --ignore=vendor \
140145
--report-file=./php_code_quality/codesniffer_results.txt .
141146
```
@@ -146,7 +151,7 @@ See https://github.com/PHPCompatibility/PHPCompatibility and https://github.com/
146151
usage details of this tool.
147152

148153
```bash
149-
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:latest sh -c \
154+
docker run -it --rm -v "$PWD":/app -w /app sbitio/php-qa:8-cli-bookworm sh -c \
150155
'phpcs -sv --config-set installed_paths /usr/local/lib/php-qa/vendor/phpcompatibility/php-compatibility \
151156
&& phpcs -sv --standard='PHPCompatibility' --extensions=php --ignore=vendor . \
152157
--report-file=./php_code_quality/phpcompatibility_results.txt .'

0 commit comments

Comments
 (0)