Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix version handling for remi repo #510

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Rathios
Copy link

@Rathios Rathios commented Mar 9, 2019

Pull Request (PR) description

  • Cleans up and fixes version handling when installing PHP using the remi repo on CentOS/RHEL. Tested on CentOS 7.
  • Also adds beaker-vagrant to gemfile (see details in commit message for why)

Note: This changes the default version string of $php::globals::globals_php_version from 5.x to 5.6 on non-Debian/Ubuntu because we really should use sane version strings in such variables so we can re-use them elsewhere (like in php::repo::redhat for remi repo). I anticipate the versioning in php::globals will be cleaned up eventually. (I'll volunteer too.) It doesn't look like this change will have any adverse effects.

If merged, this PR obsoletes the following PRs: (Sorry, I'm impatient and they don't look like they're going anywhere)

This Pull Request (PR) fixes the following issues

Fixes #480

@Rathios
Copy link
Author

Rathios commented Mar 9, 2019

There's some weird stuff going on with $php::globals::globals_php_version wanting to set invalid default versions (like 5.x). It probably wasn't intended to be used outside of the class, but there is no other mechanism to rely on to follow the default version behavior (DRY). I'm not sure what to do about that. Ideally, clean up the entire class, perhaps. All of the PHP versions up to and including 7.0 are end of life (except RHEL's supported backports ...).

@bastelfreak bastelfreak added bug Something isn't working tests-fail labels Mar 10, 2019
@bastelfreak
Copy link
Member

Hi @Rathiosl thanks for providing this PR. Can you please add acceptance tests for the change to use the remi repository? Are you interested in cleaning up the class (probably in a seperate PR)? Since PHP 5.6 is EOL we could probably remove all this legacy code.

@Rathios
Copy link
Author

Rathios commented Mar 10, 2019

I wouldn't mind cleaning stuff up. I'd argue I'm pretty good at that.

Getting started with acceptance testing using CONTRIBUTING.md, and I've run into some problems:

$ bundle install --path .vendor/ --with system_tests --without development release
$ BEAKER_set=archlinux-2-x64 bundle exec rake acceptance
...
Beaker::Hypervisor, found some vagrant boxes to create

An error occurred while loading ./spec/acceptance/php56_spec.rb.
Failure/Error: require 'beaker-rspec'
LoadError:
  cannot load such file -- beaker/hypervisor/vagrant
$ gem list | grep beaker
(plenty of beaker gems, but no beaker-vagrant - beaker is v 4.6.0)

Over at beaker-vagrant I find: As of Beaker 4.0, all hypervisor and DSL extension libraries have been removed and are no longer dependencies. In order to use a specific hypervisor or DSL extension library in your project, you will need to include them alongside Beaker in your Gemfile or project.gemspec.

Couple questions:

  1. I'm assuming the Gemfile is missing some stuff? Would be good to get that sorted so it will be easier for starters (like me) to get up and running.
  2. In spec/acceptance/nodesets (ignoring ec2) there is only an archlinux-2-x64.yml. This needs to be tested on CentOS or RHEL. Should that come in via modulesync, do I just add a file, or do I test it some other way?

Edit:
ec2 doesn't work out of the box either, I'd assume because of the same.

$ BEAKER_set=ec2/rhel-73-x64 bundle exec rake acceptance
Beaker::Hypervisor, found some ec2 boxes to create

An error occurred while loading ./spec/acceptance/php56_spec.rb.
Failure/Error: require 'beaker-rspec'
LoadError:
  cannot load such file -- beaker/hypervisor/ec2

@bastelfreak
Copy link
Member

Hi. For most tests we generate the nodesets on the fly with beaker hostgenerator. Also on travis and locally we use the docker backend and not vagrant. You can take a look at the .travis.yml for some examples:

puppet-php/.travis.yml

Lines 26 to 27 in 64bbc0b

env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker CHECK=beaker
script: bundle exec rspec spec/acceptance/php56_spec.rb

so the command to test Ubuntu with docker would be:

PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker bundle exec rspec spec/acceptance/php56_spec.rb
PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker bundle exec rspec spec/acceptance/php_spec.rb

Or for CentOS 7:

PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker bundle exec rspec spec/acceptance/php56_spec.rb
PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker bundle exec rspec spec/acceptance/php_spec.rb

If you want to use vagrant, you need to add the beaker-vagrant gem to the Gemfile. I should probably do this for all Gemfiles we have...

The vagrant command should be (I don't have Vagrant by hand to verify this):

PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=vagrant bundle exec rspec spec/acceptance/php56_spec.rb
PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=vagrant bundle exec rspec spec/acceptance/php_spec.rb

Sorry for the trouble. I will update our Gemfiles later. Let me know if you've furthe questions.

CONTRIBUTING.md contains instructions for how to run acceptance tests
using vagrant, but Beaker v4+ has removed dependencies on Beaker
hypervisor gems. We have to install them via Gemfile in each module
now. This should make it easier for newbies to get started with
acceptance testing as well. Especially in environments like WSL
on Win10 where it's much easier to get Vagrant working with VirtualBox
than getting a Docker environment running.
@Rathios
Copy link
Author

Rathios commented Mar 11, 2019

@bastelfreak Thanks! That helped me get things sorted out. Much appreciated. :)

This should be ready for merge now, if everything looks okay.

Copy link
Member

@towo towo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me from a syntactical and logical POV, cannot vouchsafe functionality, though. :)

@minorOffense
Copy link
Contributor

Just wanted to chime in and see if what we wrote a while ago may be of use. We found (at least at the time) we had to fix a few things when switching from the stock php repo to remi.

  1. There were other dependencies that were needed so we had to add his base repo along with the php repo
  2. The php configuration files are named slightly different (especially with pecl prefixed stuff) so we had to add a cleanup script to remove those files from php.d. Wasn’t the cleanest solution but it worked.

We wrapped our php class around this module’s stuff so not everything here may be necessary anymore but I wanted to share in case any of that might still be needed.

class coldfront::php {
  include ::php

  $version = lookup('php::upgrade', {value_type => String, default_value => '56'})

  if $version != 'default' {
    class {"coldfront::php::phpupdate":
      version => $version,
    }
  }

  $php_extensions = lookup("php::extensions", {value_type => Hash, merge => 'deep', default_value => {}})

  $php_config_root_ini = pick_default($::php::config_root_ini, $::php::params::config_root_ini)

  # Create the certs
  $php_extensions.each |$key, $value| {

    # Get the extension name.
    # @see https://github.com/voxpupuli/puppet-php/blob/master/manifests/extension.pp#L65
    if (!empty($value['so_name'])) {
      $ext_name = downcase($value['so_name'])
    }
    else {
      $ext_name = downcase($key)
    }

    # Check for the ini prefix.
    if (!empty($value['ini_prefix'])) {
      $ini_prefix = $value['ini_prefix']
    }
    else {
      $ini_prefix = ''
    }

    exec {"php-conf-clean-${$key}":
      cwd => $php_config_root_ini,
      command => "find . -type f \( -name '*-${ext_name}.ini' -o -name '${ext_name}.ini' \) ! -name '${ini_prefix}${ext_name}.ini' -delete",
      onlyif => "test \$(find . -type f \( -name '*-${ext_name}.ini' -o -name '${ext_name}.ini' \) ! -name '${ini_prefix}${ext_name}.ini' | wc -l) -ne 0",
      path => ['/bin', '/usr/bin'],
      require => Class['::php'],
    }
  }

  # Install the right apache module for PHP if required.
  $classes = lookup('classes', {value_type => Array, default_value => []})

  if 'coldfront::role::webserver::apache' in $classes {
    # Fix some ordering issues with puppet. It could be that
    # coldfront::role::webserver::apache hasn't been applied yet.
    # Ensure it is.
    require coldfront::role::webserver::apache

    class { 'apache::mod::php':
      php_version  => $version[0],
    }
  }
}

class coldfront::php::composer {
  class {"::composer":
    auto_update => true,
    build_deps => false,
    require => [Class['coldfront::php'], Class['::php']],
  }
}

class coldfront::php::phpupdate (
  $version = '56',
) {
  # @todo add regex calidation on $version variable (always two digits).
  if $::osfamily == 'redhat' {
    # @see https://github.com/voxpupuli/puppet-php/blob/master/manifests/repo/redhat.pp#L13
    $releasever = $facts['os']['name'] ? {
      /(?i:Amazon)/ => '6',
      default       => '$releasever',  # Yum var
    }

    yumrepo { 'remi':
      descr      => 'Remi\'s RPM repository for Enterprise Linux $releasever - $basearch',
      mirrorlist => "https://rpms.remirepo.net/enterprise/${releasever}/remi/mirror",
      enabled    => 1,
      gpgcheck   => 1,
      gpgkey     => 'https://rpms.remirepo.net/RPM-GPG-KEY-remi',
      priority   => 1,
    }

    yumrepo { "remi-php${version}":
      descr      => 'Remi\'s PHP RPM repository for Enterprise Linux',
      mirrorlist => "https://rpms.remirepo.net/enterprise/${releasever}/php${version}/mirror",
      enabled    => 1,
      gpgcheck   => 1,
      gpgkey     => 'https://rpms.remirepo.net/RPM-GPG-KEY-remi',
      priority   => 1,
      before     => Class['::php'],
      require    => Yumrepo['remi'],
    }
  }
}

@vox-pupuli-tasks
Copy link

Dear @Rathios, thanks for the PR!

This is Vox Pupuli Tasks, your friendly Vox Pupuli GitHub Bot. I noticed that your pull request contains merge conflict. Can you please rebase?

You can find my sourcecode at voxpupuli/vox-pupuli-tasks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working merge-conflicts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add PHP 7.x support for Enterprise Linux
4 participants