Skip to content

Commit

Permalink
Add PHP module dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
cytopia committed Nov 29, 2022
1 parent 40c6d48 commit 52aa0d4
Show file tree
Hide file tree
Showing 310 changed files with 5,087 additions and 0 deletions.
38 changes: 38 additions & 0 deletions php_modules/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
ifneq (,)
.error This Makefile requires GNU Make.
endif

default: help

# Ensure additional Makefiles are present
MAKEFILES = Makefile.python
$(MAKEFILES): URL=https://raw.githubusercontent.com/devilbox/makefiles/master/$(@)
$(MAKEFILES):
@if ! (curl --fail -sS -o $(@) $(URL) || wget -O $(@) $(URL)); then \
echo "Error, curl or wget required."; \
echo "Exiting."; \
false; \
fi
include $(MAKEFILES)


# -------------------------------------------------------------------------------------------------
# Default configuration
# -------------------------------------------------------------------------------------------------
MYPY_ARGS = --strict --disable-error-code no-any-return

PYLINT_DIR = *.py
PYLINT_PIP_PKGS = yamllint
PYLINT_ARGS = --disable=invalid-name

PYCODE_ARGS = --max-line-length=100

BLACK_LINT_ARGS = -l 100 --check --diff
BLACK_FIX_ARGS = -l 100


# -------------------------------------------------------------------------------------------------
# Default Target
# -------------------------------------------------------------------------------------------------
help:
@echo "make lint # Lint Python sources"
195 changes: 195 additions & 0 deletions php_modules/README-build.yml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# Extension definition: `build.yml`


## Top level defines

| Yaml key | Description |
|-----------------|-------------|
| `already_avail` | Array of PHP versions for which we don't have to install the module as it is already present via its FROM image. |
| `all` | Is generic for all PHP versions and will be used whenever no specific version is defined. |
| `7.2` | A version specific block for PHP 7.2. Its child keys will overwrite what has been defined in `all`. |

**Example:** Using `already_avail`
```yaml
# "{{ php_all_versions }}" Jinja2 variable is available and
# translates to an array of all available PHP versions.
already_avail: "{{ php_all_versions }}"
```
**Example:** Overwriting `git_ref` for a specific version
```yaml
already_avail: [5.2]
all:
type: git
git_url: https://github.com/phalcon/cphalcon
git_ref: master
# PHP 8.1 is using a different git_ref
8.1:
git_ref: v1.0.0
# PHP 8.0 is using a different git_ref dynamically with latest tag found
# See the usage of supported shell code
8.0:
git_ref: $( git tag | sort -V | tail -1 )
```


## Second level defines

The following keys can be added below: `all`, `8.2`, `8.1`, `8.0`, `7.4`, ...

| Yaml key | Required | Supports<br/>Shell code | Description |
|-------------|----------|-------------------------|-------------|
| `pre` | No | Yes | Specify a shell command to be run before module installation. |
| `post` | No | Yes | Specify a shell command to be run after module installation. |
| `build_dep` | No | No | Array Debian packages required to build the module (they won't be present in the final image - only used to built the module) If you don't need any, assign it an empty array: `build_dep: []`. |
| `run_dep` | No | No | Array Debian packages required for the module run-time (they won't be present during the build stage - only in the final image). If you don't need any, assign it an empty array: `run_dep: []`. |
| `type` | **Yes** | No | On of the following types to build the module: `builtin`, `pecl`, `git`, `custom`. |

**Example:**
```yaml
all:
type: builtin
pre: |
ARCH="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE))" \
post: |
rm -f /tmp/file.txt \
build_dep: [libmcrypt-dev]
run_dep: [libmcrypt4]
8.1:
type: builtin
build_dep: []
run_dep: []
```


## Second level defines for `type: builtin`

| Yaml key | Required | Supports<br/>Shell code | Description |
|-------------|----------|-------------------------|-------------|
| `configure` | No | Yes | Add `./configure` arguments. E.g.:<br/> `configure: --with-jpeg --with-png` |

**Example:**
```yaml
all:
type: builtin
8.1:
type: builtin
configure: --with-jpeg --with-png
8.0:
type: builtin
configure: --with-jpeg
```


## Second level defines for `type: pecl`

| Yaml key | Required | Supports<br/>Shell code | Description |
|-------------|----------|-------------------------|-------------|
| `version` | No | Yes | Pecl packet version |
| `command` | No | Yes | Overwrite pecl command (default: `pecl install <ext>`) |

**Example:**
```yaml
all:
type: pecl
command: echo "/usr" | pecl install amqp
build_dep: [librabbitmq-dev]
run_dep: [librabbitmq4]
5.5:
type: pecl
version: 1.9.3
run_dep: [librabbitmq1]
```


## Second level defines for `type: git`

| Yaml key | Required | Supports<br/>Shell code | Description |
|-------------|----------|-------------------------|-------------|
| `git_url` | **Yes** | Yes | Git repository URL |
| `git_ref` | No | Yes | Tag, branch, commit to check out (shell code supported to dynamically checkout) |
| `configure` | No | Yes | Add `./configure` arguments. |
| `command` | No | Yes | Overwrite default command (default: `phpize && ./configure && make && make install`) |

**Example:**
```yaml
already_avail: [5.2]
all:
type: git
git_url: https://github.com/phalcon/cphalcon
git_ref: master
# PHP 8.1 is using a different git_ref
8.1:
git_ref: v1.0.0
# PHP 8.0 is using a different git_ref dynamically with latest tag found
# See the usage of supported shell code
8.0:
git_ref: $( git tag | sort -V | tail -1 )
```


## Second level defines for `type: custom`

| Yaml key | Required | Supports<br/>Shell code | Description |
|-------------|----------|-------------------------|-------------|
| `command` | **Yes** | Yes | Custom command to install and enable a module |

**Example:**
```yaml
all:
type: custom
command: |
wget http://url/file.tar.gz \
&& tar xvfz file.tar.gz \
&& cd file \
&& phpize \
&& ./configure \
&& make \
&& make install \
```


## Usage of shell code

### Single-line vs Multi-line

**Note:** All keys that support shell code can be written as a single line yaml definition or as a multi line yaml definition. Multi-line yaml definitions need a trailing `\` at the end of each line, including the last line.<br/>
**Single-line:**
```bash
all:
pre: VERSION="$( curl http://url | grep -Eo '[0-9.]+' )"
```
**Multi-line:**
```bash
all:
pre: |
VERSION="$( \
curl http://url \
| grep -Eo '[0-9.]+' \
)" \
```

### Single-command vs Multi-command

**Note:** All keys that support shell code also support to write multiple shell commands. If you use multiple shell commands, you need to separate them with `&&`.<br/>
**Single-command:**
```bash
all:
pre: |
VERSION="$( \
curl http://url \
| grep -Eo '[0-9.]+' \
)" \
```
**Multi-command:**
```bash
all:
pre: |
URL="http://url" \
&& VERSION="$( \
curl "${URL} \
| grep -Eo '[0-9.]+' \
)" \
&& echo "${VERSION}" \
```
6 changes: 6 additions & 0 deletions php_modules/README-options.yml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Extension definition: `options.yml`

To be done


For now have a look at the existing modules into the respective `options.yml` files as they are mostly the same.
3 changes: 3 additions & 0 deletions php_modules/README-test.yml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Extension definition: `test.yml`

This is not yet implemented and thus no documentation exists.
42 changes: 42 additions & 0 deletions php_modules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# PHP Module definitions

This documentation describes how to create new or alter existing PHP module definitions.

All PHP modules/extensions (for all PHP versions and both for `amd64` and `arm64` platforms) are defined in here in their dedicated directory. These definitions are then transformed to Ansible group_vars and afterwards Ansible will generate the corresponding Dockerfiles (Stage: `mods`).


## How to add PHP modules?

1. **Inside `php_modules/` directory:**
1. Create a new directory with the name of the PHP module in `php_modules/`
2. Add `build.yml`, `options.yml` and `test.yml` into your newly created directory
3. Alter `build.yml`, `options.yml` and `test.yml` according to documentation below
4. Run `python3 modules-validate.py` to validate the created PHP module definitions
5. Run `python3 modules-generate.py` to create Ansible group_vars

2. **Inside the root of this git repository:**
1. Run `make gen-dockerfiles` to generate Dockerfiles via Ansible
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`

**Note:** If you want to test if your new module builds correctly, you can generate Dockerfiles which only contain your 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 you generate group_vars for your module only via:

```bash
# Only generate group_vars for curl
# Note: if curl has other modules as requiredments to be built beforehand, those will also be added
python3 module-generate.py curl
```


## Extension definition: `build.yml`

See **[README-build.yml.md](README-build.yml.md)** how to alter the `build.yml` file.


## Extension definition: `options.yml`

See **[README-options.yml.md](README-options.yml.md)** how to alter the `options.yml` file.


## Extension definition: `test.yml`

See **[README-test.yml.md](README-test.yml.md)** how to alter the `test.yml` file.
32 changes: 32 additions & 0 deletions php_modules/amqp/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---

# Available Jinja2 variables:
# ---------------------------
# * {{ php_all_versions }}: Array of all PHP versions


all:
type: pecl
command: echo "/usr" | pecl install amqp
build_dep: [librabbitmq-dev]
run_dep: [librabbitmq4]

5.5:
type: pecl
version: 1.9.3
run_dep: [librabbitmq1]

5.4:
type: pecl
version: 1.9.3
run_dep: [librabbitmq1]

5.3:
type: pecl
version: 1.9.3
run_dep: [librabbitmq1]

5.2:
type: pecl
version: 1.6.1
run_dep: [librabbitmq1]
21 changes: 21 additions & 0 deletions php_modules/amqp/options.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---

# The name of the module
name: amqp

# Exclude module build/installation for the following PHP versions
exclude: []

# In order for this module to built correctly against all dependencies,
# the following modules must have been built first.
depends_build: []

# In order for this module to function correctly,
# the following modules must be loaded before.
depends_load: []

# Enable this module by default via php.ini for PHP cli command?
enabled_php_cli: true

# Enable this module by default via php.ini for PHP-FPM?
enabled_php_fpm: true
2 changes: 2 additions & 0 deletions php_modules/amqp/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---

25 changes: 25 additions & 0 deletions php_modules/apcu/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---

# Available Jinja2 variables:
# ---------------------------
# * {{ php_all_versions }}: Array of all PHP versions


all:
type: pecl

5.6:
type: pecl
version: 4.0.11

5.5:
type: pecl
version: 4.0.11

5.4:
type: pecl
version: 4.0.11

5.3:
type: pecl
version: 4.0.11
21 changes: 21 additions & 0 deletions php_modules/apcu/options.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---

# The name of the module
name: apcu

# Exclude module build/installation for the following PHP versions
exclude: [5.2]

# In order for this module to built correctly against all dependencies,
# the following modules must have been built first.
depends_build: []

# In order for this module to function correctly,
# the following modules must be loaded before.
depends_load: []

# Enable this module by default via php.ini for PHP cli command?
enabled_php_cli: true

# Enable this module by default via php.ini for PHP-FPM?
enabled_php_fpm: true
2 changes: 2 additions & 0 deletions php_modules/apcu/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---

Loading

0 comments on commit 52aa0d4

Please sign in to comment.