Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

What is the best practice to migrate scripts from test to production

by Anonymous Monk
on Jun 27, 2007 at 13:53 UTC ( [id://623625]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I have written some scripts and have tested succcessfully in the 'test' environment. I am not sure what is the best approach to migrate them from 'test' to 'production' environment.

The scripts start as follows:

#! /usr/local/perl -wT use strict; use warnings; # look for additional modules # (I have the .pm files for the test environment in this path) use lib '/path/to/modules/testenvir/'; # logic follows.. ... ...

Ideally, I would have liked to move (i.e. copy) the scripts from 'test' to 'production' environment without any changes but the problem I am having is that all the scripts have additional path to look for modules(i.e '/path/to/modules/testenvir/' ) .

If I migrate the scripts without any changes, then the 'production' environment would be using the modules in the 'test' environment, which isn't right. The other way is to change the lib path to point to '/path/to/modules/prodenvir/', but I have to modify all the scripts everytime I want to move something to production.

Is there a better way to handle this problem?

Replies are listed 'Best First'.
Re: What is the best practice to migrate scripts from test to production
by pemungkah (Priest) on Jun 27, 2007 at 19:34 UTC
    Try using a relative path instead of an absolute one. Your scripts will do this:
    use lib '../lib';
    so going to production involves pretty much a tar/untar operation; everything moves together, rather than separately. You might want to explicitly install any CPAN modules that you're using into your own lib/ directory to ensure that someone upgrading the system Perl doesn't mess you over by changing a module on you.

    If you wanted to make it even neater, symlink to the production version; to change versions, alter the symlink. Also makes it really easy to drop back to a previous version if necessary. In detail:

    1. Move your software foobar-v1.0 and symlink foobar to that. Your software runs out of foobar.
    2. Install your new version by untarring it at foobar-v1.1.
    3. Delete the symlink and symlink foobar-v1.1 to foobar. The new version is now running out of foobar.
    This works really nicely because you've just moved a single symlink; if you really have to fall back, you move the symlink and nothing else to revert.
Re: What is the best practice to migrate scripts from test to production
by greywolf (Priest) on Jun 27, 2007 at 18:42 UTC
    I like to use a text file in the directory where the script resides. Use this file to hold any path or variable information that would differ in test mode and production mode. The script can then read the text file in its current directory and get the info it needs.

    mr greywolf
Re: What is the best practice to migrate scripts from test to production
by wfsp (Abbot) on Jun 27, 2007 at 14:54 UTC
    I have a similar situation where I want to run the same cgi scripts locally and on the webhoster. This is what I've come up with.

    Perhaps something similar would be of use?

    #!/usr/bin/perl use strict; use warnings; my ($local, $root, $domain); BEGIN { $local++ if $ENV{HTTP_HOST} =~ m|localhost|; if ($local){ $root = q{/www/local}; } else{ $root = q{/path/on/webhoster/htdocs}; } $domain = q{sw/admin}; } use lib ( qq{$root/lib}, qq{$root/$domain/lib}, ); use Article; # rest of script...
    update: changed the paths

      Thanks for the response

      Unfortunately, I can't use your approach as my "test" and "production" scripts are in the same server, but under different directories. Hence, "HTTP_HOST" returns the same value for both "test" and "production".

      But, I noticed that env variables, "REQUEST_URI" and "SCRIPT_FILENAME", has the "test" or "prod" string string attached to them (i.e, if the script name is test.cgi, the REQUEST_URI string has a value of "/testenvir/test.cgi" in 'test' environment and "/prodenvir/test.cgi" in 'prod' environment, respectively).

      I am going to check if I can use your logic with the above ENV variable(s).

      Is that a good approach?

      Thanks,Vgn

        Rather than having an extra conditional in your code, you might read the path from the environment.

        ...roboticus

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://623625]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-28 14:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found