From a0d7b23199e26f148e6fd1ef4290bd033bc7d44c Mon Sep 17 00:00:00 2001 From: Ryan Mullins Date: Mon, 12 Aug 2024 15:52:37 +0000 Subject: [PATCH] Converting hosted demos images to multi-stage builds --- .github/workflows/ci.yml | 1 + Dockerfile | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2422e3b5..74014c8e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,4 +73,5 @@ jobs: - name: Build Docker image uses: docker/build-push-action@v4 with: + target: lit-nlp-prod tags: lit-nlp:ci-${{ github.sha }} diff --git a/Dockerfile b/Dockerfile index 11c1eeea..c9d405cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,22 +14,44 @@ # ============================================================================== # Use the official lightweight Python image. # https://hub.docker.com/_/python -FROM python:3.10-slim + +# ---- LIT Base Container ---- + +FROM python:3.11-slim AS lit-nlp-base # Update Ubuntu packages and install basic utils RUN apt-get update RUN apt-get install -y wget curl gnupg2 gcc g++ git +# Copy local code to the container image. +ENV APP_HOME /app +WORKDIR $APP_HOME + +COPY ./lit_nlp/examples/gunicorn_config.py ./ + + + +# ---- LIT Container for Hosted Demos ---- + +FROM lit-nlp-base AS lit-nlp-prod + +RUN python -m pip install 'lit-nlp[examples]' + +WORKDIR $APP_HOME +ENTRYPOINT ["gunicorn", "--config=gunicorn_config.py"] + + + +# ---- LIT Container for Developing and Testing Hosted Demos ---- + +FROM lit-nlp-base AS lit-nlp-dev + # Install yarn RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | \ tee /etc/apt/sources.list.d/yarn.list RUN apt update && apt -y install yarn -# Copy local code to the container image. -ENV APP_HOME /app -WORKDIR $APP_HOME - # Set up python environment with production dependencies # This step is slow as it installs many packages. COPY ./requirements*.txt ./ @@ -47,7 +69,4 @@ RUN yarn && yarn build && rm -rf node_modules/* # Note that the config file supports configuring the LIT demo that is launched # via the DEMO_NAME and DEMO_PORT environment variables. WORKDIR $APP_HOME -ENTRYPOINT [ \ - "gunicorn", \ - "--config=lit_nlp/examples/gunicorn_config.py" \ -] +ENTRYPOINT ["gunicorn", "--config=gunicorn_config.py"]