Skip to content

Commit c1cb4b5

Browse files
committed
First version
1 parent d8aee67 commit c1cb4b5

14 files changed

Lines changed: 347 additions & 1 deletion

File tree

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
# Set default charset and newline ending every file
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
indent_size = 4
9+
indent_style = space
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
[*.yml]
14+
indent_size = 2
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: "Documentation"
2+
3+
on:
4+
workflow_call:
5+
pull_request:
6+
branches:
7+
- "master"
8+
paths:
9+
- ".github/workflows/documentation.yml"
10+
- "docs/**"
11+
push:
12+
branches:
13+
- "master"
14+
paths:
15+
- ".github/workflows/documentation.yml"
16+
- "docs/**"
17+
18+
permissions:
19+
contents: read
20+
packages: read
21+
pages: write
22+
id-token: write
23+
24+
concurrency:
25+
group: "pages"
26+
cancel-in-progress: false
27+
28+
jobs:
29+
build:
30+
name: "Build documentation site"
31+
runs-on: "ubuntu-22.04"
32+
33+
steps:
34+
- name: "Checkout"
35+
uses: "actions/checkout@v4"
36+
37+
- name: "Log in to GitHub Container Registry"
38+
uses: "docker/login-action@v3"
39+
with:
40+
registry: "ghcr.io"
41+
username: "${{ github.actor }}"
42+
password: "${{ secrets.GITHUB_TOKEN }}"
43+
44+
- name: "Build site"
45+
run: |
46+
docker run --rm -v "${{ github.workspace }}:/src" -w /src \
47+
ghcr.io/phppdf/docker-image-hugo:dev \
48+
--minify --source docs --destination ../public --themesDir /hugo-themes
49+
50+
- name: "Upload Pages artifact"
51+
uses: "actions/upload-pages-artifact@v3"
52+
with:
53+
path: "public"
54+
55+
deploy:
56+
name: "Deploy to GitHub Pages"
57+
if: "github.ref == 'refs/heads/master' && github.event_name == 'push'"
58+
needs: "build"
59+
runs-on: "ubuntu-22.04"
60+
61+
environment:
62+
name: "github-pages"
63+
url: "${{ steps.deployment.outputs.page_url }}"
64+
65+
steps:
66+
- name: "Deploy to GitHub Pages"
67+
id: "deployment"
68+
uses: "actions/deploy-pages@v4"

.github/workflows/publish.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
permissions:
9+
contents: read
10+
packages: write
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Log in to GHCR
19+
uses: docker/login-action@v3
20+
with:
21+
registry: ghcr.io
22+
username: ${{ github.actor }}
23+
password: ${{ secrets.GITHUB_TOKEN }}
24+
25+
- name: Build and push
26+
uses: docker/build-push-action@v6
27+
with:
28+
context: .
29+
file: src/Dockerfile
30+
push: true
31+
tags: ghcr.io/phppdf/docker-image-php-cli:dev

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/.claude
2+
/.idea
3+
/docs/public
4+
/docs/resources
5+
/docs/.hugo_build.lock

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,28 @@
11
# docker-image-php-cli
2-
A Docker image that can be used to run PHP via the CLI.
2+
3+
A Docker image for running PHP CLI tooling (Composer, PHPUnit, PHPStan, PHPCS, PHPBench, ...)
4+
against a project, without installing PHP locally.
5+
6+
The image expects the project to be mounted at `/app`. It has no entrypoint, so any command can
7+
be run directly.
8+
9+
## Usage
10+
11+
```yaml
12+
services:
13+
cli:
14+
image: ghcr.io/phppdf/docker-image-php-cli:dev
15+
volumes:
16+
- ./:/app
17+
```
18+
19+
```sh
20+
docker compose run --rm cli composer install
21+
docker compose run --rm cli vendor/bin/phpunit
22+
```
23+
24+
Run PHPUnit with coverage (the image includes Xdebug):
25+
26+
```sh
27+
docker compose run --rm -e XDEBUG_MODE=coverage cli vendor/bin/phpunit --coverage-html .phpunit-coverage
28+
```

docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
services:
2+
cli:
3+
build:
4+
context: .
5+
dockerfile: src/Dockerfile
6+
image: ghcr.io/phppdf/docker-image-php-cli:dev
7+
container_name: phppdf-docker-image-php-cli
8+
volumes:
9+
- ./:/app
10+
11+
docs-webserver:
12+
image: ghcr.io/phppdf/docker-image-hugo:dev
13+
container_name: phppdf-docker-image-php-cli-docs
14+
volumes:
15+
- ./:/src
16+
ports:
17+
- "1313:1313"

docs/content/_index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: "docker-image-php-cli documentation"
3+
---
4+
5+
`docker-image-php-cli` is a Docker image for running PHP CLI tooling — Composer, PHPUnit,
6+
PHPStan, PHPCS, PHPBench, and other `vendor/bin/` scripts — against a project, without
7+
installing PHP locally. It bundles PHP, Composer and Xdebug, and has no entrypoint, so any command
8+
can be run directly.

docs/content/docs/cli.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: "Using the CLI"
3+
weight: 20
4+
---
5+
6+
The image has no `ENTRYPOINT`, so any command can be run directly — `composer`, `php`, or
7+
any `vendor/bin/` script — as long as the project is mounted at `/app`.
8+
9+
## Examples
10+
11+
Install dependencies:
12+
13+
```sh
14+
docker run --rm -v ./:/app ghcr.io/phppdf/docker-image-php-cli:dev composer install
15+
```
16+
17+
Run the test suite:
18+
19+
```sh
20+
docker run --rm -v ./:/app ghcr.io/phppdf/docker-image-php-cli:dev vendor/bin/phpunit
21+
```
22+
23+
Run PHPStan:
24+
25+
```sh
26+
docker run --rm -v ./:/app ghcr.io/phppdf/docker-image-php-cli:dev vendor/bin/phpstan analyse
27+
```
28+
29+
Open a shell in the container:
30+
31+
```sh
32+
docker run --rm -it -v ./:/app ghcr.io/phppdf/docker-image-php-cli:dev bash
33+
```
34+
35+
Print the PHP version:
36+
37+
```sh
38+
docker run --rm ghcr.io/phppdf/docker-image-php-cli:dev php -v
39+
```

docs/content/docs/coverage.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: "Code coverage"
3+
weight: 30
4+
---
5+
6+
The image bundles [Xdebug](https://xdebug.org/), which is the easiest way to collect code
7+
coverage with PHPUnit. Xdebug's coverage mode adds overhead, so it is disabled by default and must
8+
be enabled per-run via the `XDEBUG_MODE` environment variable.
9+
10+
## Running PHPUnit with coverage
11+
12+
```sh
13+
docker run --rm -v ./:/app -e XDEBUG_MODE=coverage \
14+
ghcr.io/phppdf/docker-image-php-cli:dev \
15+
vendor/bin/phpunit --coverage-html .phpunit-coverage
16+
```
17+
18+
With Compose:
19+
20+
```sh
21+
docker compose run --rm -e XDEBUG_MODE=coverage cli \
22+
vendor/bin/phpunit --coverage-html .phpunit-coverage
23+
```
24+
25+
The HTML report is written to `.phpunit-coverage/` in the project, since `/app` is a bind mount of
26+
the project directory.
27+
28+
## Other coverage formats
29+
30+
Any PHPUnit coverage option works the same way, for example a text summary on stdout:
31+
32+
```sh
33+
docker run --rm -v ./:/app -e XDEBUG_MODE=coverage \
34+
ghcr.io/phppdf/docker-image-php-cli:dev \
35+
vendor/bin/phpunit --coverage-text
36+
```

docs/content/docs/extensions.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: "Bundled tools and extensions"
3+
weight: 40
4+
---
5+
6+
In addition to the extensions bundled with [`php:8.4-cli`](https://hub.docker.com/_/php) (which
7+
include `mbstring`, `dom`, `libxml`, `openssl` and `zlib`), the image installs:
8+
9+
- **Composer**, available as `composer`
10+
- **Xdebug**, for [code coverage](../coverage/)
11+
- PHP extensions: `gd` (with JPEG support), `pdo`, `pdo_pgsql`, `zip`
12+
- `git`, `unzip`, `zip`
13+
- Noto fonts (`fonts-noto-core`, `fonts-noto-cjk`), for tests that render text
14+
15+
## PHP configuration
16+
17+
`memory_limit` is unbounded (`-1`) and the timezone is set to `UTC`. Error display is enabled,
18+
which is suitable for running tests and CLI tools but not for serving requests.

0 commit comments

Comments
 (0)