Skip to content

Commit 864a2aa

Browse files
Speed up Docker builds with BuildKit ccache mount
Enable ccache in the Docker build by: - Adding ccache to the builder stage's apt packages - Using a BuildKit cache mount (--mount=type=cache) for /root/.cache/ccache so the compiler cache persists across rebuilds - Setting CMAKE_C/CXX_COMPILER_LAUNCHER=ccache in the cmake invocation - Adding the BuildKit syntax directive and BUILDKIT_INLINE_CACHE=1 build arg in the CI workflow Also modernise the Dockerfile syntax: - Use '=' form for ENV directives (required by newer Docker versions) - Use uppercase AS for multi-stage build aliases Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
1 parent 5719027 commit 864a2aa

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

.github/workflows/pull-request-checks.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ jobs:
10151015
sudo apt update
10161016
sudo apt install openjdk-11-jdk-headless
10171017
- name: Build docker image
1018-
run: docker build -t cbmc .
1018+
run: docker build --build-arg BUILDKIT_INLINE_CACHE=1 -t cbmc .
10191019
- name: Smoke test goto-cc
10201020
run: docker run -v ${PWD}/.github/workflows/smoke_test_assets:/mnt/smoke -t cbmc goto-cc -o /mnt/smoke/test.goto /mnt/smoke/test.c
10211021
- name: Smoke test cbmc

Dockerfile

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
FROM ubuntu:20.04 as builder
2-
ENV DEBIAN_FRONTEND noninteractive
3-
ENV DEBCONF_NONINTERACTIVE_SEEN true
1+
# syntax=docker/dockerfile:1
2+
FROM ubuntu:20.04 AS builder
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
ENV DEBCONF_NONINTERACTIVE_SEEN=true
45
# Timezone data is needed during the installation of dependencies,
56
# since cmake depends on the tzdata package. In an interactive terminal,
67
# the user selects the timezone at installation time. Since this needs
@@ -18,11 +19,18 @@ RUN echo 'tzdata tzdata/Areas select Etc' | debconf-set-selections; \
1819
flex \
1920
bison \
2021
libxml2-utils \
21-
patch
22+
patch \
23+
ccache
2224
COPY . /tmp/cbmc
2325
WORKDIR /tmp/cbmc
24-
RUN cmake -S . -Bbuild -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ && cd build; ninja -j2
26+
RUN --mount=type=cache,target=/root/.cache/ccache \
27+
cmake -S . -Bbuild -G Ninja -DCMAKE_BUILD_TYPE=Release \
28+
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
29+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
30+
-DCMAKE_C_COMPILER=/usr/bin/gcc \
31+
-DCMAKE_CXX_COMPILER=/usr/bin/g++ && \
32+
cd build && ninja -j2
2533

26-
FROM ubuntu:20.04 as runner
34+
FROM ubuntu:20.04 AS runner
2735
COPY --from=builder /tmp/cbmc/build/bin/* /usr/local/bin/
2836
RUN apt-get update && apt-get install -y gcc

0 commit comments

Comments
 (0)