Skip to content

Commit 9411f58

Browse files
committed
UPSTREAM: <carry>: Add support for optional prebuilt Go binaries in Dockerfiles
Signed-off-by: Helber Belmiro <[email protected]>
1 parent dca9085 commit 9411f58

File tree

5 files changed

+45
-7
lines changed

5 files changed

+45
-7
lines changed

backend/Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,15 @@ RUN GO111MODULE=on go mod download
3131
# Copy the source
3232
COPY ${SOURCE_CODE}/ ./
3333

34-
RUN GO111MODULE=on CGO_ENABLED=1 GOEXPERIMENT=strictfipsruntime go build -tags strictfipsruntime -o /bin/apiserver ./backend/src/apiserver/ && \
35-
dnf clean all
34+
# Accept an optional prebuilt Go binary
35+
ARG PREBUILT_BINARY="unset"
36+
37+
RUN if [ "$PREBUILT_BINARY" = "unset" ]; then \
38+
GO111MODULE=on CGO_ENABLED=1 GOEXPERIMENT=strictfipsruntime go build -tags strictfipsruntime -o /bin/apiserver ./backend/src/apiserver/ ;\
39+
else \
40+
cp "${PREBUILT_BINARY}" /bin/apiserver ;\
41+
fi \
42+
&& dnf clean all
3643

3744
# 2. Compile preloaded pipeline samples
3845
FROM registry.access.redhat.com/ubi9/python-39:9.5 as compiler

backend/Dockerfile.driver

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ RUN GO111MODULE=on go mod download
3434
# Copy the source
3535
COPY ${SOURCE_CODE}/ ./
3636

37-
RUN GO111MODULE=on CGO_ENABLED=1 GOOS=linux GOARCH=amd64 GOEXPERIMENT=strictfipsruntime go build -tags 'netgo strictfipsruntime' -o /bin/driver ./backend/src/v2/cmd/driver/*.go
37+
ARG PREBUILT_BINARY="unset"
38+
39+
# If PREBUILT_BINARY is set, use it; otherwise, build from source
40+
RUN if [ "$PREBUILT_BINARY" = "unset" ]; then \
41+
GO111MODULE=on CGO_ENABLED=1 GOOS=linux GOARCH=amd64 GOEXPERIMENT=strictfipsruntime go build -tags 'netgo strictfipsruntime' -o /bin/driver ./backend/src/v2/cmd/driver/*.go; \
42+
else \
43+
cp ${PREBUILT_BINARY} /bin/driver; \
44+
fi
3845

3946
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5
4047

backend/Dockerfile.launcher

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,16 @@ RUN GO111MODULE=on go mod download
3636
# Copy the source
3737
COPY ${SOURCE_CODE}/ ./
3838

39-
RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags netgo -ldflags '-extldflags "-static"' -o /bin/launcher-v2 ./backend/src/v2/cmd/launcher-v2/*.go
40-
RUN GO111MODULE=on CGO_ENABLED=1 GOOS=linux GOARCH=amd64 GOEXPERIMENT=strictfipsruntime go build -tags 'netgo strictfipsruntime' -o /bin/launcher-v2-fips ./backend/src/v2/cmd/launcher-v2/*.go
39+
# Accept an optional prebuilt Go binary
40+
ARG PREBUILT_BINARY="unset"
41+
42+
RUN if [ "$PREBUILT_BINARY" = "unset" ]; then \
43+
GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags netgo -ldflags '-extldflags "-static"' -o /bin/launcher-v2 ./backend/src/v2/cmd/launcher-v2/*.go && \
44+
GO111MODULE=on CGO_ENABLED=1 GOOS=linux GOARCH=amd64 GOEXPERIMENT=strictfipsruntime go build -tags 'netgo strictfipsruntime' -o /bin/launcher-v2-fips ./backend/src/v2/cmd/launcher-v2/*.go ;\
45+
else \
46+
cp "${PREBUILT_BINARY}" /bin/launcher-v2 && \
47+
cp "${PREBUILT_BINARY}" /bin/launcher-v2-fips ;\
48+
fi
4149

4250
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5
4351

backend/Dockerfile.persistenceagent

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ RUN GO111MODULE=on go mod download
3535
# Copy the source
3636
COPY ${SOURCE_CODE}/ ./
3737

38-
RUN GO111MODULE=on CGO_ENABLED=1 GOEXPERIMENT=strictfipsruntime go build -tags strictfipsruntime -o /bin/persistence_agent backend/src/agent/persistence/*.go
38+
# Accept an optional prebuilt Go binary
39+
ARG PREBUILT_BINARY="unset"
40+
41+
# If PREBUILT_BINARY is set, use it; otherwise, build from source
42+
RUN if [ "$PREBUILT_BINARY" = "unset" ]; then \
43+
GO111MODULE=on CGO_ENABLED=1 GOEXPERIMENT=strictfipsruntime go build -tags strictfipsruntime -o /bin/persistence_agent backend/src/agent/persistence/*.go; \
44+
else \
45+
cp ${PREBUILT_BINARY} /bin/persistence_agent; \
46+
fi
3947

4048
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5
4149
WORKDIR /bin

backend/Dockerfile.scheduledworkflow

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,15 @@ RUN GO111MODULE=on go mod download
4040
# Copy the source
4141
COPY ${SOURCE_CODE}/ ./
4242

43-
RUN GO111MODULE=on CGO_ENABLED=1 GOEXPERIMENT=strictfipsruntime go build -tags strictfipsruntime -o /bin/controller backend/src/crd/controller/scheduledworkflow/*.go
43+
# Accept an optional prebuilt Go binary
44+
ARG PREBUILT_BINARY="unset"
45+
46+
# If PREBUILT_BINARY is set, use it; otherwise, build from source
47+
RUN if [ "$PREBUILT_BINARY" = "unset" ]; then \
48+
GO111MODULE=on CGO_ENABLED=1 GOEXPERIMENT=strictfipsruntime go build -tags strictfipsruntime -o /bin/controller backend/src/crd/controller/scheduledworkflow/*.go; \
49+
else \
50+
cp ${PREBUILT_BINARY} /bin/controller; \
51+
fi
4452

4553
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5
4654
WORKDIR /bin

0 commit comments

Comments
 (0)