|
| 1 | + |
| 2 | +ARG BUILD_BASE=develop |
| 3 | + |
| 4 | +#go-1.21 |
| 5 | +FROM --platform=$BUILDPLATFORM registry.redhat.io/ubi8/go-toolset@sha256:4ec05fd5b355106cc0d990021a05b71bbfb9231e4f5bdc0c5316515edf6a1c96 AS build |
| 6 | + |
| 7 | +FROM --platform=$BUILDPLATFORM $BUILD_BASE AS build |
| 8 | + |
| 9 | +LABEL image="build" |
| 10 | + |
| 11 | +USER root |
| 12 | + |
| 13 | +# needed for konflux as the previous stage is not used |
| 14 | +WORKDIR /opt/app |
| 15 | +COPY go.mod go.sum ./ |
| 16 | +# Download dependencies before copying the source so they will be cached |
| 17 | +RUN go mod download |
| 18 | + |
| 19 | +# Copy the source |
| 20 | +COPY . ./ |
| 21 | + |
| 22 | +ARG TARGETOS=amd64 |
| 23 | +ARG TARGETARCH=linux |
| 24 | + |
| 25 | +# Build the binaries using native go compiler from BUILDPLATFORM but compiled output for TARGETPLATFORM |
| 26 | +# https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/ |
| 27 | +RUN --mount=type=cache,target=/root/.cache/go-build \ |
| 28 | + --mount=type=cache,target=/go/pkg \ |
| 29 | + export GOOS=${TARGETOS:-linux} && \ |
| 30 | + export GOARCH=${TARGETARCH:-amd64} && \ |
| 31 | + go build -o puller model-serving-puller/main.go && \ |
| 32 | + go build -o triton-adapter model-mesh-triton-adapter/main.go && \ |
| 33 | + go build -o mlserver-adapter model-mesh-mlserver-adapter/main.go && \ |
| 34 | + go build -o ovms-adapter model-mesh-ovms-adapter/main.go && \ |
| 35 | + go build -o torchserve-adapter model-mesh-torchserve-adapter/main.go |
| 36 | + |
| 37 | + |
| 38 | +############################################################################### |
| 39 | +# Stage 3: Copy build assets to create the smallest final runtime image |
| 40 | +############################################################################### |
| 41 | +#ubi-minimal:latest |
| 42 | +FROM registry.redhat.io/ubi8/ubi-minimal@sha256:7583ca0ea52001562bd81a961da3f75222209e6192e4e413ee226cff97dbd48c as runtime |
| 43 | + |
| 44 | +ARG USER=2000 |
| 45 | + |
| 46 | +USER root |
| 47 | + |
| 48 | +# install python to convert keras to tf |
| 49 | +# NOTE: tensorflow not supported on PowerPC (ppc64le) or System Z (s390x) https://github.com/tensorflow/tensorflow/issues/46181 |
| 50 | +RUN --mount=type=cache,target=/root/.cache/microdnf:rw \ |
| 51 | + microdnf install --setopt=cachedir=/root/.cache/microdnf --setopt=ubi-8-appstream-rpms.module_hotfixes=1 \ |
| 52 | + gcc \ |
| 53 | + gcc-c++ \ |
| 54 | + python38-devel \ |
| 55 | + python38 \ |
| 56 | + && ln -sf /usr/bin/python3 /usr/bin/python \ |
| 57 | + && ln -sf /usr/bin/pip3 /usr/bin/pip \ |
| 58 | + && true |
| 59 | + |
| 60 | +# need to upgrade pip and install wheel before installing grpcio, before installing tensorflow on aarch64 |
| 61 | +# use caching to speed up multi-platform builds |
| 62 | +COPY requirements.txt requirements.txt |
| 63 | +ENV PIP_CACHE_DIR=/root/.cache/pip |
| 64 | +RUN --mount=type=cache,target=/root/.cache/pip \ |
| 65 | + pip install -r requirements.txt |
| 66 | +RUN rm -rfv requirements.txt |
| 67 | +USER ${USER} |
| 68 | + |
| 69 | +# Add modelmesh version |
| 70 | +COPY version /etc/modelmesh-version |
| 71 | + |
| 72 | +# Copy over the binary and use it as the entrypoint |
| 73 | +COPY --from=build /opt/app/puller /opt/app/ |
| 74 | +COPY --from=build /opt/app/triton-adapter /opt/app/ |
| 75 | +COPY --from=build /opt/app/mlserver-adapter /opt/app/ |
| 76 | +COPY --from=build /opt/app/model-mesh-triton-adapter/scripts/tf_pb.py /opt/scripts/ |
| 77 | +COPY --from=build /opt/app/ovms-adapter /opt/app/ |
| 78 | +COPY --from=build /opt/app/torchserve-adapter /opt/app/ |
| 79 | + |
| 80 | +# wait to create commit-specific LABEL until end of the build to not unnecessarily |
| 81 | +# invalidate the cached image layers |
| 82 | +ARG IMAGE_VERSION |
| 83 | +ARG COMMIT_SHA |
| 84 | + |
| 85 | +LABEL com.redhat.component="odh-modelmesh-runtime-adapter-container" \ |
| 86 | + name="managed-open-data-hub/odh-modelmesh-runtime-adapter-container-rhel8" \ |
| 87 | + description="Container which runs in each model serving pod and act as an intermediary between model-mesh and third-party model-server containers" \ |
| 88 | + summary="odh-model-serving-runtime-adapter" \ |
| 89 | + maintainer="[' [email protected]']" \ |
| 90 | + io.k8s.display-name="odh-model-serving-runtime-adapter" \ |
| 91 | + io.k8s.description="odh-model-serving-runtime-adapter" \ |
| 92 | + com.redhat.license_terms="https://www.redhat.com/licenses/Red_Hat_Standard_EULA_20191108.pdf" |
| 93 | + |
| 94 | +# Don't define an entrypoint. This is a multi-purpose image so the user should specify which binary they want to run (e.g. /opt/app/puller or /opt/app/triton-adapter) |
| 95 | +# ENTRYPOINT ["/opt/app/puller"] |
0 commit comments