From 6c3656423c87bb06ea48112654f6c39d620a155f Mon Sep 17 00:00:00 2001 From: Yauheni Kaliuta Date: Wed, 20 Nov 2024 18:22:13 +0200 Subject: [PATCH] Dockerfile: merges manifests builder stages to one (#1381) We can combine two build stages into one, as there is no need to always build both images (not done by podman) to only then decide from which one we want to copy manifests to the target image. Instead manifests stage will either copy local manifests or fetches using the script based on USE_LOCAL argument. Move USE_LOCAL and OVERWIRTE_MANIFESTS args under FROM since args have scope of the FROM they are declared in. It requires opt/manifests directory to exist, but since it's a part of git repo, it's fine. Original patch from: Bartosz Majsak [1] [1] https://github.com/opendatahub-io/opendatahub-operator/pull/773 Signed-off-by: Yauheni Kaliuta (cherry picked from commit c1671ab5fd11baea814f8acdee1bc448d502fb1c) --- Dockerfiles/Dockerfile | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/Dockerfiles/Dockerfile b/Dockerfiles/Dockerfile index 5de4803a321..7566fd1dd68 100644 --- a/Dockerfiles/Dockerfile +++ b/Dockerfiles/Dockerfile @@ -1,27 +1,21 @@ # Build the manager binary ARG GOLANG_VERSION=1.21 -ARG USE_LOCAL=false -ARG OVERWRITE_MANIFESTS="" ################################################################################ -FROM registry.access.redhat.com/ubi8/go-toolset:$GOLANG_VERSION as builder_local_false -ARG OVERWRITE_MANIFESTS -# Get all manifests from remote git repo to builder_local_false by script +FROM registry.access.redhat.com/ubi8/toolbox as manifests +ARG USE_LOCAL=false +ARG OVERWRITE_MANIFESTS="" USER root WORKDIR / -COPY get_all_manifests.sh get_all_manifests.sh -RUN ./get_all_manifests.sh ${OVERWRITE_MANIFESTS} - -################################################################################ -FROM registry.access.redhat.com/ubi8/go-toolset:$GOLANG_VERSION as builder_local_true -# Get all manifests from local to builder_local_true -USER root -WORKDIR /opt -# copy local manifests to build COPY opt/manifests/ /opt/manifests/ +COPY get_all_manifests.sh get_all_manifests.sh +RUN if [ "${USE_LOCAL}" != "true" ]; then \ + rm -rf /opt/manifests/*; \ + ./get_all_manifests.sh ${OVERWRITE_MANIFESTS}; \ + fi ################################################################################ -FROM builder_local_${USE_LOCAL} as builder +FROM registry.access.redhat.com/ubi8/go-toolset:$GOLANG_VERSION as builder ARG CGO_ENABLED=1 USER root WORKDIR /workspace @@ -53,7 +47,7 @@ RUN CGO_ENABLED=${CGO_ENABLED} GOOS=linux GOARCH=amd64 go build -a -o manager ma FROM registry.access.redhat.com/ubi8/ubi-minimal:latest WORKDIR / COPY --from=builder /workspace/manager . -COPY --chown=1001:0 --from=builder /opt/manifests /opt/manifests +COPY --chown=1001:0 --from=manifests /opt/manifests /opt/manifests # Recursive change all files RUN chown -R 1001:0 /opt/manifests &&\ chmod -R g=u /opt/manifests