Skip to content

Commit c235f5f

Browse files
ArtofBugsawhittle2ramerethArtofBugs
authored
Convert Cookbook to Resource-Based (#350)
* Custom resources, library helpers, passing source tests * Add missing resources back to test cookbook Signed-off-by: Lance Albertson <[email protected]> * Various fixes and refactoring Signed-off-by: Lance Albertson <[email protected]> * Fixing errors, trying to make community work * Amazon Linux + Centos kinda working * Trying to fix debian * Update metadata.rb * Update metadata.rb * Update metadata.rb * Update community.rb * Update install.rb * Update community.rb * Update install.rb * Update metadata.rb * Update community.rb * Update community.rb * Update community.rb * Update community.rb * Update ci.yml * Update metadata.rb * Update community.rb * Update community.rb * Update community.rb * Update community.rb * Update community.rb * Update community.rb * Update community.rb * Update community.rb * Update community.rb * Update community.rb * Update community.rb * Fix amazonlinux version number * Uncomment idempotency lines Signed-off-by: ArtofBugs <[email protected]> * Revert "Fix amazonlinux version number" This reverts commit 8bc17c1. * Uncomment source install code Signed-off-by: ArtofBugs <[email protected]> * Update properties Signed-off-by: ArtofBugs <[email protected]> * Fix cookstyle Signed-off-by: ArtofBugs <[email protected]> * Rename config.rb to ini.rb Signed-off-by: ArtofBugs <[email protected]> * Update default recipe and remove unnecessary helpers Signed-off-by: ArtofBugs <[email protected]> * Comment out source install since @ramereth wants to remove it Signed-off-by: ArtofBugs <[email protected]> * Fix ini resource name and remove default action Signed-off-by: ArtofBugs <[email protected]> * Clean up unnecessary code Signed-off-by: ArtofBugs <[email protected]> * Fix helpers that depend on install_method Signed-off-by: ArtofBugs <[email protected]> * Remove `new_resource.` from beginning in properties Signed-off-by: ArtofBugs <[email protected]> * Remove options for source install Signed-off-by: ArtofBugs <[email protected]> * Fix php_conf_dir being pulled from property instead of helper Signed-off-by: ArtofBugs <[email protected]> * Revert order between apt update and php installation Signed-off-by: ArtofBugs <[email protected]> * Fix nested package resources Signed-off-by: ArtofBugs <[email protected]> * Fix php_ext_dir substitution in templates Signed-off-by: ArtofBugs <[email protected]> * Fix cookstyle Signed-off-by: ArtofBugs <[email protected]> * Remove source from run lists Signed-off-by: ArtofBugs <[email protected]> * Remove source-install suite from jobs Signed-off-by: ArtofBugs <[email protected]> * Fix default package installation being inside community conditional Signed-off-by: ArtofBugs <[email protected]> * Fix cookstyle Signed-off-by: ArtofBugs <[email protected]> * Move community and source install content out of php_install resource Signed-off-by: ArtofBugs <[email protected]> * Edit properties for customization for community installs Signed-off-by: ArtofBugs <[email protected]> * Fix conditionals for cookstyle Signed-off-by: ArtofBugs <[email protected]> * Fix missing assignment operators Signed-off-by: ArtofBugs <[email protected]> * Pin php package version for amazon Signed-off-by: ArtofBugs <[email protected]> * Fix name clash Signed-off-by: ArtofBugs <[email protected]> * Fix missing fpm_service property Signed-off-by: ArtofBugs <[email protected]> * Test and fix fpm_ini_control from #241 Signed-off-by: ArtofBugs <[email protected]> * Move fpm ini management to fpm_pool Signed-off-by: ArtofBugs <[email protected]> * Fix fpm_conf_dir location on RHEL; minor new properties for fpm_pool resource Signed-off-by: ArtofBugs <[email protected]> * Skip Ubuntu 18.04 when installing from community repo Signed-off-by: ArtofBugs <[email protected]> * Fix amazonlinux remi installation Signed-off-by: ArtofBugs <[email protected]> * Exclude ubuntu-18.04 from community run Signed-off-by: ArtofBugs <[email protected]> * Skip Amazon Linux for community install Signed-off-by: ArtofBugs <[email protected]> * Remove already-symlinked pear binary location Signed-off-by: ArtofBugs <[email protected]> * Rename config_spec.rb to ini_spec.rb Signed-off-by: ArtofBugs <[email protected]> * Add :remove action to php_ini Signed-off-by: ArtofBugs <[email protected]> * Move depends from main metadata.rb to test metadata.rb Signed-off-by: ArtofBugs <[email protected]> * Remove default recipe Signed-off-by: ArtofBugs <[email protected]> * Update documentation Signed-off-by: ArtofBugs <[email protected]> * Disable md-link check on README temporarily; rename master branch to main branch in all links Signed-off-by: ArtofBugs <[email protected]> * Remove all source install Signed-off-by: ArtofBugs <[email protected]> * Pin Amazon package versions Signed-off-by: ArtofBugs <[email protected]> * Remove duplicated comment Signed-off-by: ArtofBugs <[email protected]> * Change root_group to just "root" Signed-off-by: ArtofBugs <[email protected]> * Remove unnecessary helpers code for ext_dir Signed-off-by: ArtofBugs <[email protected]> * Change documentation links to be relative Signed-off-by: ArtofBugs <[email protected]> * Remove Dangerfile Signed-off-by: ArtofBugs <[email protected]> * Use php_version helper instead of case statements in helpers; change php_version to use major-minor only Signed-off-by: ArtofBugs <[email protected]> * Update spec tests Signed-off-by: ArtofBugs <[email protected]> * Pin amazon php version to 8.2 Signed-off-by: ArtofBugs <[email protected]> Signed-off-by: ArtofBugs <[email protected]> * Include helpers in recipes and resources by default Signed-off-by: ArtofBugs <[email protected]> * Add UPGRADING.md Signed-off-by: ArtofBugs <[email protected]> * Add clarifications Signed-off-by: ArtofBugs <[email protected]> * Add attributes conversion table Signed-off-by: ArtofBugs <[email protected]> * Update CHANGELOG Signed-off-by: ArtofBugs <[email protected]> * Remove dead ticket links Signed-off-by: ArtofBugs <[email protected]> * Remove unnecessary helpers Signed-off-by: ArtofBugs <[email protected]> * Add note about version helper format change to major-minor only Signed-off-by: ArtofBugs <[email protected]> * Fix php-xml version from package manager being ahead on ubuntu/debian Signed-off-by: ArtofBugs <[email protected]> * Fix extension location not being found and added to ini Signed-off-by: ArtofBugs <[email protected]> * Get most recent stable version by querying the PEAR REST API since the search command ignores preferred state Signed-off-by: ArtofBugs <[email protected]> * Fix adding channel name to url Signed-off-by: ArtofBugs <[email protected]> * Fix missing trailing pipe in md table Signed-off-by: ArtofBugs <[email protected]> * Search for pear preferred state instead of hardcoding stable Signed-off-by: ArtofBugs <[email protected]> * Update to match kitchen.global.yml supported platforms Signed-off-by: ArtofBugs <[email protected]> * Update versions helper Signed-off-by: ArtofBugs <[email protected]> * Update Changelog Signed-off-by: ArtofBugs <[email protected]> --------- Signed-off-by: Lance Albertson <[email protected]> Signed-off-by: ArtofBugs <[email protected]> Signed-off-by: ArtofBugs <[email protected]> Signed-off-by: ArtofBugs <[email protected]> Co-authored-by: Abi <[email protected]> Co-authored-by: Lance Albertson <[email protected]> Co-authored-by: ArtofBugs <[email protected]>
1 parent acca564 commit c235f5f

38 files changed

+746
-827
lines changed

.github/workflows/ci.yml

+6-7
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,20 @@ jobs:
2424
matrix:
2525
os:
2626
- almalinux-8
27-
- centos-7
27+
- almalinux-9
2828
- centos-stream-8
29-
- debian-10
29+
- centos-stream-9
3030
- debian-11
31+
- debian-12
3132
- rockylinux-8
32-
- ubuntu-1804
33+
- rockylinux-9
3334
- ubuntu-2004
3435
- ubuntu-2204
36+
- ubuntu-2404
3537
suite:
3638
- resource
3739
- resource-community
3840
- resource-peclchannel
39-
- source-install
4041
fail-fast: false
4142

4243
steps:
@@ -59,12 +60,10 @@ jobs:
5960
strategy:
6061
matrix:
6162
os:
62-
- amazonlinux-2
63+
- amazonlinux-2023
6364
suite:
6465
- resource
65-
- resource-community
6666
- resource-peclchannel
67-
- source-install
6867
fail-fast: false
6968

7069
steps:

CHANGELOG.md

+19-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ This file is used to list changes made in each version of the PHP cookbook.
66

77
Standardise files with files in sous-chefs/repo-management
88

9+
- Convert cookbook to resource-based by replacing recipes and attributes
10+
- Add custom resources php_install and php_ini
11+
- Drop direct support for installation from community repos and source
12+
- Fix failing Actions
13+
- Drop support for CentOS 7, Debian 10, and Amazon Linux 2
14+
- Add support for AlmaLinux 9, CentOS Stream 9, Rocky Linux 9, and Ubuntu 24.04
15+
- Exclude Amazon Linux and Ubuntu 18.04 from community install tests because
16+
they aren't supported by the community repos
17+
918
## 9.2.18 - *2024-05-03*
1019

1120
## 9.2.17 - *2024-05-03*
@@ -375,7 +384,7 @@ Special thanks to @ThatGerber for getting the PR for this release together
375384

376385
### Bug
377386

378-
- **[COOK-4186](https://tickets.opscode.com/browse/COOK-4186)** - Upgrade_package concatenates an empty version string when version is not set or is empty.
387+
- [COOK-4186] - Upgrade_package concatenates an empty version string when version is not set or is empty.
379388

380389
## v1.3.12 (2014-01-28)
381390

@@ -405,28 +414,28 @@ Fixing style cops. Updating test harness
405414

406415
### Bug
407416

408-
- **[COOK-3479](https://tickets.opscode.com/browse/COOK-3479)** - Added Windows support to PHP
409-
- **[COOK-2909](https://tickets.opscode.com/browse/COOK-2909)** - Warnings about Chef::Exceptions::ShellCommandFailed is deprecated
417+
- [COOK-3479] - Added Windows support to PHP
418+
- [COOK-2909] - Warnings about Chef::Exceptions::ShellCommandFailed is deprecated
410419

411420
## v1.2.6
412421

413422
### Bug
414423

415-
- **[COOK-3628](https://tickets.opscode.com/browse/COOK-3628)** - Fix PHP download URL
416-
- **[COOK-3568](https://tickets.opscode.com/browse/COOK-3568)** - Fix Test Kitchen tests
417-
- **[COOK-3402](https://tickets.opscode.com/browse/COOK-3402)** - When the `ext_dir` setting is present, configure php properly for the source recipe
418-
- **[COOK-2926](https://tickets.opscode.com/browse/COOK-2926)** - Fix pear package detection when installing specific version
424+
- [COOK-3628] - Fix PHP download URL
425+
- [COOK-3568] - Fix Test Kitchen tests
426+
- [COOK-3402] - When the `ext_dir` setting is present, configure php properly for the source recipe
427+
- [COOK-2926] - Fix pear package detection when installing specific version
419428

420429
## v1.2.4
421430

422431
### Improvement
423432

424-
- **[COOK-3047](https://tickets.opscode.com/browse/COOK-3047)** - Sort directives in `php.ini`
425-
- **[COOK-2928](https://tickets.opscode.com/browse/COOK-2928)** - Abstract `php.ini` directives into variables
433+
- [COOK-3047] - Sort directives in `php.ini`
434+
- [COOK-2928] - Abstract `php.ini` directives into variables
426435

427436
### Bug
428437

429-
- **[COOK-2378](https://tickets.opscode.com/browse/COOK-2378)** - Fix `php_pear` for libevent
438+
- [COOK-2378] - Fix `php_pear` for libevent
430439

431440
## v1.2.2
432441

Dangerfile

-47
This file was deleted.

README.md

+12-55
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors)
77
[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0)
88

9-
It installs and configures PHP and the PEAR package management system. Also includes resources for managing PEAR (and PECL) packages, PECL channels, and PHP-FPM pools.
9+
The `php` cookbook installs and configures PHP and the PEAR package management system. Also includes resources for managing PEAR (and PECL) packages, PECL channels, and PHP-FPM pools.
1010

1111
## Maintainers
1212

@@ -19,76 +19,33 @@ This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of
1919
- Ubuntu 18.04 / 20.04 / 22.04
2020
- Debian 10 / 11
2121
- CentOS 7+ (incl. Alma & Rocky)
22+
- Amazon Linux 2023
2223

2324
### Chef
2425

2526
- Chef 15.3+
2627

27-
## Attributes
28-
29-
- `node['php']['install_method']` = method to install php with, default `package`.
30-
- `node['php']['directives']` = Hash of directives and values to append to `php.ini`, default `{}`.
31-
- `node['php']['pear_setup']` = Boolean value to determine whether to set up pear repositories. Default: `true`
32-
- `node['php']['pear_channels']` = List of external pear channels to add if `node['php']['pear_setup']` is true. Default: `['pear.php.net', 'pecl.php.net']`
33-
34-
The file also contains the following attribute types:
35-
36-
- platform specific locations and settings.
37-
- source installation settings
38-
3928
## Resources
4029

4130
This cookbook includes resources for managing:
4231

43-
- [php_pear](https://github.com/sous-chefs/php/tree/master/documentation/php_pear.md)
44-
- [php_pear_channel](https://github.com/sous-chefs/php/tree/master/documentation/php_pear_channel.md)
45-
- [php_fpm_pool](https://github.com/sous-chefs/php/tree/master/documentation/php_fpm_pool.md)
46-
47-
## Recipes
48-
49-
### `php::default`
50-
51-
Include the default recipe in a run list, to get `php`. By default `php` is installed from packages but this can be changed by using the `install_method` attribute.
52-
53-
### `php::package`
32+
- [php_ini](documentation/php_ini.md)
33+
- [php_install](documentation/php_install.md)
34+
- [php_pear](documentation/php_pear.md)
35+
- [php_pear_channel](documentation/php_pear_channel.md)
36+
- [php_fpm_pool](documentation/php_fpm_pool.md)
5437

55-
This recipe installs PHP from packages.
56-
57-
### `php::community_package`
58-
59-
This recipe installs PHP from one of two available community package repositories, depending on platform family. This provides the ability to install PHP versions that are no provided by the official distro repositories.
38+
## Usage
6039

61-
Set `node['php']['install_method'] = 'community_package'` to use these repositories.
40+
<!-- markdown-link-check-disable-next-line -->
41+
Simply use the `php_install` resource wherever you would like PHP installed from a package. By default, it will install from the platform's package manager (see [`libraries/helpers.rb`](https://github.com/sous-chefs/php/tree/main/libraries/helpers.rb) to see the default packages list for each platoform).
6242

63-
Please see `test/cookbooks/test/recipes/community.rb` for an example of how to use attributes to install the desired version of PHP & its supporting packages, and please refer to the documentation on these community repositories:
43+
Please see [`test/cookbooks/test/recipes/community.rb`](https://github.com/sous-chefs/php/tree/main/test/cookbooks/test/recipes/community.rb) for an example of using the `php_install` resource to install the desired version of PHP & its supporting packages from a community repository, and please refer to the documentation on these community repositories:
6444

65-
- CentOS - [Remi’s RPM repository](https://rpms.remirepo.net)
45+
- RHEL/CentOS - [Remi’s RPM repository](https://rpms.remirepo.net)
6646
- Ubuntu - [Ondřej Surý PPA](https://launchpad.net/~ondrej/+archive/ubuntu/php)
6747
- Debian - [Sury repo](https://deb.sury.org/)
6848

69-
### `php::source`
70-
71-
This recipe installs PHP from source.
72-
73-
## Usage
74-
75-
Simply include the `php` recipe where ever you would like php installed. To install from source override the `node['php']['install_method']` attribute within a role or wrapper cookbook:
76-
77-
### Role example
78-
79-
```ruby
80-
name 'php'
81-
description 'Install php from source'
82-
override_attributes(
83-
'php' => {
84-
'install_method' => 'source',
85-
}
86-
)
87-
run_list(
88-
'recipe[php]'
89-
)
90-
```
91-
9249
## Contributors
9350

9451
This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false)

UPGRADING.md

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Upgrading
2+
3+
The `package` and `ini` recipes have been removed and replaced with custom resources:
4+
5+
- package --> php_install
6+
- ini --> php_ini
7+
8+
## Attributes
9+
10+
Attributes have been converted to resource properties; default values are set in helpers. Please see the documentation for all properties and their defaults.
11+
12+
The following table lists the resources and properties that attributes have been moved to:
13+
14+
| Attribute | Resource | Property Name (if different) |
15+
| ----------------------| -------------------------------------------- | ---------------------------- |
16+
| ['bin'] | Removed | |
17+
| ['checksum'] | Removed | |
18+
| ['conf_dir'] | php_ini, php_install, php_pear | |
19+
| ['configure_options'] | Removed | |
20+
| ['directives'] | php_fpm_pool, php_ini, php_install, php_pear | |
21+
| ['disable_mod'] | php_pear | |
22+
| ['enable_mod'] | php_pear | |
23+
| ['ext_conf_dir'] | php_pear | |
24+
| ['ext_dir'] | php_fpm_pool, php_ini, php_install | |
25+
| ['fpm_conf_dir'] | php_fpm_pool | |
26+
| ['fpm_default_conf'] | php_fpm_pool | :default_conf |
27+
| ['fpm_group'] | php_fpm_pool | :group |
28+
| ['fpm_ini_control'] | php_fpm_pool | |
29+
| ['fpm_listen_group'] | php_fpm_pool | :listen_group |
30+
| ['fpm_listen_user'] | php_fpm_pool | :listen_user |
31+
| ['fpm_package'] | php_fpm_pool | |
32+
| ['fpm_pool_dir'] | php_fpm_pool | :pool_dir |
33+
| ['fpm_service'] | php_fpm_pool | :service |
34+
| ['fpm_socket'] | php_fpm_pool | :listen |
35+
| ['fpm_user'] | php_fpm_pool | :user |
36+
| ['ini']['cookbook'] | php_fpm_pool, php_ini, php_install | :ini_cookbook |
37+
| ['ini']['template'] | php_fpm_pool, php_ini, php_install | :ini_template |
38+
| ['install_method'] | Removed | |
39+
| ['packages'] | php_install | |
40+
| ['pear'] | Removed | |
41+
| ['pear_channels'] | Removed | |
42+
| ['pear_setup'] | Removed | |
43+
| ['pecl'] | php_pear | |
44+
| ['prefix_dir'] | Removed | |
45+
| ['src_deps'] | Removed | |
46+
| ['src_recompile'] | Removed | |
47+
| ['url'] | Removed | |
48+
| ['version'] | Helper - versions now follow X.X format | php_version |
49+
50+
Attributes specific to recipes or installing from source were removed.
51+
52+
## Package Install
53+
54+
Installing from package managers can now be done through the `php_install` resource.
55+
56+
```ruby
57+
# Old Style
58+
include_recipe 'php::default'
59+
```
60+
61+
```ruby
62+
# New Style
63+
php_install 'php' do
64+
action :install
65+
end
66+
```
67+
68+
## Community Install
69+
70+
Installing from community repos is no longer built in to the cookbook. The `php_install` resource can be configured to help in installing from community repos. See [`test/cookbooks/test/recipes/community.rb`](https://github.com/sous-chefs/php/tree/main/test/cookbooks/test/recipes/community.rb) for an example of fetching and installing from community repos.
71+
72+
## Source Install
73+
74+
Installing from source is no longer built in to the cookbook. Users should manage installation from source on their own. The original recipe can be referenced [here](https://github.com/sous-chefs/php/blob/9.2.16/recipes/source.rb) to help with the switch.
75+
76+
## .ini Configuration
77+
78+
Configuring PHP and FPM can now be done through the `php_ini` resource.
79+
80+
```ruby
81+
# Old Style
82+
include_recipe 'php::ini'
83+
```
84+
85+
```ruby
86+
# New Style
87+
php_ini 'php' do
88+
action :add
89+
end
90+
```
91+
92+
A `.ini` file can also be removed using the `php_ini` resource.
93+
94+
```ruby
95+
# New Style
96+
php_ini 'php' do
97+
action :remove
98+
end
99+
```
100+
101+
The `node['php']['fpm_ini_control']` attribute has been moved to a property of the `php_fpm_pool` resource.
102+
103+
```ruby
104+
# Old Style
105+
node['php']['fpm_ini_control'] = true
106+
include_recipe 'php::ini'
107+
```
108+
109+
```ruby
110+
# New Style
111+
php_fpm_pool 'fpm_pool' do
112+
fpm_ini_control true
113+
action :install
114+
end
115+
```

0 commit comments

Comments
 (0)