Using Perl 5.24 Red Hat Software Collection
Red Hat Software Collection (RHSCL) 2.3 brings new rh-perl524 collection.
It includes Perl 5.24.0, which provides a number of bug fixes and enhancements over the previously released rh-perl520 Software Collection. The details about the changes can be found in 5.22.0 perldelta and 5.24.0 perldelta. The new collection adds package rh-perl524-perl-App-cpanminus, which contains the cpanm utility for getting, extracting, building, and installing modules from the Comprehensive Perl Archive Network (CPAN) repository.
RHSCL is distributed as a collection of RPM packages that can be installed, updated and uninstalled by using the standard package management tools or as a Docker image based on RHSCL.
Using collection of RPM packages
This way could be used on RHEL 6 and 7 systems
To start using Perl 5.24 RHSCL, we have to install the rh-perl524 as root:
# yum install rh-perl524
Now we can verify the Perl version:
# scl enable rh-perl524 'perl -v' This is perl 5, version 24, subversion 0 (v5.24.0)
Now we create a Perl program that can be run from the command line:
$ cat hello.pl #!/usr/bin/env perl print "Hello from Perl $^V\n"; $ chmod +x hello.pl
We can run the scripts by using scl enable:
$ scl enable rh-perl524 './hello.pl'
On the other hand, run shell session with a software collection as default and then run the script:
$ scl enable rh-perl524 bash ./hello
If we want to permanent enable a software collection in a development environment, then we add the following line to your ~/.bashrc:
# Add Perl 5.24 from RHSCL to my login environment source scl_source enable rh-perl524
After making the change, you should log out and log back in again.
If we want to find additional Perl packages in RHSCL, run:
$ yum list available rh-perl524-\*
You can also see Red Hat Software Collection for more details.
Using Perl 5.24 Docker image for deploying PSGI application
This way can be used only for RHEL 7 servers.
The basic idea is to combine the application code from Git tree and Red Hat’s rhscl/perl-524-rhel7 base image into an application image that will run the application in an environment. Your application can either be a simple Common Gateway Interface (CGI) script or a full-fledged Perl Web Server Gateway Interface (PSGI) application.
First, we have to install docker and start the service:
# yum install docker # systemctl start docker
Then we download the rhscl/perl-524-rhel7 Docker image:
# docker pull rhscl/perl-524-rhel7
Now we can verify that the base image really contains Perl 5.24:
# docker run --rm -ti rhscl/perl-524-rhel7 perl -v This is perl 5, version 24, subversion 0 (v5.24.0) built for x86_64-linux-thread-multi (with 29 registered patches, see perl -V for more detail) [...]
For creating the application image, we will use s2i. The tool is provided by the source-to-image package, so install it:
# yum install source-to-image
Then we will need git tool for creating application repository, so we will install it:
# yum install git
We will begin with an empty Git repository:
$ mkdir application $ cd application $ git init-db . Initialized empty Git repository in /root/application/.git/
As an example application, we download application.psgi, which provides simple form. We need to declare the application dependencies. We will use a cpanfile for that. cpanfile for this example is here:
If you haven’t yet configured your Git identity, you can do it now:
$ git config --global user.email "firstname.lastname@example.org" $ git config --global user.name "Developer"
Then commit the sources into Git tree:
$ git add application.psgi cpanfile $ git commit -m 'Simple application' [master (root-commit) 7d4cbc3] Simple application 2 files changed, 2 insertions(+) create mode 100644 application.psgi create mode 100644 cpanfile
Now we are ready to build our application image. The magic command to build an application from a base Docker image and a Git tree is:
# s2i build file://$PWD rhscl/perl-524-rhel7 application ---> Installing application source ... ---> PSGI application found in ./application.psgi ---> Installing modules from cpanfile ... [...] <== Installed dependencies for .. Finishing. 31 distributions installed
The second argument is a URL to the Git tree with your application. We used a current working directory in this example. But you can use any remote location. For example a repository on the GitHub. The third argument is base Docker image identifier. We used the Red Hat’s Perl 5.24 RHSCL image. The last argument is a tag for the resulting application image.
The application image was built successfully. And we can verify it in Docker images listing:
# docker images REPOSITORY TAG IMAGE ID CREATED SIZE application latest 75ec8cce098e 16 seconds ago 497.2 MB rhscl/perl-524-rhel7 latest 1c4d4f1b4d03 6 weeks ago 477 MB
Now, we can run the application:
# docker run --rm -ti application [Fri Jan 13 12:25:48.981151 2017] [so:warn] [pid 1] AH01574: module perl_module is already loaded, skipping AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
And the application will be available on the reported IP address and TCP port 8080. You can use docker’s option -p to publish the container’s port 8080 on a different external port number.
Finally, we can use a web browser to connect to the application and use it:
There is an example of building the test application from the public GitHub sti-perl repository, underneath the 2.4/test/psi/ directory:
# s2i build https://github.com/openshift/sti-perl.git --context-dir=5.24/test/psgi rhscl/perl-524-rhel7 perl-524-rhel7-psgi [...] ---> Installing application source ... ---> PSGI application found in ./application.psgi ---> Installing modules from cpanfile ... [...] <== Installed dependencies for .. Finishing. 44 distributions installed
The option –context-dir specifies sub-directory inside repository with application code.
You can see Using Red Hat Software Collections Container Images for more details.