Skip to content

Commit 58e8724

Browse files
committed
base: speed up local rebuilds.
Using ccache can speed up local rebuilds even when the container layer cache is invalidated, which is easy to happen. It also requires a less complicated and less fragile setup than distcc (though distcc will always make for faster first builds). install_epics.sh still supports ccache-less setups, should that be required. On my machine, building an image with ccache for the first time took ~15m. Rebuilding it after invalidating the layer cache took only 3m36s. The output of 'ccache -s' is reproduced below: Cacheable calls: 3858 / 8743 (44.13%) Hits: 1923 / 3858 (49.84%) Direct: 1822 / 1923 (94.75%) Preprocessed: 101 / 1923 ( 5.25%) Misses: 1935 / 3858 (50.16%) Uncacheable calls: 4885 / 8743 (55.87%) Local storage: Cache size (GB): 0.18 / 5.00 ( 3.70%) It is not clear why the cache hits were below 50%, but it was still enough to make a big difference in build times. This was based on StackOverflow [1]. [1] https://stackoverflow.com/a/56833198
1 parent aa10732 commit 58e8724

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

base/Dockerfile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ FROM debian:${DEBIAN_VERSION}
55
ARG JOBS
66

77
ENV DEBIAN_FRONTEND=noninteractive
8+
ARG CCACHE_DIR=/ccache
89

910
# Disable APT sandbox so that single UID restriction is satisfied in systems
1011
# without subuid and subgid configured.
@@ -13,6 +14,7 @@ RUN echo 'APT::Sandbox::User "root";' > /etc/apt/apt.conf.d/90-disable-sandbox.c
1314
RUN apt update -y && \
1415
apt install -y --no-install-recommends \
1516
build-essential \
17+
ccache \
1618
git \
1719
libaravis-dev \
1820
libevent-dev \
@@ -32,7 +34,8 @@ RUN apt update -y && \
3234
python3-dev \
3335
cython3 \
3436
python3-numpy \
35-
ca-certificates
37+
ca-certificates && \
38+
for p in gcc g++; do ln -vs /usr/bin/ccache /usr/local/bin/$p; done
3639

3740
COPY lnls-get-n-unpack.sh /usr/local/bin/lnls-get-n-unpack
3841

@@ -49,24 +52,26 @@ WORKDIR /opt/epics
4952

5053
COPY epics-base-static-linking.patch $EPICS_IN_DOCKER
5154
COPY epics_versions.sh install_epics.sh $EPICS_IN_DOCKER
52-
RUN $EPICS_IN_DOCKER/install_epics.sh
55+
RUN --mount=type=cache,target=/ccache/ USE_CCACHE=1 $EPICS_IN_DOCKER/install_epics.sh
5356

5457
WORKDIR ${EPICS_MODULES_PATH}
5558

5659
COPY backport-ipmicomm.patch ipmicomm.patch caputlog-waveform-fix.patch $EPICS_IN_DOCKER
5760
COPY modules_versions.sh install_modules.sh $EPICS_IN_DOCKER
58-
RUN NEEDS_TIRPC=YES $EPICS_IN_DOCKER/install_modules.sh
61+
RUN --mount=type=cache,target=/ccache/ NEEDS_TIRPC=YES $EPICS_IN_DOCKER/install_modules.sh
5962

6063
COPY backport-adsupport-nanohttp.patch $EPICS_IN_DOCKER
6164
COPY area_detector_versions.sh install_area_detector.sh $EPICS_IN_DOCKER
62-
RUN $EPICS_IN_DOCKER/install_area_detector.sh
65+
RUN --mount=type=cache,target=/ccache/ $EPICS_IN_DOCKER/install_area_detector.sh
6366

6467
COPY motor_versions.sh install_motor.sh $EPICS_IN_DOCKER
65-
RUN $EPICS_IN_DOCKER/install_motor.sh
68+
RUN --mount=type=cache,target=/ccache/ $EPICS_IN_DOCKER/install_motor.sh
6669

6770
ARG DEBIAN_VERSION
6871
COPY opcua_versions.sh install_opcua.sh $EPICS_IN_DOCKER
69-
RUN $EPICS_IN_DOCKER/install_opcua.sh
72+
RUN --mount=type=cache,target=/ccache/ $EPICS_IN_DOCKER/install_opcua.sh
73+
74+
RUN --mount=type=cache,target=/ccache/ ccache -s
7075

7176
COPY lnls-prune-artifacts.sh /usr/local/bin/lnls-prune-artifacts
7277
COPY lnls-run.sh /usr/local/bin/lnls-run

base/install_epics.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ if [ -n "$COMMANDLINE_LIBRARY" ]; then
1414
echo "COMMANDLINE_LIBRARY = $COMMANDLINE_LIBRARY" > ${EPICS_BASE_PATH}/configure/CONFIG_SITE.local
1515
fi
1616

17+
if [ "$USE_CCACHE" = 1 ]; then
18+
printf "CC=/usr/local/bin/gcc\nCCC=/usr/local/bin/g++\n" >> ${EPICS_BASE_PATH}/configure/CONFIG.gnuCommon
19+
fi
20+
1721
install_module base EPICS_BASE

base/musl/Dockerfile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ FROM alpine:$ALPINE_VERSION
44

55
ARG JOBS
66

7+
ARG CCACHE_DIR=/ccache
8+
79
RUN apk add --no-cache \
810
bash \
11+
ccache \
912
git \
1013
g++ \
1114
libevent-dev \
@@ -32,7 +35,8 @@ RUN apk add --no-cache \
3235
python3-dev \
3336
py3-setuptools \
3437
cython \
35-
py3-numpy-dev
38+
py3-numpy-dev && \
39+
for p in gcc g++; do ln -vs /usr/bin/ccache /usr/local/bin/$p; done
3640

3741
COPY lnls-get-n-unpack.sh /usr/local/bin/lnls-get-n-unpack
3842
COPY lnls-run.sh /usr/local/bin/lnls-run
@@ -50,12 +54,14 @@ WORKDIR /opt/epics
5054

5155
COPY epics-base-static-linking.patch $EPICS_IN_DOCKER
5256
COPY epics_versions.sh install_epics.sh $EPICS_IN_DOCKER
53-
RUN COMMANDLINE_LIBRARY=READLINE_NCURSES $EPICS_IN_DOCKER/install_epics.sh
57+
RUN --mount=type=cache,target=/ccache/ USE_CCACHE=1 COMMANDLINE_LIBRARY=READLINE_NCURSES $EPICS_IN_DOCKER/install_epics.sh
5458

5559
WORKDIR ${EPICS_MODULES_PATH}
5660

5761
COPY backport-ipmicomm.patch ipmicomm.patch caputlog-waveform-fix.patch $EPICS_IN_DOCKER
5862
COPY modules_versions.sh install_modules.sh $EPICS_IN_DOCKER
59-
RUN NEEDS_TIRPC=YES $EPICS_IN_DOCKER/install_modules.sh
63+
RUN --mount=type=cache,target=/ccache/ NEEDS_TIRPC=YES $EPICS_IN_DOCKER/install_modules.sh
64+
65+
RUN --mount=type=cache,target=/ccache/ ccache -s
6066

6167
COPY lnls-build-static-ioc.sh /usr/local/bin/lnls-build-static-ioc

0 commit comments

Comments
 (0)