如何使用 cpanm 为离线服务器捆绑模块

How to bundle modules for an offline server with cpanm

我想 cpanm SomeModule 安装 SomeModule 以及大约 10 个依赖项,但目标服务器无法访问互联网。我确实有一台非常相似的开发机器(相同的 Perl 环境,相同的 Perl 版本),cpanm 可以下载它的源模块。

看了cpanm的man page,感觉可以在开发机上制作一个tarball,传到服务器端,用它一次性安装模块。

不幸的是,我似乎没有找到确切的组合。特别是,由于在开发机器上已经安装了模块,我需要强制它仍然将所有依赖项添加到 tarball(当然不包括核心模块)。

有人可以给出开发机器和目标机器的命令吗?

编辑:这是关于 cpanm 的。当然,如果你能权威地说cpanm绝对不可能,那也是一个有效的答案......

编辑:到目前为止的评论和答案建议使用 pintominicpan 来创建一组 CPAN 模块源。这很好用(尤其是 pinto 用于此非常简单)。我现在使用 pinto 来解决我当前的问题,但 Pinto 本身仍然有 lot 的先决条件模块(与 Perl-Core 相比 >100)。我对这个问题的希望是 cpanm,它是一个独立的、无需安装的脚本,可以自己完成(它有广泛的选项,听起来他们可以朝那个方向发展)。这对于在没有大量开销的情况下引导 Perl 安装会很好。

您可以从 CPAN 或 metacpan 手动下载所有依赖项的 tars,然后复制它们并按正确的顺序一一安装。对于十个模块来说,这是一些工作,但还算不错。你可以写个脚本。

但您也可以使用 minicpan 创建一个只包含您需要的内容的本地小型 CPAN。拥有部分或全部 CPAN 的本地副本非常好,例如当您在飞行中破解代码时需要安装模块时,在 USB 驱动器上。它本质上是一个包含更多目录和 tars 的目录。你可以只选择你需要的东西,压缩它,将它移动到你的生产服务器,在那里解压它并告诉 cpanm 从本地 CPAN 镜像安装。

您可以使用 Carton to bundle the dependencies locally (on your machine with internet access) and then use either Carton itself to install the bundled distributions, or use cpanm 本身并指定包位置。

你需要 carton 1.0.32 (to generate the package index) and cpanm 1.7016(对于 --from 选项)才能工作。

在你的发行版的根目录下,你可以做

$ carton install # will install the dependencies in `local`
$ carton bundle  # will cache the dependencies in `vendor`
$ tree vendor/
vendor/
└── cache
    ├── authors
    │   └── id
    │       └── F
    │           └── FO
    │               └── FOOBAR
    │                   ├── Some-Dist-1.337.tar.gz
    │                   └── Another-Dist-0.001001.tar.gz
    └── modules
        └── 02packages.details.txt.gz

稍后,将其传输到您的另一台气隙机器后,您可以使用 carton:

$ carton install --cached
$ carton exec scripts/your-script.pl

或者直接用cpanm安装

# To emulate carton:
$ cpanm -L local --from "$PWD/vendor/cache" --installdeps --notest --quiet .
# Or to install globally:
$ cpanm --from "$PWD/vendor/cache" .