Add ability to cache apt-get programs

caching

#1

From Caching apt-get install results

All credit to @winksaville, this is a feature I would really like as well.

It would speed up builds immensely.


Caching apt-get packages
#2

+1 for this. I was wondering how I could do this earlier. Especially helpful when you need to run an apt-get update before installing a package.


#3

Thank you for your feedback—we’ll see what we can do here.


#4

This should work >

dependencies:
  cache_directories:
    - "~/.apt-cache"
  pre:
    - sudo rm -rf /var/cache/apt/archives && sudo ln -s ~/.apt-cache /var/cache/apt/archives && mkdir -p ~/.apt-cache/partial

#5

Or set the cache dir when you call it:

- sudo apt-get -o dir::cache::archives="/home/ubuntu/aptcache" update; sudo apt-get -o dir::cache::archives="/home/ubuntu/aptcache" install -y libmemcached-dev gettext cowsay


#6

I’m not sure if this caches the update bit, since the lists are stored somewhere else if I am not mistaken. I may be silly and haven’t timed the overhead of update properly, but I have this more complicated approach

#!/bin/bash

set -e

pkgs=(git curl libcurl3 libcurl3-gnutls)

# Work from the directory CI will cache
mkdir -p ~/cache/deb
cd ~/cache/deb

# check we have a deb for each package
useCache=true
for pkg in "${pkgs[@]}"; do
    if ! ls | grep "^${pkg}"; then
        useCache=false
    fi
done

set -x

if [ ${useCache} == true ]; then
    sudo dpkg -i *.deb
    exit 0
fi

sudo apt-get update
sudo apt-get install --reinstall "${pkgs[@]}"

cp -v /var/cache/apt/archives/*.deb ~/cache/deb/

(we have ~/cache in our cached_directories)


#7

Hello!

I’ve just published a guide which helps improve apt-get installs on
CCI, please try it out and let me know how we can improve it!


#8

Your guide seems to solve this for CircleCI 1.0. Is there an equivalent for 2.0?


#9

The same would work in 2.0 if you are using a Debian-based environment. Ideally, before trying to employ this, you would simply use a Docker image that has the packages installed and not installing them on the fly.


#10