From d9f4793d5843a7b420cf3f3c6f72fe3869aac1c3 Mon Sep 17 00:00:00 2001 From: MohammadiIram Date: Tue, 15 Oct 2024 16:12:23 +0530 Subject: [PATCH] Review Dockerfile and RPM files for building odh-ml-pipelines-api-server-v2 in konflux --- backend/Dockerfile.api.konflux | 62 +++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/backend/Dockerfile.api.konflux b/backend/Dockerfile.api.konflux index f78e21179e5..e5a2627c735 100644 --- a/backend/Dockerfile.api.konflux +++ b/backend/Dockerfile.api.konflux @@ -12,48 +12,54 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM registry.redhat.io/ubi8/go-toolset@sha256:4ec05fd5b355106cc0d990021a05b71bbfb9231e4f5bdc0c5316515edf6a1c96 AS build +FROM registry.redhat.io/ubi8/go-toolset@sha256:4ec05fd5b355106cc0d990021a05b71bbfb9231e4f5bdc0c5316515edf6a1c96 AS builder -LABEL image="build" +## Build args to be used at this step +ARG SOURCE_CODE USER root -WORKDIR /opt/app -COPY go.mod go.sum ./ +RUN dnf update -y && \ + dnf install -y cmake clang openssl -# Download dependencies before copying the source so they will be cached -RUN go mod download + +COPY ${SOURCE_CODE}/go.mod ./ +COPY ${SOURCE_CODE}/go.sum ./ # Copy the source -COPY . ./ +COPY ${SOURCE_CODE}/ ./ + +RUN GO111MODULE=on go build -o /bin/apiserver ./backend/src/apiserver/ && \ + dnf clean all +FROM registry.redhat.io/ubi8/ubi-minimal@sha256:7583ca0ea52001562bd81a961da3f75222209e6192e4e413ee226cff97dbd48c -# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope -# don't provide "default" values (e.g. 'ARG TARGETARCH=amd64') for non-buildx environments, -# see https://github.com/docker/buildx/issues/510 -ARG TARGETOS -ARG TARGETARCH +WORKDIR /bin -# Build the binaries using native go compiler from BUILDPLATFORM but compiled output for TARGETPLATFORM -# https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/ +COPY --from=builder /opt/app-root/src/backend/src/apiserver/config/ /config +COPY --from=builder /bin/apiserver /bin/apiserver -RUN GOOS=${TARGETOS:-linux} \ - GOARCH=${TARGETARCH:-amd64} \ - CGO_ENABLED=0 \ - GO111MODULE=on \ - go build -a -o /go/bin/server ./proxy/ +RUN chmod +x /bin/apiserver +USER root -############################################################################### -# Stage 3: Copy binaries only to create the smallest final runtime image -############################################################################### -FROM registry.access.redhat.com/ubi8/ubi-micro@sha256:cf8d8796a2c07577b4adc8b598aa648b200cc6b4b5f78d2e13539711ea64f275 as runtime +# Adding CA certificate so API server can download pipeline through URL and wget is used for liveness/readiness probe command +RUN microdnf install -y ca-certificates wget -ARG USER=2000 +USER 1001 -USER ${USER} +# Expose apiserver port +EXPOSE 8888 -COPY version /etc/modelmesh-version -COPY --from=build /go/bin/server /go/bin/server +# Start the apiserver +CMD /bin/apiserver --config=/config --sampleconfig=/config/sample_config.json -logtostderr=true -CMD ["/go/bin/server"] \ No newline at end of file +LABEL com.redhat.component="odh-ml-pipelines-api-server-v2-container" \ + name="managed-open-data-hub/odh-ml-pipelines-api-server-v2-rhel8" \ + description="odh-ml-pipelines-api-server-v2" \ + summary="odh-ml-pipelines-api-server-v2" \ + maintainer="['managed-open-data-hub@redhat.com']" \ + io.openshift.expose-services="" \ + io.k8s.display-name="odh-ml-pipelines-api-server-v2" \ + io.k8s.description="odh-ml-pipelines-api-server-v2" \ + com.redhat.license_terms="https://www.redhat.com/licenses/Red_Hat_Standard_EULA_20191108.pdf"