【发布时间】:2020-05-22 00:47:09
【问题描述】:
我正在使用travis-ci 来测试我的github 存储库,我发现3 到10 分钟用于下载deb 包。他们只是127 MB大。
我检查了travis-ci/Caching Dependencies and Directories
,但不支持apt-get。
如何做到这一点?
【问题讨论】:
我正在使用travis-ci 来测试我的github 存储库,我发现3 到10 分钟用于下载deb 包。他们只是127 MB大。
我检查了travis-ci/Caching Dependencies and Directories
,但不支持apt-get。
如何做到这一点?
【问题讨论】:
可以通过将内容缓存到非root用户可访问的另一个文件夹中来实现这一点,并将其下的mv所有deb缓存到/var/cache/apt/archives/中。安装后,cp他们回到那个文件夹。
注意:
我建议你在~ 下的某个地方创建YOUR_DIR_FOR_DEB_PACKAGES。
# .travis.yml
sudo: required
cache:
- directories:
- $YOUR_DIR_FOR_DEB_PACKAGES # This must be accessible for non-root users
addons:
apt:
sources:
# Whatever source you need
# Download the dependencies if it is not cached
# All the "echo" and "ls" in "before_script" can be remove since they are only used for debugging.
before_script:
- echo "Print content of $YOUR_DIR_FOR_DEB_PACKAGES"
- ls $YOUR_DIR_FOR_DEB_PACKAGES
- echo "Check whether apt-get has no cache"
- ls /var/cache/apt/archives
-
- echo "Start loading cache"
- |
exist() {
[ -e "$1" ]
}
- |
if exist ~/$YOUR_DIR_FOR_DEB_PACKAGES/*.deb
then
sudo mv ~/$YOUR_DIR_FOR_DEB_PACKAGES/*.deb /var/cache/apt/archives/
ls /var/cache/apt/archives
fi
-
- echo "Start to install software"
- sudo apt-get update
- sudo apt-get install -y --no-install-recommends --no-install-suggests $THE_PACKAGES_REQUIRED
-
- echo "Start updating the cache"
- cp /var/cache/apt/archives/*deb ~/$YOUR_DIR_FOR_DEB_PACKAGES/
script:
- # Do whatever you want here.
【讨论】:
在我看来,这不是推荐的做法。 根据official documentation
安装速度快但下载速度慢的大文件不会 从缓存中受益,因为它们需要很长时间才能从缓存中下载 来自原始来源:
- Debian 软件包
【讨论】: