【问题标题】:How to cache the downloaded packages of the apt-get in travis?如何在travis中缓存apt-get的下载包?
【发布时间】:2020-05-22 00:47:09
【问题描述】:

我正在使用travis-ci 来测试我的github 存储库,我发现310 分钟用于下载deb 包。他们只是127 MB大。

我检查了travis-ci/Caching Dependencies and Directories ,但不支持apt-get

如何做到这一点?

【问题讨论】:

    标签: caching travis-ci apt-get


    【解决方案1】:

    可以通过将内容缓存到非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.
    

    【讨论】:

      【解决方案2】:

      在我看来,这不是推荐的做法。 根据official documentation

      安装速度快但下载速度慢的大文件不会 从缓存中受益,因为它们需要很长时间才能从缓存中下载 来自原始来源:

      • Debian 软件包

      【讨论】:

        猜你喜欢
        • 2023-03-31
        • 2019-07-30
        • 1970-01-01
        • 2020-06-07
        • 2021-04-29
        • 2011-05-24
        • 1970-01-01
        • 1970-01-01
        • 2012-05-07
        相关资源
        最近更新 更多