From c9accc6b96b287e73d5c5a7e8818692412f44e00 Mon Sep 17 00:00:00 2001 From: David A Date: Thu, 12 Sep 2024 17:50:27 +0300 Subject: [PATCH 1/3] fix(dockerfile): optimized dockerfile, removed additional docker layers --- Dockerfile | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index b3879b69e..1bba20793 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,22 @@ # Container for building Go binary. FROM golang:1.23.1-bookworm AS builder + # Install dependencies -RUN apt-get update && apt-get install -y build-essential git +RUN apt-get update && apt-get install -y --no-install-recommends build-essential git \ + && rm -rf /var/lib/apt/lists/* + # Prep and copy source WORKDIR /app/charon +COPY go.mod go.sum ./ +RUN go mod download + COPY . . + # Populate GO_BUILD_FLAG with a build arg to provide an optional go build flag. ARG GO_BUILD_FLAG ENV GO_BUILD_FLAG=${GO_BUILD_FLAG} RUN echo "Building with GO_BUILD_FLAG='${GO_BUILD_FLAG}'" + # Build with Go module and Go build caches. RUN \ --mount=type=cache,target=/go/pkg \ @@ -18,33 +26,41 @@ RUN echo "Built charon version=$(./charon version)" # Copy final binary into light stage. FROM debian:bookworm-slim -RUN apt-get update && apt-get install -y ca-certificates wget fio +RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates wget fio \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ARG GITHUB_SHA=local ENV GITHUB_SHA=${GITHUB_SHA} + COPY --from=builder /app/charon/charon /usr/local/bin/ + # Don't run container as root ENV USER=charon ENV UID=1000 ENV GID=1000 -RUN addgroup --gid "$GID" "$USER" -RUN adduser \ +RUN addgroup --gid "$GID" "$USER" \ + && adduser \ --disabled-password \ --gecos "charon" \ --home "/opt/$USER" \ --ingroup "$USER" \ --no-create-home \ --uid "$UID" \ - "$USER" -RUN chown charon /usr/local/bin/charon -RUN chmod u+x /usr/local/bin/charon + "$USER" \ + && chown $USER /usr/local/bin/charon \ + && chmod u+x /usr/local/bin/charon \ + && mkdir -p "/opt/$USER" \ + && chown $USER "/opt/$USER" + WORKDIR "/opt/$USER" -RUN chown charon "/opt/$USER" USER charon + ENTRYPOINT ["/usr/local/bin/charon"] CMD ["run"] + # Used by GitHub to associate container with repo. LABEL org.opencontainers.image.source="https://github.com/obolnetwork/charon" LABEL org.opencontainers.image.title="charon" LABEL org.opencontainers.image.description="Proof of Stake Ethereum Distributed Validator Client" LABEL org.opencontainers.image.licenses="GPL v3" LABEL org.opencontainers.image.documentation="https://github.com/ObolNetwork/charon/tree/main/docs" + From dedc93e21568fef887ac7814d692d6944e492812 Mon Sep 17 00:00:00 2001 From: David A Date: Thu, 12 Sep 2024 18:33:02 +0300 Subject: [PATCH 2/3] fix(dockerfile): fix pr comments --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1bba20793..f309bcbb7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,7 @@ RUN echo "Built charon version=$(./charon version)" # Copy final binary into light stage. FROM debian:bookworm-slim -RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates wget fio \ +RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates fio wget \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ARG GITHUB_SHA=local ENV GITHUB_SHA=${GITHUB_SHA} @@ -46,10 +46,10 @@ RUN addgroup --gid "$GID" "$USER" \ --no-create-home \ --uid "$UID" \ "$USER" \ - && chown $USER /usr/local/bin/charon \ + && chown "$USER" /usr/local/bin/charon \ && chmod u+x /usr/local/bin/charon \ && mkdir -p "/opt/$USER" \ - && chown $USER "/opt/$USER" + && chown "$USER" "/opt/$USER" WORKDIR "/opt/$USER" USER charon From 8ee649e09178eb7f5288090fa4d5661901165fbb Mon Sep 17 00:00:00 2001 From: David A Date: Mon, 23 Sep 2024 07:46:17 +0300 Subject: [PATCH 3/3] fix(dockerfile): fix pr comments --- Dockerfile | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index f309bcbb7..741da5a0f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,10 @@ FROM golang:1.23.1-bookworm AS builder # Install dependencies -RUN apt-get update && apt-get install -y --no-install-recommends build-essential git \ - && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install -y --no-install-recommends build-essential git # Prep and copy source WORKDIR /app/charon -COPY go.mod go.sum ./ -RUN go mod download COPY . . @@ -47,9 +44,7 @@ RUN addgroup --gid "$GID" "$USER" \ --uid "$UID" \ "$USER" \ && chown "$USER" /usr/local/bin/charon \ - && chmod u+x /usr/local/bin/charon \ - && mkdir -p "/opt/$USER" \ - && chown "$USER" "/opt/$USER" + && chmod u+x /usr/local/bin/charon WORKDIR "/opt/$USER" USER charon @@ -63,4 +58,3 @@ LABEL org.opencontainers.image.title="charon" LABEL org.opencontainers.image.description="Proof of Stake Ethereum Distributed Validator Client" LABEL org.opencontainers.image.licenses="GPL v3" LABEL org.opencontainers.image.documentation="https://github.com/ObolNetwork/charon/tree/main/docs" -