Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

chef cpan cookbook

by melezhik (Acolyte)
on Mar 25, 2013 at 11:22 UTC ( #1025272=perlnews: print w/ replies, xml ) Need Help??


In this post I want to share my chef cookbook called cpan.
Chef is the modern platform for deploy automation and configuration.
One of chef great feature - one may create custom recipes to deploy/configure
specific applications, written on any languages. When I first met with chef,
I had already had some experience on deploying perl applications. I used standard build cycle:

perl Build.PL ./Build ./Build installdeps ./Build test ./Build install
So the idea of integrating perl application install come into my mind in natural way. With cpan cookbook one may do standard perl build/test/install idioms using chef. Here I am putting some use cases, just to give some sense of what it is. If you like it, you may learn more on http://community.opscode.com/cookbooks/cpan.
Cpan cookbook use cases
Installing application, distributed with tar-ball. Let's say you have already fetch and store tar-ball with
others chef resources (the following code is self-explanatory). So you may easily install it into given install base:

remote_file '/tmp/app-0.0.1.tag.gz' source 'http://local.server/app-0.0.1.tag.gz' end execute 'cd /tmp/ && tar -xzf app.tag.gz' cpan_client 'my application' do user 'root' group 'root' install_type 'application' action 'install' install_base '/path/to/your/application/home' cwd '/tmp/app-0.0.1' end
The same thing with your perl5lib paths taking into account ('/home/user/alex/perl5lib/'):
cpan_client 'my application' do user 'root' group 'root' install_type 'application' action 'install' install_base '/path/to/your/application/home' cwd '/tmp/app-0.0.1' inc %w{ /home/user/alex/perl5lib/ } end
If you need just installing arbitrary cpan module, here some examples to start. Install by given link:
cpan_client "http://search.cpan.org/CPAN/authors/id/M/MA/MARKSTOS/CGI. +pm-3.59.tar.gz" do user 'root' group 'root' module_name 'CGI' action 'install' end
Or just rely on your cpan mirrors:
cpan_client 'CGI' do user 'root' group 'root' install_type 'cpan_module' action 'install' end
With cpan cookbooks you may even play with version requirements. Require minimal version:
cpan_client 'CGI' do user 'root' group 'root' version '3.55' install_type 'cpan_module' action 'install' end
Do not install if already installed:
cpan_client 'CGI' do user 'root' group 'root' version '0' install_type 'cpan_module' action 'install' end
Try to upgrade to highest possible version:
cpan_client 'CGI' do user 'root' group 'root' install_type 'cpan_module' action 'install' end
If you install by distributive, you may even require concrete version:
cpan_client 'http://search.cpan.org/CPAN/authors/id/M/MA/MARKSTOS/CGI. +pm-3.59.tar.gz' do user 'root' group 'root' module_name 'CGI' version '=3.59' action 'install' end
Other examples to check out is on http://community.opscode.com/cookbooks/cpan.

Comment on chef cpan cookbook
Select or Download Code
Re: chef cpan cookbook
by Tux (Monsignor) on Mar 25, 2013 at 16:04 UTC

    Did you know about distroprefs (also being referred to as cpanprefs)?


    Enjoy, Have FUN! H.Merijn
      If to say about inner layout - mostly CPAN::Shell interface is used. I do not know why should I use CPAN::Distroprefs ? Just give me a hint ((: ...

        These are just examples that I. use. There are more example here,

        In your $HOME/.cpan/prefs you can hold .yml files that describe how cpan should act on the distributions describes in the YAML file, which includes answering questions asked by Makefile.PL or Build.PL. You can make sections specific for os, so these preferences can be shipped portable across OS's. These files can also refer to patches that you want to apply to the modules (for various reasons). These patches are usually stored in $HOME/.cpan/patches.

        $ cat ~/.cpan/patches/XML-Twig.patch --- tools/xml_pp/xml_pp 2010-10-29 13:30:38.000000000 +0200 +++ tools/xml_pp/xml_pp 2010-10-29 13:30:49.000000000 +0200 @@ -10,7 +10,7 @@ my @styles= XML::Twig->_pretty_print_sty my $styles= join '|', @styles; # for usage my %styles= map { $_ => 1} @styles; # to check option -my $DEFAULT_STYLE= 'indented'; +my $DEFAULT_STYLE= 'indented_close_tag'; my $USAGE= "usage: $0 [-v] [-i<extension>] [-s ($styles)] [-p <tag(s) +>] [-e <encoding>] [-l] [-f <file>] [<files>]"; $ cat ~/.cpan/prefs/MIROD.XML-Twig.yml --- match: distribution: "^MIROD/XML-Twig-" pl: expect: - "Do you want to install 'xml_pp'" - "y\n" - "Do you want to install 'xml_grep'" - "y\n" - "Do you want to install 'xml_split'" - "y\n" - "Do you want to install 'xml_merge'" - "y\n" - "Do you want to install 'xml_spellcheck'" - "y\n" depends: requires: Test::Pod::Coverage: 0 patches: - "../../patches/XML-Twig.patch" $ cat ~/.cpan/prefs/NANIS.Crypt-SSLeay.yml --- match: distribution: "^(DLAND|NANIS)/Crypt-SSLeay-" perlconfig: osname: "linux" pl: eexpect: mode: anyorder talk: - "Which OpenSSL build path" - "\n" - "Which SSL install path" - "\n" - "Do you want to run the live tests" - "n\n" --- match: distribution: "^(DLAND|NANIS)/Crypt-SSLeay-" perlconfig: osname: "hpux" pl: eexpect: mode: anyorder talk: - "Which OpenSSL build path" - "\n" - "Which SSL install path" - "/usr/local/ssl\n" - "Do you want to run the live tests" - "n\n" $

        Enjoy, Have FUN! H.Merijn
        /div

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlnews [id://1025272]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2014-10-20 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (74 votes), past polls