|
| 1 | +# Copyright 2021 IBM Corporation |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +ARG GOLANG_VERSION=1.21 |
| 16 | +ARG BUILD_BASE=develop |
| 17 | + |
| 18 | +FROM --platform=$BUILDPLATFORM registry.redhat.io/ubi8/go-toolset@sha256:4ec05fd5b355106cc0d990021a05b71bbfb9231e4f5bdc0c5316515edf6a1c96 AS build |
| 19 | + |
| 20 | +FROM --platform=$BUILDPLATFORM $BUILD_BASE AS build |
| 21 | + |
| 22 | +LABEL image="build" |
| 23 | + |
| 24 | +USER root |
| 25 | + |
| 26 | +# needed for konflux as the previous stage is not used |
| 27 | +WORKDIR /opt/app |
| 28 | +COPY go.mod go.sum ./ |
| 29 | +# Download dependencies before copying the source so they will be cached |
| 30 | +RUN go mod download |
| 31 | + |
| 32 | +# Copy the source |
| 33 | +COPY . ./ |
| 34 | + |
| 35 | +# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope |
| 36 | +# don't provide "default" values (e.g. 'ARG TARGETARCH=amd64') for non-buildx environments, |
| 37 | +# see https://github.com/docker/buildx/issues/510 |
| 38 | +ARG TARGETOS |
| 39 | +ARG TARGETARCH |
| 40 | + |
| 41 | +# Build the binaries using native go compiler from BUILDPLATFORM but compiled output for TARGETPLATFORM |
| 42 | +# https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/ |
| 43 | +RUN --mount=type=cache,target=/root/.cache/go-build \ |
| 44 | + --mount=type=cache,target=/go/pkg \ |
| 45 | + export GOOS=${TARGETOS:-linux} && \ |
| 46 | + export GOARCH=${TARGETARCH:-amd64} && \ |
| 47 | + go build -o puller model-serving-puller/main.go && \ |
| 48 | + go build -o triton-adapter model-mesh-triton-adapter/main.go && \ |
| 49 | + go build -o mlserver-adapter model-mesh-mlserver-adapter/main.go && \ |
| 50 | + go build -o ovms-adapter model-mesh-ovms-adapter/main.go && \ |
| 51 | + go build -o torchserve-adapter model-mesh-torchserve-adapter/main.go |
| 52 | + |
| 53 | + |
| 54 | +############################################################################### |
| 55 | +# Stage 3: Copy build assets to create the smallest final runtime image |
| 56 | +############################################################################### |
| 57 | +FROM registry.access.redhat.com/ubi8/ubi-minimal:latest as runtime |
| 58 | + |
| 59 | +ARG USER=2000 |
| 60 | + |
| 61 | +USER root |
| 62 | + |
| 63 | +# install python to convert keras to tf |
| 64 | +# NOTE: tensorflow not supported on PowerPC (ppc64le) or System Z (s390x) https://github.com/tensorflow/tensorflow/issues/46181 |
| 65 | +RUN --mount=type=cache,target=/root/.cache/microdnf:rw \ |
| 66 | + microdnf install --setopt=cachedir=/root/.cache/microdnf --setopt=ubi-8-appstream-rpms.module_hotfixes=1 \ |
| 67 | + gcc \ |
| 68 | + gcc-c++ \ |
| 69 | + python38-devel \ |
| 70 | + python38 \ |
| 71 | + && ln -sf /usr/bin/python3 /usr/bin/python \ |
| 72 | + && ln -sf /usr/bin/pip3 /usr/bin/pip \ |
| 73 | + && true |
| 74 | + |
| 75 | +# need to upgrade pip and install wheel before installing grpcio, before installing tensorflow on aarch64 |
| 76 | +# use caching to speed up multi-platform builds |
| 77 | +COPY requirements.txt requirements.txt |
| 78 | +ENV PIP_CACHE_DIR=/root/.cache/pip |
| 79 | +RUN --mount=type=cache,target=/root/.cache/pip \ |
| 80 | + pip install -r requirements.txt |
| 81 | +RUN rm -rfv requirements.txt |
| 82 | +USER ${USER} |
| 83 | + |
| 84 | +# Add modelmesh version |
| 85 | +COPY version /etc/modelmesh-version |
| 86 | + |
| 87 | +# Copy over the binary and use it as the entrypoint |
| 88 | +COPY --from=build /opt/app/puller /opt/app/ |
| 89 | +COPY --from=build /opt/app/triton-adapter /opt/app/ |
| 90 | +COPY --from=build /opt/app/mlserver-adapter /opt/app/ |
| 91 | +COPY --from=build /opt/app/model-mesh-triton-adapter/scripts/tf_pb.py /opt/scripts/ |
| 92 | +COPY --from=build /opt/app/ovms-adapter /opt/app/ |
| 93 | +COPY --from=build /opt/app/torchserve-adapter /opt/app/ |
| 94 | + |
| 95 | +# wait to create commit-specific LABEL until end of the build to not unnecessarily |
| 96 | +# invalidate the cached image layers |
| 97 | +ARG IMAGE_VERSION |
| 98 | +ARG COMMIT_SHA |
| 99 | + |
| 100 | +LABEL name="model-serving-runtime-adapter" \ |
| 101 | + version="${IMAGE_VERSION}" \ |
| 102 | + release="${COMMIT_SHA}" \ |
| 103 | + summary="Sidecar container which runs in the ModelMesh Serving model server pods" \ |
| 104 | + description="Container which runs in each model serving pod acting as an intermediary between ModelMesh and third-party model-server containers" |
| 105 | + |
| 106 | +# 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) |
| 107 | +ENTRYPOINT ["/opt/app/puller"] |
0 commit comments