Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable / setup Dependency Caches for apt-get on BitBucket Pipelines

Tags:

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 [email protected] -F ~/.ssh/config "cd /path/to/code && git pull"           # update composer           - ssh [email protected] -F ~/.ssh/config "cd /path/to/code && composer update --no-scripts"           # optimise files           - ssh [email protected] -F ~/.ssh/config "cd /path/to/code && php artisan optimize" 

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?

And how can I go about caching the apt-get step?

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 
like image 233
Niraj Shah Avatar asked Aug 30 '17 13:08

Niraj Shah


People also ask

How do I add dependencies to a Bitbucket build?

An easy way to make dependencies available to your build is to install them using the build script in your bitbucket-pipelines.yml file. The exact method of installing dependencies will depend on the Docker image you're using for your build. For Docker images based on Debian or Ubuntu, you can use apt-get to install packages.

What is Bitbucket Pipelines dependency caching?

Bitbucket Pipelines is able to cache external build dependencies and directories, such as 3rd-party libraries, between builds providing faster builds, and reducing the number of consumed build minutes. What is dependency caching?

Does Apt-Get Update Delete pipeline cache?

Remember that the pipeline caches may be deleted at any time, so you always need to run the commands anyway. apt-get update doesn't use a cache, so will download the latest indexes every time.

Is there a way to save time with pipeline caches?

Remember that the pipeline caches may be deleted at any time, so you always need to run the commands anyway. apt-get update doesn't use a cache, so will download the latest indexes every time. apt-get install caches downloaded packages in /var/cache/apt so you could save that. However this probably won't actually save any time


1 Answers

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.)

In your simple case, this Dockerfile should be enough:

FROM php:7.1.1  RUN apt-get update && \     apt-get install -y openssh-client 

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

like image 132
BlueM Avatar answered Oct 22 '22 11:10

BlueM