Skip to content

Commit 3cda0b7

Browse files
committed
Document PHP tool generation
1 parent 02b3bda commit 3cda0b7

File tree

3 files changed

+185
-0
lines changed

3 files changed

+185
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[PHP Tools: Overview](../../php_tools/README.md) |
2+
[PHP Tools: `options.yml`](PHP-TOOL-options.yml.md) |
3+
PHP Tools: `install.yml`
4+
5+
---
6+
7+
<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 Tools</h2>
8+
9+
10+
11+
# Tool definition: `install.yml`
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[PHP Tools: Overview](../../php_tools/README.md) |
2+
PHP Tools: `options.yml` |
3+
[PHP Tools: `install.yml`](../doc/contributor/PHP-TOOL-install.yml.md)
4+
5+
---
6+
7+
<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 Tools</h2>
8+
9+
10+
11+
# Tool definition: `options.yml`

php_tools/README.md

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
PHP Tools: Overview |
2+
[PHP Tools: `options.yml`](../doc/contributor/PHP-TOOL-options.yml.md) |
3+
[PHP Tools: `install.yml`](../doc/contributor/PHP-TOOL-install.yml.md)
4+
5+
---
6+
7+
<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 Tools</h2>
8+
9+
10+
11+
# PHP Tool definitions
12+
13+
This document describes how to create new or alter existing PHP tools.
14+
15+
All PHP tools (for all PHP versions and both for `amd64` and `arm64` platforms) are defined in the `php_tools/` directory in their corresponding sub directory. Tools defined in there will be built for the `work` flavour.
16+
17+
**Directory Structure:**
18+
```bash
19+
php_tools/
20+
└── <php-tool>/
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 tools 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)**.
36+
37+
38+
## How to add PHP tools?
39+
40+
Simply add your new tool definitions into `php_tools/` as shown in the above directory structure.
41+
42+
You can either look at existing tools to find out what needs to be added to `install.yml` and `options.yml` or you check out the documentation for that:
43+
44+
* See **[PHP-TOOL-install.yml.md](../doc/contributor/PHP-TOOL-install.yml.md)** how to alter the `install.yml` file.
45+
* See **[PHP-TOOL-options.yml.md](../doc/contributor/PHP-TOOL-options.yml.md)** how to alter the `options.yml` file.
46+
47+
Below is a simple example of how the `yq` tool was created:
48+
49+
```bash
50+
# Enter the php_tools directory
51+
cd php_tools/
52+
53+
# Create the yq directory
54+
mkdir yq
55+
56+
# Create necessary empty files
57+
touch yq/install.yml
58+
touch yq/options.yml
59+
```
60+
61+
Now let's edit `options.yml`:
62+
```yaml
63+
---
64+
name: yq # The name must match the directory name
65+
exclude: [] # Any PHP versions to exclude?
66+
67+
depends: [jq] # The jq tool must be installed (yq depends on it)
68+
```
69+
70+
Now let's edit the `install.yml`:
71+
```yaml
72+
---
73+
check: yq --version 2>&1 | grep -E '[0-9][.0-9]+' || (yq --version; false)
74+
75+
all:
76+
type: pip
77+
version:
78+
build_dep: []
79+
run_dep: []
80+
pre:
81+
post:
82+
```
83+
84+
85+
## How to generate the Dockerfiles?
86+
87+
Dockerfiles are generated for all PHP versions with a single `make` command. If you do not specify any arguments, then all PHP tools found in the `php_tools/` directory are being added to the Dockerfiles.
88+
89+
You can however also generate Dockerfiles only containing the tool that you have created/altered. This makes the `docker build` process much faster and you can troubleshoot potential errors quicker.
90+
91+
### Generate Dockerfiles for all PHP tools
92+
93+
Inside the root of this git repository execute the following:
94+
```bash
95+
# Generate Dockerfiles with all available PHP tools found in php_tools/ dir
96+
make gen-dockerfiles
97+
```
98+
99+
### Generate Dockerfiles for a single PHP tool
100+
101+
Inside the root of this git repository execute the following:
102+
```bash
103+
# Generate Dockerfiles with only yq tool
104+
make gen-dockerfiles PHP_TOOLS="yq"
105+
```
106+
107+
> **🛈 Note:** This will also add any tools that `yq` depends on (specified via `depends:` in `options.yml`)
108+
109+
You can also exlcude any dependent tools by specifying the `-i` flag.
110+
111+
```bash
112+
# Generate Dockerfiles with only yq tool and no dependent tools
113+
make gen-dockerfiles PHP_TOOLS="-i yq"
114+
```
115+
116+
> **⚠ Warning:** The `-i` option might break your build.
117+
118+
### Generate Dockerfiles for multiple PHP tools
119+
120+
Inside the root of this git repository execute the following:
121+
```bash
122+
# Generate Dockerfiles with only yq and zsh tool
123+
make gen-dockerfiles PHP_TOOLS="yq zsh"
124+
```
125+
126+
> **🛈 Note:** This will also add any tools that `yq` and `zsh` depends on (specified via `depends:` in `options.yml`)
127+
128+
You can also exlcude any dependent tools by specifying the `-i` flag.
129+
130+
```bash
131+
# Generate Dockerfiles with only yq and zsh tool and no dependent tools
132+
make gen-dockerfiles PHP_TOOLS="-i yq zsh"
133+
```
134+
135+
136+
## How to build the Dockerfiles?
137+
138+
Once you have generated the Dockerfiles, pick a PHP version and an architecture (`linux/am64` or `linux/arm64`) and then build it via `make`.
139+
140+
> **🛈 Note 1:** PHP tools are generated into Dockerfiles of the `work` flavour, so you will have to use `STAGE=work` to build this flavour.<br/>
141+
> **🛈 Note 2:** The `work` flavour depends on the `slim` flavour, so you need to ensure to either pull this Docker image or build it yourself.
142+
143+
The following example will show the build for:
144+
* PHP version: `8.1`
145+
* Architecture: `linux/amd64`
146+
147+
### Ensure to have `slim` flavour
148+
149+
Either build it yourself for the specific PHP version and architecture.
150+
```bash
151+
make build STAGE=slim VERSION=8.1 ARCH=linux/amd64
152+
```
153+
Or pull it from Dockerhub
154+
```
155+
make docker-pull-base-image STAGE=work VERSION=8.1 ARCH=linux/amd64
156+
```
157+
158+
### Build the `work` flavour
159+
160+
This flavour will include the PHP tools you have generated above.
161+
```bash
162+
make build STAGE=work VERSION=8.1 ARCH=linux/amd64
163+
```

0 commit comments

Comments
 (0)