Skip to content

Commit d81f406

Browse files
committed
Update Documentaion for PHP module generation
1 parent 3cda0b7 commit d81f406

File tree

1 file changed

+126
-25
lines changed

1 file changed

+126
-25
lines changed

php_modules/README.md

+126-25
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,158 @@
11
PHP Mods: Overview |
22
[PHP Mods: `options.yml`](../doc/contributor/PHP-EXT-options.yml.md) |
3-
[PHP Mods: `build.yml`](../doc/contributor/PHP-EXT-build.yml.md) |
4-
[PHP Mods: `test.yml`](../doc/contributor/PHP-EXT-test.yml.md)
3+
[PHP Mods: `install.yml`](../doc/contributor/PHP-EXT-install.yml.md)
54

65
---
76

87
<h2><img name="Documentation" title="Documentation" width="20" src="https://github.com/devilbox/artwork/raw/master/submissions_logo/cytopia/01/png/logo_64_trans.png"> Contributor Documentation: PHP Modules</h2>
98

109

1110

12-
# PHP Module definitions
11+
## PHP Module definitions
1312

14-
This document describes how to create new or alter existing PHP module definitions.
13+
This document describes how to create new or alter existing PHP modules.
1514

16-
All PHP modules/extensions (for all PHP versions and both for `amd64` and `arm64` platforms) are defined in the `php_modules/` directory in their corresponding sub directory. These definitions are then transformed to Ansible group_vars and afterwards Ansible will generate the corresponding Dockerfiles (Stage: `mods`).
15+
All PHP modules (for all PHP versions and both for `amd64` and `arm64` platforms) are defined in the `php_modules/` directory in their corresponding sub directory. Modules defined in there will be built for the `mods` flavour.
16+
17+
**Directory Structure:**
18+
```bash
19+
php_modules/
20+
└── <php-mod>/
21+
   ├── install.yml
22+
   ├── options.yml
23+
   └── README.md
24+
```
25+
26+
27+
### Requirements
28+
29+
In order to create new or altere existing PHP modules you need to have the following tools installed locally:
30+
* Python3
31+
* Python [`PyYAML`](https://pypi.org/project/PyYAML/) module
32+
* Docker
33+
* The `make` command
34+
35+
Additionally you should have a brief understanding about what flavours exist and how they derive from each other: **[Documentation: Flavours](../doc/flavours.md)**.
1736

1837

1938
## How to add PHP modules?
2039

21-
> **Note:** The below listed steps require you to have the following on your local machine installed: `python3`, `PyYAML` Python module, `docker` and `make`.
40+
Simply add your new module definitions into `php_modules/` as shown in the above directory structure.
2241

23-
1. **Inside `php_modules/` directory:**
24-
1. Create a new directory with the name of the PHP module in `php_modules/`
25-
2. Add `build.yml`, `options.yml` and `test.yml` into your newly created directory
26-
3. Alter `build.yml`, `options.yml` and `test.yml` according to documentation below
42+
You can either look at existing modules to find out what needs to be added to `install.yml` and `options.yml` or you check out the documentation for that:
2743

28-
2. **Inside the root of this git repository:**
29-
1. Run `make gen-dockerfiles` to generate Dockerfiles via Ansible
30-
2. Run `make build STAGE=mods VERSION=8.1 ARCH=linux/amd64` to build the `mods` Docker image with version `8.1` for platform `linux/amd64`
44+
* See **[PHP-EXT-install.yml.md](../doc/contributor/PHP-EXT-install.yml.md)** how to alter the `install.yml` file.
45+
* See **[PHP-EXT-options.yml.md](../doc/contributor/PHP-EXT-options.yml.md)** how to alter the `options.yml` file.
3146

32-
**Note:** If you want to test if your new module builds correctly, you can generate Dockerfiles which only contain this one module and all others removed. This allows for much faster Docker builds and you don't have to wait for all other modules to be built. To do so, generate only group_vars for your one module via:
47+
Below is a simple example of how the `xls` module was created:
3348

3449
```bash
35-
# Commands shown here are executed from root of this repository
50+
# Enter the php_modules directory
51+
cd php_modules/
52+
53+
# Create the xls directory
54+
mkdir xls
55+
56+
# Create necessary empty files
57+
touch xls/install.yml
58+
touch xls/options.yml
59+
```
60+
61+
Now let's edit `options.yml`:
62+
```yaml
63+
---
64+
name: xls # The name must match the directory name
65+
exclude: [] # Any PHP versions to exclude?
3666

37-
# Only generate Dockerfiles with PHP extension curl
38-
# Note: if curl has other modules as requirements to be built beforehand, those will also be added
39-
make gen-dockerfiles MODS="curl"
67+
depends_build: [libxml] # The libxml module must be built before xls
4068
```
4169
42-
:information_source: For details on how to generate modules see **[Abuser Documentation: Build your own image](../doc/abuser/README.md)**
70+
Now let's edit the `install.yml`:
71+
```yaml
72+
---
73+
all:
74+
type: builtin
75+
build_dep: [libxslt-dev] # This Debian package is required to build xls
76+
run_rep: [libxslt1.1] # This Debian package is required during run-time
77+
```
78+
79+
80+
## How to generate the Dockerfiles?
81+
82+
Dockerfiles are generated for all PHP versions with a single `make` command. If you do not specify any arguments, then all PHP modules found in the `php_modules/` directory are being added to the Dockerfiles.
83+
84+
You can however also generate Dockerfiles only containing the module that you have created/altered. This makes the `docker build` process much faster and you can troubleshoot potential errors quicker.
4385

86+
### Generate Dockerfiles for all PHP modules
4487

45-
## Extension definition: `build.yml`
88+
Inside the root of this git repository execute the following:
89+
```bash
90+
# Generate Dockerfiles with all available PHP modules found in php_modules/ dir
91+
make gen-dockerfiles
92+
```
4693

47-
See **[PHP-EXT-build.yml.md](../doc/contributor/PHP-EXT-build.yml.md)** how to alter the `build.yml` file.
94+
### Generate Dockerfiles for a single PHP module
4895

96+
Inside the root of this git repository execute the following:
97+
```bash
98+
# Generate Dockerfiles with only xls module
99+
make gen-dockerfiles PHP_MODS="xls"
100+
```
49101

50-
## Extension definition: `options.yml`
102+
> **🛈 Note:** This will also add any modules that `xls` depends on (specified via `depends_build:` in `options.yml`)
51103

52-
See **[PHP-EXT-options.yml.md](../doc/contributor/PHP-EXT-options.yml.md)** how to alter the `options.yml` file.
104+
You can also exlcude any dependent modules by specifying the `-i` flag.
53105

106+
```bash
107+
# Generate Dockerfiles with only xls module and no dependent modules
108+
make gen-dockerfiles PHP_MODS="-i xls"
109+
```
54110

55-
## Extension definition: `test.yml`
111+
> **⚠ Warning:** The `-i` option might break your build.
56112

57-
See **[PHP-EXT-test.yml.md](../doc/contributor/PHP-EXT-test.yml.md)** how to alter the `test.yml` file.
113+
### Generate Dockerfiles for multiple PHP modules
114+
115+
Inside the root of this git repository execute the following:
116+
```bash
117+
# Generate Dockerfiles with only xls and xmlwriter module
118+
make gen-dockerfiles PHP_MODS="xls xmlwriter"
119+
```
120+
121+
> **🛈 Note:** This will also add any modules that `xls` and `xmlwriter` depends on (specified via `depends_build:` in `options.yml`)
122+
123+
You can also exlcude any dependent modules by specifying the `-i` flag.
124+
125+
```bash
126+
# Generate Dockerfiles with only xls and xmlwriter module and no dependent modules
127+
make gen-dockerfiles PHP_MODS="-i xls xmlwriter"
128+
```
129+
130+
131+
## How to build the Dockerfiles?
132+
133+
Once you have generated the Dockerfiles, pick a PHP version and an architecture (`linux/am64` or `linux/arm64`) and then build it via `make`.
134+
135+
> **🛈 Note 1:** PHP modules are generated into Dockerfiles of the `mods` flavour, so you will have to use `STAGE=mods` to build this flavour.<br/>
136+
> **🛈 Note 2:** The `mods` flavour depends on the `base` flavour, so you need to ensure to either pull this Docker image or build it yourself.
137+
138+
The following example will show the build for:
139+
* PHP version: `8.1`
140+
* Architecture: `linux/amd64`
141+
142+
### Ensure to have `base` flavour
143+
144+
Either build it yourself for the specific PHP version and architecture.
145+
```bash
146+
make build STAGE=base VERSION=8.1 ARCH=linux/amd64
147+
```
148+
Or pull it from Dockerhub
149+
```
150+
make docker-pull-base-image STAGE=mods VERSION=8.1 ARCH=linux/amd64
151+
```
152+
153+
### Build the `mods` flavour
154+
155+
This flavour will include the PHP modules you have generated above.
156+
```bash
157+
make build STAGE=mods VERSION=8.1 ARCH=linux/amd64
158+
```

0 commit comments

Comments
 (0)