Skip to content

Commit

Permalink
fix(image): merges manifests builder stages to one
Browse files Browse the repository at this point in the history
We can combine two build stages to one, as there is no need to
always build both images 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
`FETCH_MANIFESTS` argument (previously known as `USE_LOCAL`).

In addition it opens up `IMAGE_BUILD_FLAGS` variable to be overwritten
when executing make targets instead of changing its value in the
`Makefile` directly, as it was previously needed.
  • Loading branch information
bartoszmajsak committed Dec 1, 2023
1 parent d81665d commit b7735c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
23 changes: 9 additions & 14 deletions Dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
# Build the manager binary
ARG GOLANG_VERSION=1.19
ARG USE_LOCAL=false
ARG FETCH_MANIFESTS=true
ARG OVERWRITE_MANIFESTS=""

################################################################################
FROM registry.access.redhat.com/ubi8/go-toolset:$GOLANG_VERSION as builder_local_false
FROM registry.access.redhat.com/ubi8/toolbox as manifests
ARG FETCH_MANIFESTS
ARG OVERWRITE_MANIFESTS
# Get all manifests from remote git repo to builder_local_false by script
USER root
WORKDIR /opt
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 odh-manifests/ /opt/odh-manifests/
RUN if [ "${FETCH_MANIFESTS}" = "true" ]; then \
rm -rf /opt/odh-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
USER root
WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -46,7 +41,7 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
WORKDIR /
COPY --from=builder /workspace/manager .
COPY --chown=1001:0 --from=builder /opt/odh-manifests /opt/manifests
COPY --chown=1001:0 --from=manifests /opt/odh-manifests /opt/manifests
# Recursive change all files
RUN chown -R 1001:0 /opt/manifests &&\
chmod -R a+r /opt/manifests
Expand Down
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ SHELL = /usr/bin/env bash -o pipefail
E2E_TEST_FLAGS = "--skip-deletion=false" -timeout 15m # See README.md, default go test timeout 10m

# Default image-build is to not use local odh-manifests folder
# set to "true" to use local instead
# see target "image-build"
IMAGE_BUILD_FLAGS = --build-arg USE_LOCAL=false
IMAGE_BUILD_FLAGS ?= --build-arg FETCH_MANIFESTS=true

.PHONY: all
all: build
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ make image-build
By default, building an image without any local changes(as a clean build)
This is what the production build system is doing.

In order to build an image with local `odh-manifests` folder, to set `IMAGE_BUILD_FLAGS ="--build-arg USE_LOCAL=true"` in make.
e.g `make image-build -e IMAGE_BUILD_FLAGS="--build-arg USE_LOCAL=true"`
In order to build an image with local `odh-manifests` folder, to set `IMAGE_BUILD_FLAGS ="--build-arg FETCH_MANIFESTS=false"` in make.
e.g `make image-build -e IMAGE_BUILD_FLAGS="--build-arg FETCH_MANIFESTS=false"`

#### Build Image

Expand Down

0 comments on commit b7735c3

Please sign in to comment.