Bitbucket Pipelines:如何查找apt-get安装包的缓存目录?
Bitbucket Pipeline 缓存apt-get安装包的解决方案
你遇到的问题根源在于:/var/cache/apt目录下,实际存放下载的deb安装包的子目录是/var/cache/apt/archives/,而默认情况下apt-get install执行完成后会自动清理这些下载的包,导致你缓存的目录里只有空配置文件,没有实际的包内容,所以才会出现仅缓存164字节的情况。
要解决这个问题,需要两步操作:
1. 配置APT保留下载的包
在执行apt-get install之前,添加命令让APT不要自动清理下载的deb包:
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
2. 调整缓存目录配置
把缓存目录从/var/cache/apt改成/var/cache/apt/archives(明确指定存放包的子目录,避免缓存无关文件),修改后的caches定义如下:
caches: install-php-extensions: /usr/local/bin/ phpunit: web-app/vendor/bin/ composer: /usr/local/bin # 调整为实际存放deb包的目录 apt-cache: /var/cache/apt/archives php-extensions: /usr/lib/php/ sonar: ~/.sonar
修改后的流水线关键步骤示例
Test步骤的apt安装部分
script: # 先配置APT保留下载包 - echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache # 再执行安装命令 - apt-get update && apt-get install -y curl unzip git # 后续其他步骤...
Deploy步骤的apt安装部分
script: # 同样先配置APT保留下载包 - echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache # 执行安装命令 - apt-get update && apt-get install -y unzip awscli # 后续其他步骤...
这样配置后,Bitbucket Pipeline会缓存下载的deb包,下次运行流水线时就无需重新下载这些包,能显著缩短apt安装环节的耗时。
内容的提问来源于stack exchange,提问作者Drew Gallagher
相关产品推荐
相关产品推荐

