Skip to content

Commit 4453bbf

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 4m06s. The output of 'ccache -s' is reproduced below: Cacheable calls: 1929 / 4371 (44.13%) Hits: 1923 / 1929 (99.69%) Direct: 1829 / 1923 (95.11%) Preprocessed: 94 / 1923 ( 4.89%) Misses: 6 / 1929 ( 0.31%) Uncacheable calls: 2442 / 4371 (55.87%) Local storage: Cache size (GB): 0.19 / 5.00 ( 3.71%) This was based on StackOverflow [1], but adding the compiler symlinks to /usr/local/bin wasn't enough for the EPICS build system to use them, since it uses fully qualified paths. Therefore, it was necessary to override the paths in configure/CONFIG.gnuCommon (appending to the file was the easiest way to override them for sure). We also had to call 'ccache -z' to remove the ccache statistics file, otherwise it would roll over for each build and mix data from different builds. [1] https://stackoverflow.com/a/56833198
1 parent aa10732 commit 4453bbf

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

base/Dockerfile

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ 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.
1112
RUN echo 'APT::Sandbox::User "root";' > /etc/apt/apt.conf.d/90-disable-sandbox.conf
1213

13-
RUN apt update -y && \
14+
RUN --mount=type=cache,target=/ccache/ 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,9 @@ RUN apt update -y && \
3234
python3-dev \
3335
cython3 \
3436
python3-numpy \
35-
ca-certificates
37+
ca-certificates && \
38+
ccache -z && \
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

@@ -49,24 +53,26 @@ WORKDIR /opt/epics
4953

5054
COPY epics-base-static-linking.patch $EPICS_IN_DOCKER
5155
COPY epics_versions.sh install_epics.sh $EPICS_IN_DOCKER
52-
RUN $EPICS_IN_DOCKER/install_epics.sh
56+
RUN --mount=type=cache,target=/ccache/ USE_CCACHE=1 $EPICS_IN_DOCKER/install_epics.sh
5357

5458
WORKDIR ${EPICS_MODULES_PATH}
5559

5660
COPY backport-ipmicomm.patch ipmicomm.patch caputlog-waveform-fix.patch $EPICS_IN_DOCKER
5761
COPY modules_versions.sh install_modules.sh $EPICS_IN_DOCKER
58-
RUN NEEDS_TIRPC=YES $EPICS_IN_DOCKER/install_modules.sh
62+
RUN --mount=type=cache,target=/ccache/ NEEDS_TIRPC=YES $EPICS_IN_DOCKER/install_modules.sh
5963

6064
COPY backport-adsupport-nanohttp.patch $EPICS_IN_DOCKER
6165
COPY area_detector_versions.sh install_area_detector.sh $EPICS_IN_DOCKER
62-
RUN $EPICS_IN_DOCKER/install_area_detector.sh
66+
RUN --mount=type=cache,target=/ccache/ $EPICS_IN_DOCKER/install_area_detector.sh
6367

6468
COPY motor_versions.sh install_motor.sh $EPICS_IN_DOCKER
65-
RUN $EPICS_IN_DOCKER/install_motor.sh
69+
RUN --mount=type=cache,target=/ccache/ $EPICS_IN_DOCKER/install_motor.sh
6670

6771
ARG DEBIAN_VERSION
6872
COPY opcua_versions.sh install_opcua.sh $EPICS_IN_DOCKER
69-
RUN $EPICS_IN_DOCKER/install_opcua.sh
73+
RUN --mount=type=cache,target=/ccache/ $EPICS_IN_DOCKER/install_opcua.sh
74+
75+
RUN --mount=type=cache,target=/ccache/ ccache -s
7076

7177
COPY lnls-prune-artifacts.sh /usr/local/bin/lnls-prune-artifacts
7278
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: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ FROM alpine:$ALPINE_VERSION
44

55
ARG JOBS
66

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

3742
COPY lnls-get-n-unpack.sh /usr/local/bin/lnls-get-n-unpack
3843
COPY lnls-run.sh /usr/local/bin/lnls-run
@@ -50,12 +55,14 @@ WORKDIR /opt/epics
5055

5156
COPY epics-base-static-linking.patch $EPICS_IN_DOCKER
5257
COPY epics_versions.sh install_epics.sh $EPICS_IN_DOCKER
53-
RUN COMMANDLINE_LIBRARY=READLINE_NCURSES $EPICS_IN_DOCKER/install_epics.sh
58+
RUN --mount=type=cache,target=/ccache/ USE_CCACHE=1 COMMANDLINE_LIBRARY=READLINE_NCURSES $EPICS_IN_DOCKER/install_epics.sh
5459

5560
WORKDIR ${EPICS_MODULES_PATH}
5661

5762
COPY backport-ipmicomm.patch ipmicomm.patch caputlog-waveform-fix.patch $EPICS_IN_DOCKER
5863
COPY modules_versions.sh install_modules.sh $EPICS_IN_DOCKER
59-
RUN NEEDS_TIRPC=YES $EPICS_IN_DOCKER/install_modules.sh
64+
RUN --mount=type=cache,target=/ccache/ NEEDS_TIRPC=YES $EPICS_IN_DOCKER/install_modules.sh
65+
66+
RUN --mount=type=cache,target=/ccache/ ccache -s
6067

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

0 commit comments

Comments
 (0)