Skip to content

Commit

Permalink
Dockerfile: merges manifests builder stages to one (opendatahub-io#1381)
Browse files Browse the repository at this point in the history
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 <[email protected]> [1]

[1] opendatahub-io#773

Signed-off-by: Yauheni Kaliuta <[email protected]>
(cherry picked from commit c1671ab)
  • Loading branch information
ykaliuta authored and zdtsw committed Nov 29, 2024
1 parent f60ab71 commit 6c36564
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions Dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6c36564

Please sign in to comment.