Skip to content

Instantly share code, notes, and snippets.

@FlorianHeigl
Created May 7, 2026 20:12
Show Gist options
  • Select an option

  • Save FlorianHeigl/535f0db4decfe7ed6610baa85f8c910e to your computer and use it in GitHub Desktop.

Select an option

Save FlorianHeigl/535f0db4decfe7ed6610baa85f8c910e to your computer and use it in GitHub Desktop.
gitlab-ci-local apt caching, ccache caching
---
stages:
- bootstrap
default:
image: ubuntu:22.04
tags:
- docker
variables:
# FORCE_UNSAFE_CONFIGURE: 1
HTTP_PROXY: http://proxy:3128
HTTPS_PROXY: http://proxy:3128
FTP_PROXY: http://proxy:3128
http_proxy: http://proxy:3128
https_proxy: http://proxy:3128
ftp_proxy: http://proxy:3128
bootstrap:
stage: bootstrap
cache:
paths:
- ccache
- .apt
before_script:
# gitlab docs use a bind mount, that is NOT NEEDED, you can just use symlinks like shown here
- rm -f /etc/apt/apt.conf.d/docker-clean
- mkdir -p .apt/cache .apt/cache/partial .apt/lists || true
- rm -r /var/cache/apt/archives /var/lib/apt/lists || true
- ln -sfn ${CI_PROJECT_DIR}/.apt/cache /var/cache/apt/archives
- ln -sfn ${CI_PROJECT_DIR}/.apt/lists /var/lib/apt/lists
- apt update
- DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade
- DEBIAN_FRONTEND=noninteractive apt-get -yq install ccache
- DEBIAN_FRONTEND=noninteractive apt-get -yq install pkg-config build-essential ninja-build automake autoconf libtool wget curl git gcc libssl-dev bc slib squashfs-tools android-sdk-libsparse-utils jq python3-distutils scons parallel tree python3-dev python3-pip device-tree-compiler ssh cpio fakeroot libncurses5 flex bison libncurses5-dev genext2fs rsync unzip dosfstools mtools tcl openssh-client cmake expect python-is-python3 python3-jinja2
# copied from somewhere
- export PATH="/usr/lib/ccache:$PATH" # Override compiler path with ccache (this example is for Debian)
- export CCACHE_DIR="${CI_PROJECT_DIR}/ccache"
- export CCACHE_BASEDIR="${CI_PROJECT_DIR}"
- export CCACHE_COMPILERCHECK=content # Compiler
script:
- ccache --zero-stats || true
- run and build stuff
- done with stuff
image:
name: ubuntu:22.04
tags:
- docker
@FlorianHeigl
Copy link
Copy Markdown
Author

FlorianHeigl commented May 7, 2026

this is useful especially with gitlab-ci-local if you do many runs of a dockerized build, you can shorten the install phase like this.
there's also a flag for changing the behaviour when fetching the image, but I found the apt steps were a specific slowdown.
I'm testing other things like a caching registry as well; there's many things one can tune. most are error prone and the impact is always not documented. treat this the same way.

I can say my larger build job is already down from 28 to 21 mins before caching the packages, I hope once I optimize the package install and also speed up the ./configure runs in buildroot by putting /tmp in ram it should get to around 10 minutes. the rest is legit compiles which don't need tuning...

@FlorianHeigl
Copy link
Copy Markdown
Author

oh well and what do you know, uploading the cache at the end is also taking considerable time so it would appear there's no gain even though the install phase was so much faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment