Dependency archiving for airgapped network

爷,独闯天下 提交于 2021-02-08 09:24:11

问题


I am trying to use Bazel in a network which is not connected to the internet. Even without using any special libraries, Bazel still needs to download some dependencies via HTTP.

I was advised to try and set up an HTTP proxy server which will cache the files which Bazel downloads, and then transfer the proxy server along with its cache into our isolated network.

In order for this to work, I need to be able to operate the proxy in two modes:

  1. When creating the cache, the proxy caches all requests from Bazel, and never discards any of the files.
  2. When using the cache within the network, the proxy never tries to cache any additional files, serves the existing files in the cache and never discards them.

I looked at nginx in order to achieve this, but could not find any option to prevent files in the cache from being discarded.

Is there any way to do this in nginx? If not is there a proxy which suites my use case? Or maybe there's another alternative solution which I haven't considered?


回答1:


You can use the --distdir distribution directory in your airgapped environment. This distribution directory should contain the implicit dependencies of the Bazel binary you're invoking.

To build these dependencies outside of your airgapped environment, first checkout the Bazel source tree at the right version:

git clone https://github.com/bazelbuild/bazel "$BAZEL_DIR"
cd "$BAZEL_DIR"
git checkout "$BAZEL_VERSION"

Then, build the tarball containing the implicit runtime dependencies for that specific Bazel version:

bazel build @additional_distfiles//:archives.tar

Export this tarball to a directory that can be copied into your airgapped environment. Note the --strip-components flag, because --distdir can be quite finicky with the directory nesting level:

tar xvf bazel-bin/external/additional_distfiles/archives.tar -C "$NEW_DIRECTORY" --strip-components=3

Finally, when you use Bazel in your airgapped environment, pass the --distdir flag pointing to the directory. I suggest adding it as an .bazelrc entry:

build --distdir=path/to/directory


来源:https://stackoverflow.com/questions/61820038/dependency-archiving-for-airgapped-network

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!