From 6bf83bcd602d6b0345e4a2ac95f5953c106ee2b7 Mon Sep 17 00:00:00 2001 From: gr0vity Date: Mon, 18 Nov 2024 13:18:26 +0100 Subject: [PATCH] cache Docker builds --- docker/node/Dockerfile | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/docker/node/Dockerfile b/docker/node/Dockerfile index 5cee44c922..170ef4a87d 100644 --- a/docker/node/Dockerfile +++ b/docker/node/Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.4 FROM ubuntu:22.04 AS builder ARG COMPILER=gcc @@ -7,21 +8,27 @@ ARG NANO_NETWORK=live COPY ./ci/prepare/linux /tmp/prepare RUN /tmp/prepare/prepare.sh -COPY ./ /tmp/src -WORKDIR /tmp/src - -# Define ARGs for ci/build-node.sh +# Define build arguments ARG BUILD_TYPE=RelWithDebInfo ARG NANO_TEST=OFF -ARG NANO_TRACING=OFF +ARG NANO_TRACING=ON ARG COVERAGE=OFF ARG CMAKE_SANITIZER="" ARG CI_TAG=DEV_BUILD ARG CI_VERSION_PRE_RELEASE=OFF ARG SANITIZER -# Build node -RUN ci/build-node.sh +# Copy source and set workdir +COPY ./ /tmp/src +WORKDIR /tmp/src + +# Use cache mount for build directory and copy outputs to a permanent location +RUN --mount=type=cache,target=/tmp/src/build,id=nano_build,sharing=locked \ + mkdir -p build && \ + ci/build-node.sh && \ + mkdir -p /tmp/build_output && \ + cp build/nano_node build/nano_rpc /tmp/build_output/ + RUN echo ${NANO_NETWORK} >/etc/nano-network FROM ubuntu:22.04 @@ -29,21 +36,22 @@ FROM ubuntu:22.04 RUN groupadd --gid 1000 nanocurrency && \ useradd --uid 1000 --gid nanocurrency --shell /bin/bash --create-home nanocurrency -COPY --from=builder /tmp/src/build/nano_node /usr/bin -COPY --from=builder /tmp/src/build/nano_rpc /usr/bin +# Copy from the permanent location instead of the cache mount +COPY --from=builder /tmp/build_output/nano_node /usr/bin +COPY --from=builder /tmp/build_output/nano_rpc /usr/bin COPY --from=builder /tmp/src/api/ /usr/bin/api/ COPY --from=builder /etc/nano-network /etc - COPY docker/node/entry.sh /usr/bin/entry.sh COPY docker/node/config /usr/share/nano/config -RUN chmod +x /usr/bin/entry.sh -RUN ln -s /usr/bin/nano_node /usr/bin/rai_node -RUN ldconfig + +RUN chmod +x /usr/bin/entry.sh && \ + ln -s /usr/bin/nano_node /usr/bin/rai_node && \ + ldconfig WORKDIR /root USER root - ENV PATH="${PATH}:/usr/bin" + ENTRYPOINT ["/usr/bin/entry.sh"] CMD ["nano_node", "daemon", "-l"]