|
| 1 | +# Copyright 2024 Google LLC |
| 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 | +# Use the official lightweight Python image. |
| 16 | +# https://hub.docker.com/_/python |
| 17 | + |
| 18 | +# ---- LIT on GCP Base Images ---- |
| 19 | + |
| 20 | +FROM python:3.11-slim AS lit-gcp-app-server-base |
| 21 | + |
| 22 | +# Update Ubuntu packages and install basic utils |
| 23 | +RUN apt-get update |
| 24 | +RUN apt-get install -y wget curl gnupg2 gcc g++ git |
| 25 | + |
| 26 | +# Copy local code to the container image. |
| 27 | +ENV APP_HOME=/app |
| 28 | +WORKDIR $APP_HOME |
| 29 | + |
| 30 | +COPY ./lit_nlp/examples/gcp/server_gunicorn_config.py ./gunicorn_config.py |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +FROM nvidia/cuda:12.5.1-base-ubuntu22.04 AS lit-gcp-model-server-base |
| 35 | +ENV DEBIAN_FRONTEND=noninteractive |
| 36 | +ENV LANG=C.UTF-8 |
| 37 | + |
| 38 | +ARG PYTHON_VERSION=python3.11 |
| 39 | + |
| 40 | +RUN apt-get update |
| 41 | + |
| 42 | +# Install the CUDA Keyring package |
| 43 | +# See https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#network-repo-installation-for-ubuntu |
| 44 | +RUN apt-get install -y curl gnupg ca-certificates |
| 45 | +RUN curl https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb \ |
| 46 | + -o cuda-keyring_1.1-1_all.deb |
| 47 | +RUN dpkg -i cuda-keyring_1.1-1_all.deb |
| 48 | + |
| 49 | +# Install system and CUDA packages |
| 50 | +RUN apt-get install -y --no-install-recommends \ |
| 51 | + cuda-command-line-tools-12-3 \ |
| 52 | + cuda-cudart-dev-12-3 \ |
| 53 | + cuda-nvcc-12-3 \ |
| 54 | + cuda-cupti-12-3 \ |
| 55 | + cuda-nvprune-12-3 \ |
| 56 | + cuda-libraries-12-3 \ |
| 57 | + cuda-nvrtc-12-3 \ |
| 58 | + libcufft-12-3 \ |
| 59 | + libcurand-12-3 \ |
| 60 | + libcusolver-12-3 \ |
| 61 | + libcusparse-12-3 \ |
| 62 | + libcublas-12-3 \ |
| 63 | + libcudnn8=8.9.6.50-1+cuda12.2 \ |
| 64 | + libnvinfer-plugin8=8.6.1.6-1+cuda12.0 \ |
| 65 | + libnvinfer8=8.6.1.6-1+cuda12.0 \ |
| 66 | + build-essential \ |
| 67 | + pkg-config \ |
| 68 | + software-properties-common \ |
| 69 | + unzip |
| 70 | + |
| 71 | +# Install Python 3.11 |
| 72 | +RUN apt-get install -y --no-install-recommends \ |
| 73 | + $PYTHON_VERSION \ |
| 74 | + $PYTHON_VERSION-venv \ |
| 75 | + $PYTHON_VERSION-distutils \ |
| 76 | + $PYTHON_VERSION-dev |
| 77 | +RUN ln -sf /usr/bin/$PYTHON_VERSION /usr/bin/python3 |
| 78 | +RUN ln -sf /usr/bin/$PYTHON_VERSION /usr/bin/python |
| 79 | + |
| 80 | +# Install pip |
| 81 | +RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py |
| 82 | +RUN python3 get-pip.py |
| 83 | +RUN python3 -m pip install --no-cache-dir --upgrade pip |
| 84 | + |
| 85 | +RUN apt-get clean |
| 86 | +RUN rm -rf /var/lib/apt/lists/* |
| 87 | + |
| 88 | +COPY ./lit_nlp/examples/gcp/model_server_gunicorn_config.py ./ |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +# ---- LIT on GCP Production Images ---- |
| 93 | + |
| 94 | +FROM lit-gcp-app-server-base AS lit-gcp-app-server |
| 95 | + |
| 96 | +RUN python -m pip install 'lit-nlp[examples-genai]' |
| 97 | +ENTRYPOINT ["gunicorn", "--config=gunicorn_config.py"] |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | +FROM lit-gcp-model-server-base AS lit-gcp-model-server |
| 102 | + |
| 103 | +RUN python -m pip install 'lit-nlp[examples-genai]' |
| 104 | +ENTRYPOINT ["gunicorn", "--config=model_server_gunicorn_config.py"] |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | +# ---- LIT on GCP Development Images ---- |
| 109 | + |
| 110 | +FROM lit-gcp-app-server-base AS lit-gcp-app-server-dev |
| 111 | + |
| 112 | +# Install yarn |
| 113 | +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - |
| 114 | +RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | \ |
| 115 | + tee /etc/apt/sources.list.d/yarn.list |
| 116 | +RUN apt update && apt -y install yarn |
| 117 | + |
| 118 | +# Set up python environment with production dependencies |
| 119 | +# This step is slow as it installs many packages. |
| 120 | +COPY requirements.txt \ |
| 121 | + requirements_examples_common.txt \ |
| 122 | + requirements_examples_genai.txt \ |
| 123 | + ./ |
| 124 | +RUN python -m pip install -r requirements_examples_genai.txt |
| 125 | + |
| 126 | +# Copy the rest of the lit_nlp package |
| 127 | +COPY . ./ |
| 128 | + |
| 129 | +# Build front-end with yarn |
| 130 | +WORKDIR $APP_HOME/lit_nlp/client |
| 131 | +ENV NODE_OPTIONS="--openssl-legacy-provider" |
| 132 | +RUN yarn && yarn build && rm -rf node_modules/* |
| 133 | + |
| 134 | +# Run LIT server |
| 135 | +# Note that the config file supports configuring the LIT demo that is launched |
| 136 | +# via the DEMO_NAME and DEMO_PORT environment variables. |
| 137 | +WORKDIR $APP_HOME |
| 138 | +ENTRYPOINT ["gunicorn", "--config=gunicorn_config.py"] |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | +FROM lit-gcp-model-server-base AS lit-gcp-model-server-dev |
| 143 | +ENV APP_HOME=/app |
| 144 | +WORKDIR $APP_HOME |
| 145 | + |
| 146 | +# Install Node.js v18 (the base image ships with Node.js v12) |
| 147 | +# See https://github.com/nodesource/distributions |
| 148 | +RUN curl -fsSL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh |
| 149 | +RUN bash nodesource_setup.sh |
| 150 | +RUN apt-get install -y nodejs |
| 151 | + |
| 152 | +# Install yarn |
| 153 | +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - |
| 154 | +RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | \ |
| 155 | + tee /etc/apt/sources.list.d/yarn.list |
| 156 | +RUN apt update && apt -y install yarn |
| 157 | + |
| 158 | +COPY requirements.txt \ |
| 159 | + requirements_examples_common.txt \ |
| 160 | + requirements_examples_genai.txt \ |
| 161 | + ./ |
| 162 | +RUN python -m pip install -r requirements_examples_genai.txt |
| 163 | + |
| 164 | +# Copy the rest of the lit_nlp package |
| 165 | +COPY . ./ |
| 166 | + |
| 167 | +# Build front-end with yarn |
| 168 | +WORKDIR $APP_HOME/lit_nlp/client |
| 169 | +ENV NODE_OPTIONS="--openssl-legacy-provider" |
| 170 | +RUN yarn && yarn build && rm -rf node_modules/* |
| 171 | + |
| 172 | +WORKDIR $APP_HOME |
| 173 | +ENTRYPOINT ["gunicorn", "--config=model_server_gunicorn_config.py"] |
0 commit comments