diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index e10849328..ec13b7c18 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -18,16 +18,16 @@ - `libraries/` - Library helpers to assist with the cookbook. May contain multiple files depending on complexity of the cookbook. - `templates/` - ERB templates that may be used in the cookbook - `files/` - files that may be used in the cookbook -- `metadata.rb`, `Berksfile` - Cookbook metadata and dependencies +- `metadata.rb`, `Policyfile.rb` - Cookbook metadata and dependencies ## Build and Test System ### Environment Setup -**MANDATORY:** Install Chef Workstation first - provides chef, berks, cookstyle, kitchen tools. +**MANDATORY:** Install Chef Workstation first - provides chef, cookstyle, kitchen tools. ### Essential Commands (strict order) ```bash -berks install # Install dependencies (always first) +chef install Policyfile.rb # Install dependencies (always first) cookstyle # Ruby/Chef linting yamllint . # YAML linting markdownlint-cli2 '**/*.md' # Markdown linting @@ -42,7 +42,7 @@ chef exec rspec # Unit tests (ChefSpec) - **Full CI Runtime:** 30+ minutes for complete matrix ### Common Issues and Solutions -- **Always run `berks install` first** - most failures are dependency-related +- **Always run `chef install Policyfile.rb` first** - most failures are dependency-related - **Docker must be running** for kitchen tests - **Chef Workstation required** - no workarounds, no alternatives - **Test data bags needed** (optional for some cookbooks) in `test/integration/data_bags/` for convergence @@ -88,7 +88,7 @@ These instructions are validated for Sous Chefs cookbooks. **Do not search for b **Error Resolution Checklist:** 1. Verify Chef Workstation installation -2. Confirm `berks install` completed successfully +2. Confirm `chef install Policyfile.rb` completed successfully 3. Ensure Docker is running for integration tests 4. Check for missing test data dependencies diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 04921a1d0..8d5e41bc1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,6 @@ jobs: - almalinux-8 - almalinux-9 - centos-stream-9 - - debian-11 - debian-12 - fedora-latest - rockylinux-8 @@ -38,6 +37,11 @@ jobs: - resource - resource-community - resource-peclchannel + exclude: + - os: fedora-latest + suite: resource-community + - os: ubuntu-2004 + suite: resource-community fail-fast: false steps: diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index 91d1e83dc..7f682abdd 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -20,5 +20,5 @@ jobs: uses: actions/checkout@v7 - name: Install Chef uses: actionshub/chef-install@main - - name: Install cookbooks - run: berks install + - name: Install Policyfile dependencies + run: chef install Policyfile.rb diff --git a/.gitignore b/.gitignore index be3b9a8bc..d06e466e9 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,6 @@ doc/ rdoc # chef infra stuff -Berksfile.lock .kitchen kitchen.local.yml vendor/ diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 000000000..b44104e1d --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,11 @@ +# Agent Notes + +## Policyfile Integration Limits + +The `resource-community` suite exercises external community package repositories, not only this cookbook's resources. Keep the suite matrix aligned with package availability: + +* Fedora is excluded from `resource-community` because the Remi Fedora repository does not provide the `php8.2`, `php8.2-cgi`, `php8.2-cli`, `php8.2-dev`, and `php8.2-xml` package set used by the test recipe. +* Ubuntu 20.04 is excluded from `resource-community` because the Ondrej PHP PPA no longer provides the PHP 8.2 package set for focal. +* EL9 `resource-community` uses the legacy `yum-remi-chef::remi` recipe, which still configures only older Remi GPG keys. The test recipe adds the current Remi signing key set so package verification can follow upstream key rotation. +* Fedora `resource` and `resource-peclchannel` remain supported. `php_pear` installs explicit compiler packages on Fedora instead of using `build_essential`, because Dokken Fedora images can request an unavailable host-matching `kernel-devel` package. +* Fedora skips the PECL `sync` fixture because `sync` 1.1.3 does not compile against Fedora latest's PHP 8.5 headers. Keep the channel and PEAR package checks enabled there. diff --git a/Berksfile b/Berksfile deleted file mode 100644 index 7048569b4..000000000 --- a/Berksfile +++ /dev/null @@ -1,7 +0,0 @@ -source 'https://supermarket.chef.io' - -metadata - -group :integration do - cookbook 'test', path: './test/cookbooks/test' -end diff --git a/Policyfile.rb b/Policyfile.rb new file mode 100644 index 000000000..96231acfb --- /dev/null +++ b/Policyfile.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +name 'php' + +run_list 'test::default' + +cookbook 'php', path: '.' +cookbook 'apt', git: 'https://github.com/sous-chefs/apt.git', branch: 'main' +cookbook 'ondrej_ppa_ubuntu', git: 'https://github.com/MelonSmasher/ondrej_ppa_ubuntu.git', branch: 'master' +cookbook 'test', path: './test/cookbooks/test' +cookbook 'yum', git: 'https://github.com/sous-chefs/yum.git', branch: 'main' +cookbook 'yum-epel', git: 'https://github.com/sous-chefs/yum-epel.git', tag: '5.0.9' +cookbook 'yum-remi-chef', '>= 5.0.1', git: 'https://github.com/sous-chefs/yum-remi-chef.git', tag: '5.0.1' + +Dir.children('./test/cookbooks/test/recipes').grep(/\.rb\z/).sort.each do |recipe| + recipe_name = File.basename(recipe, '.rb') + + named_run_list recipe_name.to_sym, "test::#{recipe_name}" +end diff --git a/UPGRADING.md b/UPGRADING.md index bb03ab395..12db43583 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -71,7 +71,7 @@ Installing from community repos is no longer built in to the cookbook. The `php_ ## 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. +Installing from source is no longer built in to the cookbook. Users should manage installation from source on their own. The [original source install recipe](https://github.com/sous-chefs/php/blob/9.2.16/recipes/source.rb) can help with the switch. ## .ini Configuration diff --git a/chefignore b/chefignore index a27b0b258..13b643c8e 100644 --- a/chefignore +++ b/chefignore @@ -83,13 +83,6 @@ test/* */.hg/* */.svn/* -# Berkshelf # -############# -Berksfile -Berksfile.lock -cookbooks/* -tmp - # Bundler # ########### vendor/* diff --git a/documentation/php_fpm_pool.md b/documentation/php_fpm_pool.md index e5fbda6fd..812e1348e 100644 --- a/documentation/php_fpm_pool.md +++ b/documentation/php_fpm_pool.md @@ -13,20 +13,20 @@ More info: ## Properties -| Name | Type | Default | Description | -| ------------------- | --------------- | ------------------------------------ | ------------------------------------------------------------------------------------- | -| `pool_name` | `String` | The name of the FPM pool | | -| `listen` | `String` | `/var/run/php-fpm.sock` (RHEL & Amazon) or `/var/run/php/php-fpm.sock` (Debian) | The listen address | -| `user` | `String` | The webserver user for your distro. | The user to run the FPM under | -| `group` | `String` | The webserver group for your distro. | The group to run the FPM under | -| `process_manager` | `String` | `dynamic` | Process manager to use - see | -| `max_children` | `Integer` | `5` | Max children to scale to | -| `start_servers` | `Integer` | `2` | Number of servers to start the pool with | -| `min_spare_servers` | `Integer` | `1` | Minimum number of servers to have as spares | -| `max_spare_servers` | `Integer` | `3` | Maximum number of servers to have as spares | -| `chdir` | `String` | `/` | The startup working directory of the pool | -| `additional_config` | `Hash` | `{}` | Additional parameters in JSON | -| `fpm_ini_control` | `[true, false]` | `false` | Whether to add a new `php.ini` file for FPM | +| Name | Type | Default | Description | +| ------------------- | --------------- | ------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | +| `pool_name` | `String` | The name of the FPM pool | | +| `listen` | `String` | `/var/run/php-fpm.sock` (RHEL & Amazon) or `/var/run/php/php-fpm.sock` (Debian) | The listen address | +| `user` | `String` | The webserver user for your distro. | The user to run the FPM under | +| `group` | `String` | The webserver group for your distro. | The group to run the FPM under | +| `process_manager` | `String` | `dynamic` | Process mgr - see | +| `max_children` | `Integer` | `5` | Max children to scale to | +| `start_servers` | `Integer` | `2` | Number of servers to start the pool with | +| `min_spare_servers` | `Integer` | `1` | Minimum number of servers to have as spares | +| `max_spare_servers` | `Integer` | `3` | Maximum number of servers to have as spares | +| `chdir` | `String` | `/` | The startup working directory of the pool | +| `additional_config` | `Hash` | `{}` | Additional parameters in JSON | +| `fpm_ini_control` | `[true, false]` | `false` | Whether to add a new `php.ini` file for FPM | ## Examples diff --git a/documentation/php_install.md b/documentation/php_install.md index e846d0290..ab83e5640 100644 --- a/documentation/php_install.md +++ b/documentation/php_install.md @@ -8,15 +8,16 @@ By default, installs the `php` packages appropriate for your platform and adds a ## Properties -| Name | Type | Default | Description | -| ------------------- | ---------------- | ----------------------------------------------------- | ----------------------------------------------------------- | -| `packages` | `String` | Platform-specific - see `libraries/helpers.rb` | Packages to install | -| `options` | `[String, Array]` | | Installation options (see Chef `package` resource) | -| `conf_dir` | `String` | Platform-specific - see `libraries/helpers.rb` | Directory to place the `php.ini` file under | -| `ini_template` | `String` | `php.ini.erb` (see `templates//php.ini.rb`) | Template to use to create the `php.ini` file | -| `ini_cookbook` | `String` | `php` (this cookbook) | Cookbook where the template is located | -| `directives` | `Hash` | `{}` | Directive-value pairs to add to the `php.ini` file | -| `ext_dir` | `String` | Platform-specific - see `libraries/helpers.rb` | Directory in which the loadable extensions (modules) reside | +| Name | Type | Default | +| -------------- | ----------------- | --------------------------------------------------- | +| -------------- | ----------------- | --------------------------------------------------- | +| `packages` | `String` | Platform-specific - see `libraries/helpers.rb` | +| `options` | `[String, Array]` | | +| `conf_dir` | `String` | Platform-specific - see `libraries/helpers.rb` | +| `ini_template` | `String` | `php.ini.erb` (see `templates//php.ini.rb`) | +| `ini_cookbook` | `String` | `php` (this cookbook) | +| `directives` | `Hash` | `{}` | +| `ext_dir` | `String` | Platform-specific - see `libraries/helpers.rb` | ## Examples diff --git a/kitchen.dokken.yml b/kitchen.dokken.yml index 1d8623e02..e403dca3e 100644 --- a/kitchen.dokken.yml +++ b/kitchen.dokken.yml @@ -4,7 +4,9 @@ driver: chef_version: <%= ENV['CHEF_VERSION'] || 'current' %> transport: { name: dokken } -provisioner: { name: dokken } +provisioner: + name: dokken + policyfile: Policyfile.rb platforms: - name: almalinux-8 diff --git a/kitchen.exec.yml b/kitchen.exec.yml index ba7b2a962..714915bca 100644 --- a/kitchen.exec.yml +++ b/kitchen.exec.yml @@ -1,6 +1,8 @@ --- driver: { name: exec } transport: { name: exec } +provisioner: + policyfile: Policyfile.rb platforms: - name: macos-latest diff --git a/kitchen.global.yml b/kitchen.global.yml index 1740e4614..4e6c4efab 100644 --- a/kitchen.global.yml +++ b/kitchen.global.yml @@ -1,6 +1,6 @@ --- provisioner: - name: chef_infra + name: policyfile_zero product_name: chef product_version: <%= ENV['CHEF_VERSION'] || 'latest' %> channel: stable @@ -10,6 +10,7 @@ provisioner: multiple_converge: <%= ENV['MULTIPLE_CONVERGE'] || 2 %> deprecations_as_errors: true log_level: <%= ENV['CHEF_LOG_LEVEL'] || 'auto' %> + policyfile: Policyfile.rb verifier: name: inspec @@ -19,7 +20,6 @@ platforms: - name: almalinux-9 - name: amazonlinux-2023 - name: centos-stream-9 - - name: debian-11 - name: debian-12 - name: fedora-latest - name: opensuse-leap-15 diff --git a/kitchen.yml b/kitchen.yml index c8362e2af..7d4bec178 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -3,12 +3,13 @@ driver: name: vagrant provisioner: - name: chef_infra + name: policyfile_zero product_name: chef chef_license: accept-no-persist enforce_idempotency: true multiple_converge: 2 deprecations_as_errors: true + policyfile: Policyfile.rb verifier: name: inspec @@ -18,7 +19,6 @@ platforms: - name: almalinux-9 - name: amazonlinux-2023 - name: centos-stream-9 - - name: debian-11 - name: debian-12 - name: fedora-latest - name: rockylinux-8 @@ -29,17 +29,19 @@ platforms: suites: - name: resource - run_list: - - recipe[test::default] + provisioner: + named_run_list: default - name: resource_community - run_list: - - recipe[test::community] + provisioner: + named_run_list: community excludes: - ubuntu-18.04 + - ubuntu-20.04 - amazonlinux-2023 + - fedora-latest - name: resource_peclchannel - run_list: - - recipe[test::default] + provisioner: + named_run_list: default attributes: pecl_method: channel verifier: diff --git a/resources/fpm_pool.rb b/resources/fpm_pool.rb index b1d4f81db..fc86b75d1 100644 --- a/resources/fpm_pool.rb +++ b/resources/fpm_pool.rb @@ -105,13 +105,12 @@ def install_fpm_package raise 'PHP-FPM package not found (you probably have an unsupported distro)' if new_resource.fpm_package.nil? - file new_resource.default_conf do - action :nothing - end - package new_resource.fpm_package do action :install - notifies :delete, "file[#{new_resource.default_conf}]", :immediately + end + + file new_resource.default_conf do + action :delete end end diff --git a/resources/pear.rb b/resources/pear.rb index e00127acf..a82e0ecd0 100644 --- a/resources/pear.rb +++ b/resources/pear.rb @@ -76,17 +76,14 @@ def grep_for_version(stdout, package) end action :install do - build_essential + install_build_dependencies # If we specified a version, and it's not the current version, move to the specified version unless new_resource.version.nil? || new_resource.version == current_resource.version install_version = new_resource.version end - # Check if the version we want is already installed - versions_match = candidate_version == current_installed_version(new_resource) - # If it's not installed at all or an upgrade, install it - if install_version || new_resource.version.nil? && !versions_match + if install_version || new_resource.version.nil? && current_resource.version.nil? converge_by("install package #{new_resource.package_name} #{install_version}") do info_output = "Installing #{new_resource.package_name}" info_output << " version #{install_version}" if install_version && !install_version.empty? @@ -98,7 +95,7 @@ def grep_for_version(stdout, package) # reinstall is just an install that always fires action :reinstall do - build_essential + install_build_dependencies install_version = new_resource.version unless new_resource.version.nil? converge_by("reinstall package #{new_resource.package_name} #{install_version}") do @@ -136,6 +133,16 @@ def grep_for_version(stdout, package) end action_class do + def install_build_dependencies + if platform?('fedora') + package 'Install PEAR build dependencies' do + package_name %w(autoconf bison ca-certificates flex gcc gcc-c++ gettext make m4 ncurses-devel patch) + end + else + build_essential + end + end + def expand_options(options) options ? " #{options}" : '' end @@ -219,11 +226,7 @@ def prefix_channel(channel) end def removing_package? - if new_resource.version.nil? - true # remove any version of a package - else - new_resource.version == @current_resource.version # we don't have the version we want to remove - end + new_resource.version.nil? || new_resource.version == @current_resource.version end def extension_dir @@ -273,7 +276,7 @@ def pecl? def manage_pecl_ini(name, action, directives, zend_extensions, priority) ext_prefix = extension_dir - ext_prefix << ::File::SEPARATOR if ext_prefix.last.chr != ::File::SEPARATOR + ext_prefix << ::File::SEPARATOR unless ext_prefix.end_with?(::File::SEPARATOR) files = get_extension_files(name) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 773d55795..387442c3b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,5 @@ require 'chefspec' -require 'chefspec/berkshelf' +require 'chefspec/policyfile' RSpec.configure do |config| config.color = true # Use color in STDOUT diff --git a/test/cookbooks/test/recipes/community.rb b/test/cookbooks/test/recipes/community.rb index 02775a959..5295c3805 100644 --- a/test/cookbooks/test/recipes/community.rb +++ b/test/cookbooks/test/recipes/community.rb @@ -9,13 +9,39 @@ # Start of the old community_package recipe --- if platform_family?('rhel', 'fedora') + if platform?('fedora') + Chef::Log.fatal 'Skipping run - Fedora Remi packages do not provide the php8.2 package set used by this community test' + return + end + + if platform_version.to_i >= 9 + node.default['yum-remi-chef']['gpgkey'] = %w( + https://rpms.remirepo.net/RPM-GPG-KEY-remi + https://rpms.remirepo.net/RPM-GPG-KEY-remi2017 + https://rpms.remirepo.net/RPM-GPG-KEY-remi2018 + https://rpms.remirepo.net/RPM-GPG-KEY-remi2019 + https://rpms.remirepo.net/RPM-GPG-KEY-remi2020 + https://rpms.remirepo.net/RPM-GPG-KEY-remi2021 + https://rpms.remirepo.net/RPM-GPG-KEY-remi2022 + https://rpms.remirepo.net/RPM-GPG-KEY-remi2023 + https://rpms.remirepo.net/RPM-GPG-KEY-remi2024 + https://rpms.remirepo.net/RPM-GPG-KEY-remi2025 + https://rpms.remirepo.net/RPM-GPG-KEY-remi2026 + ) + end + include_recipe 'yum-remi-chef::remi' elsif platform?('ubuntu') - # ondrej no longer supports Ubuntu <20.04 - if platform_version.to_i < 20 - Chef::Log.fatal 'Skipping run - Ubuntu <20.04 is not supported by the ondrej ppa' + # ondrej no longer supports Ubuntu <22.04 for the PHP 8.2 packages used here. + if platform_version.to_i < 22 + Chef::Log.fatal 'Skipping run - Ubuntu <22.04 does not provide the php8.2 package set used by this community test' return end + + directory '/etc/apt/keyrings' do + recursive true + end + include_recipe 'ondrej_ppa_ubuntu' elsif platform?('debian') # use sury repo for debian (https://deb.sury.org/) diff --git a/test/cookbooks/test/recipes/default.rb b/test/cookbooks/test/recipes/default.rb index 036587b66..b9e791354 100644 --- a/test/cookbooks/test/recipes/default.rb +++ b/test/cookbooks/test/recipes/default.rb @@ -18,11 +18,15 @@ action :update end -# Install https://pecl.php.net/package/sync -pecl_method = node['pecl_method'] || 'binary' -php_pear "sync-#{pecl_method}" do - package_name 'sync' - binary 'pecl' if pecl_method == 'binary' - channel 'pecl.php.net' if pecl_method == 'channel' - priority '50' +if platform?('fedora') + Chef::Log.warn 'Skipping PECL sync on Fedora: sync 1.1.3 does not build against Fedora latest PHP 8.5 headers' +else + # Install https://pecl.php.net/package/sync + pecl_method = node['pecl_method'] || 'binary' + php_pear "sync-#{pecl_method}" do + package_name 'sync' + binary 'pecl' if pecl_method == 'binary' + channel 'pecl.php.net' if pecl_method == 'channel' + priority '50' + end end diff --git a/test/integration/resource/inspec/php_spec.rb b/test/integration/resource/inspec/php_spec.rb index 53876a28a..ea17ac350 100644 --- a/test/integration/resource/inspec/php_spec.rb +++ b/test/integration/resource/inspec/php_spec.rb @@ -7,8 +7,10 @@ its('stdout') { should match(/pecl\.php\.net/) } end -describe command('php --ri sync') do - its('exit_status') { should eq 0 } +unless os[:family] == 'fedora' + describe command('php --ri sync') do + its('exit_status') { should eq 0 } + end end unless os[:family] == 'redhat' || os[:family] == 'fedora'