Skip to content

Commit

Permalink
Convert Cookbook to Resource-Based (#350)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
4 people authored May 23, 2024
1 parent acca564 commit c235f5f
Show file tree
Hide file tree
Showing 38 changed files with 746 additions and 827 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ jobs:
matrix:
os:
- almalinux-8
- centos-7
- almalinux-9
- centos-stream-8
- debian-10
- centos-stream-9
- debian-11
- debian-12
- rockylinux-8
- ubuntu-1804
- rockylinux-9
- ubuntu-2004
- ubuntu-2204
- ubuntu-2404
suite:
- resource
- resource-community
- resource-peclchannel
- source-install
fail-fast: false

steps:
Expand All @@ -59,12 +60,10 @@ jobs:
strategy:
matrix:
os:
- amazonlinux-2
- amazonlinux-2023
suite:
- resource
- resource-community
- resource-peclchannel
- source-install
fail-fast: false

steps:
Expand Down
29 changes: 19 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ This file is used to list changes made in each version of the PHP cookbook.

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

- Convert cookbook to resource-based by replacing recipes and attributes
- Add custom resources php_install and php_ini
- Drop direct support for installation from community repos and source
- Fix failing Actions
- Drop support for CentOS 7, Debian 10, and Amazon Linux 2
- Add support for AlmaLinux 9, CentOS Stream 9, Rocky Linux 9, and Ubuntu 24.04
- Exclude Amazon Linux and Ubuntu 18.04 from community install tests because
they aren't supported by the community repos

## 9.2.18 - *2024-05-03*

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

### Bug

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

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

Expand Down Expand Up @@ -405,28 +414,28 @@ Fixing style cops. Updating test harness

### Bug

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

## v1.2.6

### Bug

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

## v1.2.4

### Improvement

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

### Bug

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

## v1.2.2

Expand Down
47 changes: 0 additions & 47 deletions Dangerfile

This file was deleted.

67 changes: 12 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors)
[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0)

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.
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.

## Maintainers

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

### Chef

- Chef 15.3+

## Attributes

- `node['php']['install_method']` = method to install php with, default `package`.
- `node['php']['directives']` = Hash of directives and values to append to `php.ini`, default `{}`.
- `node['php']['pear_setup']` = Boolean value to determine whether to set up pear repositories. Default: `true`
- `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']`

The file also contains the following attribute types:

- platform specific locations and settings.
- source installation settings

## Resources

This cookbook includes resources for managing:

- [php_pear](https://github.com/sous-chefs/php/tree/master/documentation/php_pear.md)
- [php_pear_channel](https://github.com/sous-chefs/php/tree/master/documentation/php_pear_channel.md)
- [php_fpm_pool](https://github.com/sous-chefs/php/tree/master/documentation/php_fpm_pool.md)

## Recipes

### `php::default`

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.

### `php::package`
- [php_ini](documentation/php_ini.md)
- [php_install](documentation/php_install.md)
- [php_pear](documentation/php_pear.md)
- [php_pear_channel](documentation/php_pear_channel.md)
- [php_fpm_pool](documentation/php_fpm_pool.md)

This recipe installs PHP from packages.

### `php::community_package`

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.
## Usage

Set `node['php']['install_method'] = 'community_package'` to use these repositories.
<!-- markdown-link-check-disable-next-line -->
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).

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:
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:

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

### `php::source`

This recipe installs PHP from source.

## Usage

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:

### Role example

```ruby
name 'php'
description 'Install php from source'
override_attributes(
'php' => {
'install_method' => 'source',
}
)
run_list(
'recipe[php]'
)
```

## Contributors

This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false)
Expand Down
115 changes: 115 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Upgrading

The `package` and `ini` recipes have been removed and replaced with custom resources:

- package --> php_install
- ini --> php_ini

## Attributes

Attributes have been converted to resource properties; default values are set in helpers. Please see the documentation for all properties and their defaults.

The following table lists the resources and properties that attributes have been moved to:

| Attribute | Resource | Property Name (if different) |
| ----------------------| -------------------------------------------- | ---------------------------- |
| ['bin'] | Removed | |
| ['checksum'] | Removed | |
| ['conf_dir'] | php_ini, php_install, php_pear | |
| ['configure_options'] | Removed | |
| ['directives'] | php_fpm_pool, php_ini, php_install, php_pear | |
| ['disable_mod'] | php_pear | |
| ['enable_mod'] | php_pear | |
| ['ext_conf_dir'] | php_pear | |
| ['ext_dir'] | php_fpm_pool, php_ini, php_install | |
| ['fpm_conf_dir'] | php_fpm_pool | |
| ['fpm_default_conf'] | php_fpm_pool | :default_conf |
| ['fpm_group'] | php_fpm_pool | :group |
| ['fpm_ini_control'] | php_fpm_pool | |
| ['fpm_listen_group'] | php_fpm_pool | :listen_group |
| ['fpm_listen_user'] | php_fpm_pool | :listen_user |
| ['fpm_package'] | php_fpm_pool | |
| ['fpm_pool_dir'] | php_fpm_pool | :pool_dir |
| ['fpm_service'] | php_fpm_pool | :service |
| ['fpm_socket'] | php_fpm_pool | :listen |
| ['fpm_user'] | php_fpm_pool | :user |
| ['ini']['cookbook'] | php_fpm_pool, php_ini, php_install | :ini_cookbook |
| ['ini']['template'] | php_fpm_pool, php_ini, php_install | :ini_template |
| ['install_method'] | Removed | |
| ['packages'] | php_install | |
| ['pear'] | Removed | |
| ['pear_channels'] | Removed | |
| ['pear_setup'] | Removed | |
| ['pecl'] | php_pear | |
| ['prefix_dir'] | Removed | |
| ['src_deps'] | Removed | |
| ['src_recompile'] | Removed | |
| ['url'] | Removed | |
| ['version'] | Helper - versions now follow X.X format | php_version |

Attributes specific to recipes or installing from source were removed.

## Package Install

Installing from package managers can now be done through the `php_install` resource.

```ruby
# Old Style
include_recipe 'php::default'
```

```ruby
# New Style
php_install 'php' do
action :install
end
```

## Community Install

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.

## Source Install

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.

## .ini Configuration

Configuring PHP and FPM can now be done through the `php_ini` resource.

```ruby
# Old Style
include_recipe 'php::ini'
```

```ruby
# New Style
php_ini 'php' do
action :add
end
```

A `.ini` file can also be removed using the `php_ini` resource.

```ruby
# New Style
php_ini 'php' do
action :remove
end
```

The `node['php']['fpm_ini_control']` attribute has been moved to a property of the `php_fpm_pool` resource.

```ruby
# Old Style
node['php']['fpm_ini_control'] = true
include_recipe 'php::ini'
```

```ruby
# New Style
php_fpm_pool 'fpm_pool' do
fpm_ini_control true
action :install
end
```
Loading

0 comments on commit c235f5f

Please sign in to comment.