From 033d4d6aa760e0ec7bee1810072bc4dc8c298d4b Mon Sep 17 00:00:00 2001 From: daniellehrner Date: Wed, 8 May 2024 10:44:23 +0200 Subject: [PATCH] Run apt-get in docker builds without using any cache. (#7011) * Run apt-get in docker builds without using any cache. Split steps in individual RUN commands Signed-off-by: Daniel Lehrner * use env variable for apt non-cache settings, revert split into several RUN commands Signed-off-by: Daniel Lehrner * clean apt-get cache after installation to decrease docker image size Signed-off-by: Daniel Lehrner --------- Signed-off-by: Daniel Lehrner --- docker/Dockerfile | 26 ++++++++++++--------- ethereum/evmtool/src/main/docker/Dockerfile | 19 +++++++++------ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 472223cd108..0cbeb3dbba4 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,17 +1,21 @@ FROM ubuntu:23.10 ARG VERSION="dev" - -RUN apt-get update && \ - apt-get install --no-install-recommends -q --assume-yes openjdk-21-jre-headless=21* libjemalloc-dev=5.* adduser=3* && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* && \ - # Ubuntu 23.10 comes with an "ubuntu" user with uid 1000. We need 1000 for besu. - userdel ubuntu 2>/dev/null || true && rm -rf /home/ubuntu && \ - # Ensure we use a stable UID for besu, as file permissions are tied to UIDs. - adduser --uid 1000 --disabled-password --gecos "" --home /opt/besu besu && \ - chown besu:besu /opt/besu && \ - chmod 0755 /opt/besu +ENV NO_PROXY_CACHE="-o Acquire::BrokenProxy=true -o Acquire::http::No-Cache=true -o Acquire::http::Pipeline-Depth=0" + +# Update and install dependencies without using any cache +RUN apt-get update $NO_PROXY_CACHE && \ + apt-get install $NO_PROXY_CACHE --no-install-recommends -q --assume-yes openjdk-21-jre-headless=21* libjemalloc-dev=5.* adduser=3* && \ + # Clean apt cache + apt-get clean && \ + rm -rf /var/cache/apt/archives/* /var/cache/apt/archives/partial/* && \ + rm -rf /var/lib/apt/lists/* && \ + # Ubuntu 23.10 comes with an "ubuntu" user with uid 1000. We need 1000 for besu. + userdel ubuntu 2>/dev/null || true && rm -rf /home/ubuntu && \ + # Ensure we use a stable UID for besu, as file permissions are tied to UIDs. + adduser --uid 1000 --disabled-password --gecos "" --home /opt/besu besu && \ + chown besu:besu /opt/besu && \ + chmod 0755 /opt/besu USER besu WORKDIR /opt/besu diff --git a/ethereum/evmtool/src/main/docker/Dockerfile b/ethereum/evmtool/src/main/docker/Dockerfile index f487d56766b..62fa5c1149e 100644 --- a/ethereum/evmtool/src/main/docker/Dockerfile +++ b/ethereum/evmtool/src/main/docker/Dockerfile @@ -1,14 +1,19 @@ FROM ubuntu:22.04 ARG VERSION="dev" +ENV NO_PROXY_CACHE="-o Acquire::BrokenProxy=true -o Acquire::http::No-Cache=true -o Acquire::http::Pipeline-Depth=0" -RUN apt-get update && \ - apt-get install --no-install-recommends -q --assume-yes ca-certificates-java=20190909* && \ - apt-get install --no-install-recommends -q --assume-yes openjdk-17-jre-headless=17* && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* && \ - adduser --disabled-password --gecos "" --home /opt/besu besu && \ - chown besu:besu /opt/besu +# Update and install dependencies without using any cache +RUN apt-get update $NO_PROXY_CACHE && \ + apt-get install $NO_PROXY_CACHE --no-install-recommends -q --assume-yes ca-certificates-java=20190909* && \ + apt-get install $NO_PROXY_CACHE --no-install-recommends -q --assume-yes openjdk-17-jre-headless=17* && \ + # Clean apt cache \ + apt-get clean && \ + rm -rf /var/cache/apt/archives/* /var/cache/apt/archives/partial/* && \ + rm -rf /var/lib/apt/lists/* && \ + # Creating a user for besu + adduser --disabled-password --gecos "" --home /opt/besu besu && \ + chown besu:besu /opt/besu USER besu WORKDIR /opt/besu-evmtool