Skip to content

Commit 0769a52

Browse files
committed
Add support for optional prebuilt Go binaries in Dockerfiles
1 parent dca9085 commit 0769a52

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ FROM registry.access.redhat.com/ubi9/go-toolset:1.23 as builder
2020

2121
## Build args to be used at this step
2222
ARG SOURCE_CODE
23+
ARG PREBUILT_BINARY="unset"
2324

2425
## Switch to root as required for some operations
2526
USER root
@@ -34,7 +35,15 @@ RUN GO111MODULE=on go mod download
3435
# Copy the source
3536
COPY ${SOURCE_CODE}/ ./
3637

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
38+
# Accept an optional prebuilt Go binary
39+
COPY ${PREBUILT_BINARY} /tmp/prebuilt-driver
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 GOOS=linux GOARCH=amd64 GOEXPERIMENT=strictfipsruntime go build -tags 'netgo strictfipsruntime' -o /bin/driver ./backend/src/v2/cmd/driver/*.go; \
44+
else \
45+
cp /tmp/prebuilt-driver /bin/driver; \
46+
fi
3847

3948
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5
4049

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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,16 @@ 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+
COPY ${PREBUILT_BINARY} /tmp/prebuilt-persistence-agent
41+
42+
# If PREBUILT_BINARY is set, use it; otherwise, build from source
43+
RUN if [ "$PREBUILT_BINARY" = "unset" ]; then \
44+
GO111MODULE=on CGO_ENABLED=1 GOEXPERIMENT=strictfipsruntime go build -tags strictfipsruntime -o /bin/persistence_agent backend/src/agent/persistence/*.go; \
45+
else \
46+
cp /tmp/prebuilt-persistence-agent /bin/persistence_agent; \
47+
fi
3948

4049
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5
4150
WORKDIR /bin

backend/Dockerfile.scheduledworkflow

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@ 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+
COPY ${PREBUILT_BINARY} /tmp/prebuilt-controller
46+
47+
# If PREBUILT_BINARY is set, use it; otherwise, build from source
48+
RUN if [ "$PREBUILT_BINARY" = "unset" ]; then \
49+
GO111MODULE=on CGO_ENABLED=1 GOEXPERIMENT=strictfipsruntime go build -tags strictfipsruntime -o /bin/controller backend/src/crd/controller/scheduledworkflow/*.go; \
50+
else \
51+
cp /tmp/prebuilt-controller /bin/controller; \
52+
fi
4453

4554
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5
4655
WORKDIR /bin

0 commit comments

Comments
 (0)