部署具有 CPAN 依赖项的内部 Perl 应用程序的防弹方法是什么?



首先,后台信息:

  • 所有服务器都在我们的控制之下
  • 所有Perl都完全相同(最新的Strawberry Perl)
  • 所有目标计算机都具有类似的操作系统配置(Windows Server 20XX)
  • 没有任何目标计算机连接到internet
  • IIS下运行的旧版CGI web应用程序
  • 在自己的机器上开发的小型开发团队
  • 持续集成环境

我最初的想法是使用Carton,但考虑到我们可以完全控制整个过程,这可能有些过头了。我们可以在CI服务器上运行一个carton bundle,然后在每个目标服务器上运行carton install --cached --deployment。这似乎是可行的,但随后我们必须将每个文件修改为use lib(或设置一个PERL5LIB环境变量,但这一点首先违背了使用Carton的目的)。

我并不反对修改Perl系统,因为正如我所说,这些是我们的服务器,我们可以完全控制它们。我也不会反对将已安装的模块与应用程序捆绑在一起的其他方法。即使是XS模块也不会造成问题,因为体系结构和Perls都是一样的。我只想能够使用CPAN中的模块,并让它在部署时、每次都能工作。

我错过了什么?

我有一个完全自动化的IIS、Strawberry Perl、CPAN模块+应用程序安装。这是cpan的一部分。

它将所有cpan命令写入一个文本文件,然后以此作为参数调用cpan。

以两种模式运行它,要么用最新下载(或ed版本下载)训练主安装,要么用主安装的副本强制本地(无网络)安装。

希望它能对有所帮助

set cpan_notest=
@IF '%skip_cpan_test%' NEQ '' GOTO SKIPPED_SKIP_CPAN_TEST
    set cpan_notest=
:SKIPPED_SKIP_CPAN_TEST
@IF '%skip_cpan%' NEQ '' GOTO SKIPPED_CPAN
    @echo EasyRisk install: CPAN starting
    @REM some modules do ask questions about things (XML::Twig)
    @set PERL_MM_USE_DEFAULT=1
    @REM for CPAN to work, Perl must be in the path
    @REM but local environment (for this .cmd) is not updated when perl is installed
    @REM Need to fetch from registry and set it from a CALL'ed .cmd-file 
    @REM (looks like only way to do it, sorry)
    @echo.
    @echo Updating local path with ref to perl bin
    @echo Local path was:  %PATH%
    @"%local-perl-path-bin%Perl.exe" Utilsupdate_path.pl > Utilsupdate_path.cmd
    @REM cpan is a batch-file, so use CALL. Otherwise it will end this script as well
    @call Utilsupdate_path.cmd > NUL
    @del Utilsupdate_path.cmd
    @echo.
    @echo Local path now:  %PATH%
    @echo.

    @set cpan-prefix=
    @set cpan-postfix=
    @REM some issues with testing  formbuilder on Perl 5.17+(modules works fine)
    @REM do not print errors, as the tests are wrong, but module considered ok. 
    @REM (the 2>&1 means send std error to std out, which is already grounded to NUL)
    @REM -f not strong enough, need to use 'force' from command-line (piped)
    @echo.
    @REM @echo Installing Perl Modules (CPAN), result is stored in logcpan_result.txt
    @REM Clear the install file, then fill it with list of needed modules
    @REM make sure we install only from local modules
    @echo.  >  cpan_cmd.txt
    @REM Set that we only want to use local cpan, and not get stuff from internet
    @echo o conf commit >>  cpan_cmd.txt
    @REM if we are not training the local cpan-directory, then force to use the local copy
    @REM If any modules added, then the minicpan must also be updated (trained)
    @REM after training, copy C:strawberrycpansources to <installkit>Utilsminicpan
    @IF '%train_cpan%' NEQ '' GOTO SKIPPED_CPAN_TRAIN_1
    @echo Transfering local copy of cpan perl modules (minicpan)
        @xcopy  /s /q /y /i Utilsminicpan "%local-perl-path%minicpan"
        @echo o conf auto_commit 0 >>  cpan_cmd.txt
        @echo o conf connect_to_internet_ok '' >>  cpan_cmd.txt
        @REM dont init, just use local @echo o conf init urllist >>  cpan_cmd.txt
        @REM Remove default cpan repositories
        @echo o conf urllist shift >>  cpan_cmd.txt
        @echo o conf urllist shift >>  cpan_cmd.txt
        @echo o conf urllist shift >>  cpan_cmd.txt
        @REM add our local first, and only
        @echo o conf urllist %local-minicpan-file% >>  cpan_cmd.txt
        @rem view it in the log (good for debug)
        @echo o conf urllist >>  cpan_cmd.txt

    :SKIPPED_CPAN_TRAIN_1
    @echo Building Cpan-install list
    @REM Version specific (example only)
    @REM echo install SAMV/Set-Object-1.28.tar.gz
    @REM version independent
    @REM echo install Set::Object

    @echo %cpan_notest%  install Test::More Devel::CheckOS Pod::Coverage Class::ISA   Test::Simple Devel::Symdump Test::Pod::Coverage Pod::Coverage Test::Pod  Test::Compile YAML Data::Inherited Data::Comparable Data::Compare Devel::CheckOS Text::Template HTML::Template CGI::FastTemplate FreezeThaw   %cpan-postfix% >>  cpan_cmd.txt
    @REM Error in tests, (module works fine), but tests fails in 5.18, so use the force
    @echo force install CGI::Session CGI::Session::Driver::odbc CGI::FormBuilder %cpan-postfix% >>  cpan_cmd.txt


    @REM reset the config (as we did modify the list of urls)
    @echo o conf defaults >>  cpan_cmd.txt
    @echo exit >>  cpan_cmd.txt
    @REM now run the file with cpan, and remove it afterwards 
    @REM 2>&1 means redirect std err to std out (which goes to logcpan_result.log)
    @echo Installing CPAN modules (from minicpan), this may take a while
    @echo See progress in "%setup_dir%logcpan_result.log"
    @REM temporary cd to the Perl-bin folder to be sure 
    @REM cpan and Perl are run from same Perl version 
    @cd /D "%local-perl-path-bin%"
    @set cpan-start=%TIME%
    @type "%setup_dir%cpan_cmd.txt" | cpan > "%setup_dir%logcpan_result.log" 2>&1
    @set cpan-end=%TIME%
    @cd /D %setup_dir%
    @REM @del cpan_cmd.txt
    @echo 'EasyRisk install: Cpan done'
    @IF '%do_pause%' NEQ '' pause 
:SKIPPED_CPAN

相关内容

最新更新