|
| 1 | +# Compile Delve in an intermediate step. |
| 2 | +FROM registry.access.redhat.com/ubi8/ubi:latest AS delve-builder |
| 3 | + |
| 4 | +# The Golang version must be provided as a build arguments, which will ensure |
| 5 | +# that Delve gets built with the same version the service's binary gets built |
| 6 | +# with, to avoid any discrepancies. |
| 7 | +ARG GOLANG_VERSION |
| 8 | + |
| 9 | +# Install Tar to be able to extract Golang. |
| 10 | +RUN yum install --assumeyes \ |
| 11 | + tar \ |
| 12 | + && yum clean all |
| 13 | + |
| 14 | +# Download and extract Golang. |
| 15 | +RUN curl --location --output "${GOLANG_VERSION}.linux-amd64.tar.gz" "https://go.dev/dl/${GOLANG_VERSION}.linux-amd64.tar.gz" \ |
| 16 | + && tar --directory /usr/local --extract --file "${GOLANG_VERSION}.linux-amd64.tar.gz" \ |
| 17 | + && rm --force "${GOLANG_VERSION}.linux-amd64.tar.gz" |
| 18 | + |
| 19 | +# Put Golang in the path so that we can Delve with it. |
| 20 | +ENV PATH=$PATH:/usr/local/go/bin |
| 21 | + |
| 22 | +# Build Delve and leave it in a temporary directory. |
| 23 | +RUN GOBIN=/tmp/bin go install github.com/go-delve/delve/cmd/dlv@latest |
| 24 | + |
| 25 | +# Build the operator as normal. |
| 26 | +FROM registry.access.redhat.com/ubi8/ubi-minimal:latest |
| 27 | + |
| 28 | +LABEL maintainer = "KubeSaw <devsandbox@redhat.com>" |
| 29 | +LABEL author = "KubeSaw <devsandbox@redhat.com>" |
| 30 | + |
| 31 | +# Ensure that the "DEBUG_MODE" is enabled so that the binary executes with |
| 32 | +# Delve. |
| 33 | +ENV DEBUG_MODE=true \ |
| 34 | + OPERATOR=/usr/local/bin/host-operator \ |
| 35 | + USER_UID=1001 \ |
| 36 | + USER_NAME=host-operator \ |
| 37 | + LANG=en_US.utf8 |
| 38 | + |
| 39 | +# Install operator binary in the image. |
| 40 | +COPY build/_output/bin/host-operator ${OPERATOR} |
| 41 | + |
| 42 | +COPY build/bin /usr/local/bin |
| 43 | +RUN /usr/local/bin/user_setup |
| 44 | + |
| 45 | +# Copy Delve to the image so that we can execute the operator with it. |
| 46 | +COPY --from=delve-builder /tmp/bin/dlv /usr/local/bin/dlv |
| 47 | + |
| 48 | +ENTRYPOINT ["/usr/local/bin/entrypoint"] |
| 49 | + |
| 50 | +# Expose the debugger's port. |
| 51 | +EXPOSE 50000 |
| 52 | + |
| 53 | +USER ${USER_UID} |
0 commit comments