按照以下过程在代理服务器中运行软件包管理器和其他工具。
要在代理服务器中运行一个工具,如程序包管理器,请执行以下操作:
-
通过将语句添加到您的
squid.conf
文件中,将该工具添加到代理服务器的允许列表中。 -
在 buildspec 文件中添加指向代理服务器的私有终端节点的命令行。
以下示例演示了如何为 apt-get
、curl
和 maven
执行此操作。如果您使用其他工具,则相同的原则将适用。将它添加到 squid.conf
文件中的允许列表中,并向 buildspec 文件添加一个命令以使 CodeBuild 了解您的代理服务器的端点。
在代理服务器中运行 apt-get
-
将以下语句添加到您的
squid.conf
文件中,以便将apt-get
添加到代理服务器中的允许列表。前三行允许apt-get
在构建环境中运行。acl allowed_sites dstdomain ppa.launchpad.net # Required for apt-get to run in the build environment acl apt_get dstdom_regex .*\.launchpad.net # Required for CodeBuild to run apt-get in the build environment acl apt_get dstdom_regex .*\.ubuntu.com # Required for CodeBuild to run apt-get in the build environment http_access allow localnet allowed_sites http_access allow localnet apt_get
-
在构建规范文件中添加以下语句,以便
apt-get
命令在/etc/apt/apt.conf.d/00proxy
中查找代理配置。echo 'Acquire::http::Proxy "http://
<private-ip-of-proxy-server>
:3128"; Acquire::https::Proxy "http://<private-ip-of-proxy-server>
:3128"; Acquire::ftp::Proxy "http://<private-ip-of-proxy-server>
:3128";' > /etc/apt/apt.conf.d/00proxy
在代理服务器中运行 curl
-
将以下内容添加到您的
squid.conf
文件中,以便将curl
添加到构建环境中的允许列表。acl allowed_sites dstdomain ppa.launchpad.net # Required to run apt-get in the build environment acl allowed_sites dstdomain google.com # Required for access to a webiste. This example uses www.google.com. http_access allow localnet allowed_sites http_access allow localnet apt_get
-
在 buildspec 文件中添加以下语句,以便
curl
使用专用代理服务器访问您添加到squid.conf
的网站。在此示例中,网站为google.com
。curl -x
<private-ip-of-proxy-server>
:3128 https://www.google.com
在代理服务器中运行 maven
-
将以下内容添加到您的
squid.conf
文件中,以便将maven
添加到构建环境中的允许列表。acl allowed_sites dstdomain ppa.launchpad.net # Required to run apt-get in the build environment acl maven dstdom_regex .*\.maven.org # Allows access to the maven repository in the build environment http_access allow localnet allowed_sites http_access allow localnet maven
-
在 buildspec 文件中添加以下语句。
maven clean install -DproxySet=true -DproxyHost=
<private-ip-of-proxy-server>
-DproxyPort=3128