如何在BitBucket管道上为apt-get启用/设置依赖项缓存 [英] How to enable / setup Dependency Caches for apt-get on BitBucket Pipelines

查看:73
本文介绍了如何在BitBucket管道上为apt-get启用/设置依赖项缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在bitbucket-pipelines.yml文件中使用以下代码将代码远程发送到登台服务器.

I am using the following code in my bitbucket-pipelines.yml files to remotely deply code to a staging server.

image: php:7.1.1

pipelines:
  default:
    - step:
        script:
          # install ssh
          - apt-get update && apt-get install -y openssh-client
          # get the latest code
          - ssh user@domain.com -F ~/.ssh/config "cd /path/to/code && git pull"
          # update composer
          - ssh user@domain.com -F ~/.ssh/config "cd /path/to/code && composer update --no-scripts"
          # optimise files
          - ssh user@domain.com -F ~/.ssh/config "cd /path/to/code && php artisan optimize"

这一切正常,除了每次运行管道时,都会下载ssh客户端并安装所有内容(使构建时间增加了约30秒).有什么办法可以缓存此步骤?

This all works, except that each time the pipeline is run, the ssh client is downloaded and installed everything (adding ~30 seconds to the build time). Is there way I can cache this step?

我该如何缓存apt-get步骤?

例如,是否可以进行类似的工作(或需要进行哪些更改才能进行以下工作):

For example, would something like this work (or what changes are needed to make the following work):

pipelines:
  default:
    - step:
        caches:
          - aptget
        script:
          - apt-get update && apt-get install -y openssh-client

definitions:
  caches:
    aptget: which ssh

推荐答案

这是一个典型的场景,您应该使用自己的Docker映像而不是Atlassian提供的映像之一. (或搜索提供此功能的Docker映像.)

This is a typical scenario where you should use your own Docker image instead of one of the ones provided by Atlassian. (Or search for a Docker image which provides exactly this.)

在您的简单情况下,此Dockerfile应该足够了:

In your simple case, this Dockerfile should be enough:

FROM php:7.1.1

RUN apt-get update && \
    apt-get install -y openssh-client

然后,创建一个DockerHub帐户,发布映像并在bitbucket-pipelines.yml中引用它.

Then, create a DockerHub account, publish the image and reference it in bitbucket-pipelines.yml.

这篇关于如何在BitBucket管道上为apt-get启用/设置依赖项缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆