Skip to content

Commit 6cc78db

Browse files
committed
docs: update documentation with comprehensive project details
- Enhanced Copilot instructions with detailed build process, PHP configuration, and extensions - Added complete documentation for dual image types (distroless + base images) - Updated README with multi-version support details (PHP 8.1-8.4) - Documented Composer and Xdebug availability in base images - Clarified CI/CD pipeline architecture and workflow dependencies - Added comprehensive extension lists and Swoole version specifications
1 parent 22daa64 commit 6cc78db

File tree

2 files changed

+71
-69
lines changed

2 files changed

+71
-69
lines changed

.github/copilot-instructions.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,53 @@ You are an expert in:
1111
## Project Context
1212

1313
This repository provides **distroless PHP container images** that combine:
14-
- **Static PHP builds** from [static-php-cli](https://github.com/crazywhalecc/static-php-cli)
14+
- **Static PHP builds** from [static-php-cli](https://github.com/crazywhalecc/static-php-cli) v2.6.1
1515
- **Google's distroless base images** for minimal attack surface
1616
- **Multi-architecture support** (AMD64/ARM64)
17+
- **Dual image types**: Distroless runtime images and Debian-based development images
1718

1819
### Key Goals
1920
- Provide the smallest possible PHP runtime environment
2021
- Eliminate unnecessary OS packages and dependencies
2122
- Maintain security through minimal attack surface
2223
- Support production-ready PHP applications
24+
- Provide development-friendly base images with Composer and Xdebug
2325

2426
## Technical Architecture
2527

2628
### Build Process
2729
- Uses a two-stage GitHub Actions pipeline:
28-
1. **PHP Build** (`php.yml`): Compiles static PHP binaries for multiple versions (8.1-8.4) and architectures
29-
2. **Image Build** (`image.yml`): Creates Docker images using the compiled binaries
30-
- Final stage uses `gcr.io/distroless/cc-debian12:nonroot` base image
30+
1. **PHP Build** (`php.yml`): Compiles static PHP binaries for multiple versions (8.1-8.4) and architectures using static-php-cli v2.6.1
31+
2. **Image Build** (`image.yml`): Creates Docker images using the compiled binaries for both distroless and base variants
32+
- Distroless images use `gcr.io/distroless/cc-debian12:nonroot` base image
33+
- Base images use `debian:12.11` with Composer 2.8 and Xdebug
3134
- Supports both `linux/amd64` and `linux/arm64` platforms
3235
- Uses GitHub Container Registry for image distribution
36+
- Matrix builds for PHP versions 8.1, 8.2, 8.3, and 8.4
37+
- Architecture-specific runners (ubuntu-24.04 for AMD64, ubuntu-24.04-arm for ARM64)
3338

3439
### PHP Configuration
3540
- **Versions**: PHP 8.1, 8.2, 8.3, 8.4 (all supported)
36-
- **Extensions**: 60+ included extensions (defined in `php.yml` workflow)
41+
- **Extensions**: 60+ included extensions including:
42+
- Core: bcmath, calendar, ctype, curl, dom, exif, ffi, fileinfo, filter, iconv, intl, mbregex, mbstring, opcache, openssl, pcntl, pdo, phar, posix, session, shmop, simplexml, soap, sockets, sodium, sqlite3, tokenizer, xml, xmlreader, xmlwriter, xsl, zip, zlib
43+
- Caching: apcu, memcache, memcached, redis
44+
- Database: mysqli, mysqlnd, pdo_mysql, pgsql, mongodb
45+
- Performance: swoole (v5.1.7 for PHP 8.1-8.3, v6.0.2 for PHP 8.4), parallel, zstd
46+
- Graphics: gd, imagick
47+
- Development: ast, xdebug (base images only)
48+
- Other: amqp, rdkafka, brotli, ds, gettext, igbinary, inotify, ldap, libxml, msgpack, opentelemetry, password-argon2, readline, xlswriter, yaml
3749
- **Binary location**: `/bin/php` in final image
3850
- **User**: Runs as non-root user for security
51+
- **ZTS**: Thread-safe builds enabled
52+
- **Special configurations**:
53+
- Swoole hooks for MySQL, PostgreSQL, and SQLite
54+
- MongoDB driver limited to 1.x versions for compatibility
3955

4056
### Project Structure
41-
- `Dockerfile`: Minimal multi-arch configuration with build arguments
42-
- `.github/workflows/php.yml`: PHP binary compilation pipeline
43-
- `.github/workflows/image.yml`: Docker image build and push pipeline
57+
- `distroless.Dockerfile`: Minimal multi-arch configuration with build arguments (PHPVERSION, TARGETARCH)
58+
- `base.Dockerfile`: Debian-based image with PHP, Composer 2.8, and Xdebug
59+
- `.github/workflows/php.yml`: PHP binary compilation pipeline using static-php-cli v2.6.1
60+
- `.github/workflows/image.yml`: Docker image build and push pipeline for both image types
4461
- `.github/copilot-instructions.md`: Development guidelines
4562
- Pre-compiled PHP binaries are built via GitHub Actions using static-php-cli
4663

@@ -51,13 +68,15 @@ This repository provides **distroless PHP container images** that combine:
5168
- Minimize layers and build context
5269
- Use appropriate ARG variables (PHPVERSION, TARGETARCH) for target architecture
5370
- Follow security best practices (non-root user, minimal permissions)
71+
- Two separate Dockerfiles: `distroless.Dockerfile` for runtime and `base.Dockerfile` for development
5472

5573
### When working with workflows:
5674
- **PHP Build Workflow**: Triggered manually via workflow_dispatch
5775
- **Image Build Workflow**: Requires a PHP workflow run ID as input
5876
- Test on both AMD64 and ARM64 architectures using matrix strategy
5977
- Extensions are defined in the `EXTENSIONS` environment variable in `php.yml`
60-
- Current image builds focus on PHP 8.3 but can be expanded via matrix strategy
78+
- Both workflows support all PHP versions (8.1, 8.2, 8.3, 8.4) via matrix strategy
79+
- Swoole versions are configured per PHP version (v5.1.7 for 8.1-8.3, v6.0.2 for 8.4)
6180

6281
### When modifying build processes:
6382
- Test on both AMD64 and ARM64 architectures using matrix strategy

README.md

Lines changed: 43 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -32,39 +32,55 @@ FROM ghcr.io/opencodeco/distroless-php:8.3-base
3232
- `8.4` - PHP 8.4 (multi-arch: AMD64, ARM64)
3333

3434
**Base Images (Debian + Composer):**
35-
- `8.3-base` - PHP 8.3 with Composer on Debian (multi-arch: AMD64, ARM64)
35+
- `8.1-base` - PHP 8.1 with Composer and Xdebug on Debian (multi-arch: AMD64, ARM64)
36+
- `8.2-base` - PHP 8.2 with Composer and Xdebug on Debian (multi-arch: AMD64, ARM64)
37+
- `8.3-base` - PHP 8.3 with Composer and Xdebug on Debian (multi-arch: AMD64, ARM64)
38+
- `8.4-base` - PHP 8.4 with Composer and Xdebug on Debian (multi-arch: AMD64, ARM64)
39+
40+
### Example
41+
42+
**Using the base image for build stage:**
43+
44+
```dockerfile
45+
FROM ghcr.io/opencodeco/distroless-php:8.3-base AS base
46+
WORKDIR /workspace
47+
COPY composer.* ./
48+
RUN composer install --prefer-dist --no-dev --no-interaction --optimize-autoloader
49+
COPY . .
50+
51+
FROM ghcr.io/opencodeco/distroless-php:8.3
52+
COPY --from=base --chown=nonroot:nonroot /workspace /opt
53+
CMD [ "/opt/bin/hyperf.php", "start" ]
54+
EXPOSE 9501
55+
```
56+
57+
*Note: Base images are available for all PHP versions (8.1-base, 8.2-base, 8.3-base, 8.4-base) and include Composer and Xdebug for development workflows.*
3658

3759
## Building
3860

3961
Images are automatically built and published via GitHub Actions using pre-compiled PHP binaries from [static-php-cli](https://github.com/crazywhalecc/static-php-cli). The build process uses multi-architecture Docker builds to support both AMD64 and ARM64 platforms.
4062

4163
### CI/CD Pipeline
4264

43-
The project uses a multi-stage GitHub Actions pipeline:
65+
The project uses a two-stage GitHub Actions pipeline:
4466

4567
1. **PHP Build** (`php.yml`): Builds static PHP binaries for both architectures
4668
- **Triggers**: Manual workflow dispatch
4769
- **PHP Versions**: 8.1, 8.2, 8.3, 8.4
4870
- **Platforms**: `linux/amd64` and `linux/arm64`
4971
- **Extensions**: 60+ extensions including amqp, apcu, ast, bcmath, brotli, calendar, ctype, curl, dom, ds, exif, ffi, fileinfo, filter, gd, gettext, iconv, igbinary, imagick, inotify, intl, ldap, libxml, mbregex, mbstring, memcache, memcached, mongodb, msgpack, mysqli, mysqlnd, opcache, openssl, opentelemetry, parallel, password-argon2, pcntl, pdo, pdo_mysql, pgsql, phar, posix, rdkafka, readline, redis, session, shmop, simplexml, soap, sockets, sodium, sqlite3, swoole, swoole-hook-mysql, swoole-hook-pgsql, swoole-hook-sqlite, tokenizer, xlswriter, xml, xmlreader, xmlwriter, xsl, yaml, zip, zlib, zstd
72+
- **Additional**: Includes Xdebug extension for base images
5073
- **Artifacts**: Uploads compiled PHP binaries as GitHub artifacts
5174

5275
2. **Image Build** (`image.yml`): Creates Docker images using the PHP binaries
5376
- **Triggers**: Manual workflow dispatch (requires PHP workflow run ID)
5477
- **Registry**: GitHub Container Registry (`ghcr.io`)
5578
- **Platforms**: Multi-architecture builds for `linux/amd64` and `linux/arm64`
56-
- **PHP Version**: Currently builds PHP 8.3 (configurable via matrix)
79+
- **PHP Versions**: Builds all supported PHP versions (8.1, 8.2, 8.3, 8.4)
80+
- **Image Types**: Both distroless runtime images and Debian-based images with Composer
5781
- **Caching**: Uses GitHub Actions cache for faster builds
5882
- **Authentication**: Uses `GITHUB_TOKEN` for registry access
5983

60-
3. **Base Image Build** (`base.yml`): Creates Debian-based images with PHP and Composer
61-
- **Triggers**: Manual workflow dispatch
62-
- **Registry**: GitHub Container Registry (`ghcr.io`)
63-
- **Platforms**: Multi-architecture builds for `linux/amd64` and `linux/arm64`
64-
- **PHP Version**: Currently builds PHP 8.3 base image
65-
- **Features**: Includes statically built PHP binary and Composer on Debian base
66-
- **Use Case**: Ideal for development and build stages where you need package managers and build tools
67-
6884
### Architecture Support
6985

7086
- **AMD64** (x86_64): Built using pre-compiled PHP binaries
@@ -75,30 +91,34 @@ The project uses a multi-stage GitHub Actions pipeline:
7591
The complete build process consists of two stages:
7692

7793
1. **PHP Binary Compilation** (`php.yml`):
78-
- Checks out the [static-php-cli](https://github.com/crazywhalecc/static-php-cli) repository
79-
- Sets up PHP 8.4 build environment with required tools and extensions
94+
- Checks out the [static-php-cli](https://github.com/crazywhalecc/static-php-cli) repository (version 2.6.1)
95+
- Sets up PHP build environment with required tools and extensions
8096
- Downloads dependencies and compiles PHP with all extensions for multiple PHP versions (8.1, 8.2, 8.3, 8.4)
8197
- Creates static PHP binaries for both AMD64 and ARM64 architectures
82-
- Uses matrix builds with architecture-specific runners (ubuntu-latest for AMD64, ubuntu-latest-arm for ARM64)
98+
- Uses matrix builds with architecture-specific runners (ubuntu-24.04 for AMD64, ubuntu-24.04-arm for ARM64)
99+
- Includes Xdebug extension as a shared module for base images
100+
- Updates Swoole to specific versions per PHP version (v5.1.7 for PHP 8.1-8.3, v6.0.2 for PHP 8.4)
83101
- Uploads binaries as GitHub artifacts with version and architecture naming
84102

85103
2. **Docker Image Creation** (`image.yml`):
86104
- Downloads the PHP binary artifacts from the previous workflow (requires run ID input)
87-
- Uses multi-stage Docker build with distroless base image
105+
- Uses multi-stage Docker build with both distroless and Debian base images
88106
- Copies the appropriate PHP binary based on target architecture using build arguments
89-
- Creates minimal container image with only PHP binary and distroless base
107+
- Creates minimal distroless container images with only PHP binary and distroless base
108+
- Creates Debian-based images with PHP, Composer, and Xdebug for development use
90109
- Supports multi-architecture builds (linux/amd64, linux/arm64)
91-
- Currently builds PHP 8.3 images (configurable via matrix strategy)
110+
- Builds all PHP versions (8.1, 8.2, 8.3, 8.4) for both image types
92111
- Pushes to GitHub Container Registry with appropriate tags
93112

94113
## How it Works
95114

96115
This project combines static PHP binaries with Google's Distroless base images to create minimal, secure PHP runtime containers:
97116

98-
1. **Static PHP Binaries**: Pre-compiled PHP binaries from [static-php-cli](https://github.com/crazywhalecc/static-php-cli) are built with 60+ extensions for multiple PHP versions (8.1, 8.2, 8.3, 8.4)
117+
1. **Static PHP Binaries**: Pre-compiled PHP binaries from [static-php-cli](https://github.com/crazywhalecc/static-php-cli) v2.6.1 are built with 60+ extensions for multiple PHP versions (8.1, 8.2, 8.3, 8.4)
99118
2. **Multi-arch Build**: Docker build process uses architecture-specific binaries (AMD64 or ARM64) via build arguments (PHPVERSION and TARGETARCH)
100119
3. **Distroless Base**: Uses `gcr.io/distroless/cc-debian12:nonroot` for minimal attack surface and runs as non-root user
101-
4. **No OS**: Final images contain only the PHP binary and distroless base - no package managers, shells, or unnecessary tools
120+
4. **Base Images**: Debian 12.11-based images with Composer 2.8 and Xdebug for development workflows
121+
5. **No OS**: Final distroless images contain only the PHP binary and distroless base - no package managers, shells, or unnecessary tools
102122

103123
### Included PHP Extensions
104124

@@ -109,54 +129,17 @@ The PHP binaries include 60+ extensions:
109129
- **Messaging**: amqp, rdkafka
110130
- **Performance**: swoole, swoole-hook-mysql, swoole-hook-pgsql, swoole-hook-sqlite, parallel, zstd
111131
- **Graphics**: gd, imagick
112-
- **Development**: ast, ffi
132+
- **Development**: ast, ffi, xdebug (base images only)
113133
- **Serialization**: igbinary, msgpack, yaml
114134
- **Monitoring**: opentelemetry
115135
- **Utilities**: brotli, ds, gettext, inotify, ldap, libxml, password-argon2, readline, xlswriter
116136

117137
### Project Structure
118138

119139
```
120-
├── Dockerfile # Multi-arch Dockerfile with build arguments (PHPVERSION, TARGETARCH)
121-
├── Dockerfile.base # Debian-based image with PHP and Composer
140+
├── distroless.Dockerfile # Multi-arch distroless Dockerfile with build arguments (PHPVERSION, TARGETARCH)
141+
├── base.Dockerfile # Debian-based image with PHP, Composer, and Xdebug
122142
├── .github/workflows/php.yml # PHP binary build pipeline (supports 8.1, 8.2, 8.3, 8.4)
123-
├── .github/workflows/image.yml # Docker image build pipeline
124-
├── .github/workflows/base.yml # Base image build pipeline
143+
├── .github/workflows/image.yml # Docker image build pipeline (both distroless and base)
125144
└── .github/copilot-instructions.md # Copilot development guidelines
126145
```
127-
128-
### Example
129-
130-
**Using the base image for build stage:**
131-
132-
```dockerfile
133-
FROM ghcr.io/opencodeco/distroless-php:8.3-base AS build
134-
WORKDIR /workspace
135-
COPY composer.* ./
136-
RUN composer install --prefer-dist --no-dev --no-interaction --optimize-autoloader
137-
COPY . .
138-
139-
FROM ghcr.io/opencodeco/distroless-php:8.3
140-
COPY --from=build --chown=nonroot:nonroot /workspace /app
141-
CMD [ "/app/bin/hyperf.php", "start" ]
142-
EXPOSE 9501
143-
```
144-
145-
**Traditional approach (still supported):**
146-
147-
```dockerfile
148-
FROM composer:2.2 AS composer
149-
FROM php:8.3 AS build
150-
RUN apt-get update && apt-get install -y libzip-dev && docker-php-ext-install zip
151-
WORKDIR /workspace
152-
COPY --from=composer /usr/bin/composer /usr/bin/composer
153-
ENV COMPOSER_ALLOW_SUPERUSER=1
154-
COPY composer.* ./
155-
RUN composer install --prefer-dist --no-dev --no-interaction --optimize-autoloader
156-
COPY . .
157-
158-
FROM ghcr.io/opencodeco/distroless-php:8.3
159-
COPY --from=build --chown=nonroot:nonroot /workspace /app
160-
CMD [ "/app/bin/hyperf.php", "start" ]
161-
EXPOSE 9501
162-
```

0 commit comments

Comments
 (0)