Skip to content

Commit

Permalink
Fix dependency related build issues in Dockerfiles (#2135)
Browse files Browse the repository at this point in the history
* Fix a path issue in Dockerfile-GPU

* Fix paths in Dockerfile-GPU

* Add workflow_dispatch to docker build task

* Remove reference to optional component from ui/, not needed anymore

* Move pytorch installation last to avoid replacing it later

* Remove optional import from rest_api too, no more needed

* Change path in ui/Dockerfile

* ui container works again

* Complete review of import paths

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
ZanSara and github-actions[bot] committed Feb 9, 2022
1 parent aca52ea commit 9dc89d2
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 56 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker_build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: docker-build

on:
workflow_dispatch:
push:
branches:
- master
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ COPY haystack /home/user/haystack/
# Copy package files & models
COPY setup.py setup.cfg pyproject.toml VERSION.txt LICENSE README.md models* /home/user/
# Copy REST API code
COPY rest_api /home/user/rest_api
COPY rest_api /home/user/rest_api/

# Install package
RUN pip install --upgrade pip
Expand All @@ -33,8 +33,8 @@ RUN pip freeze
RUN python3 -c "from haystack.utils.docker import cache_models;cache_models()"

# create folder for /file-upload API endpoint with write permissions, this might be adjusted depending on FILE_UPLOAD_PATH
RUN mkdir -p /home/user/file-upload
RUN chmod 777 /home/user/file-upload
RUN mkdir -p /home/user/rest_api/file-upload
RUN chmod 777 /home/user/rest_api/file-upload

# optional : copy sqlite db if needed for testing
#COPY qa.db /home/user/
Expand Down
23 changes: 11 additions & 12 deletions Dockerfile-GPU
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ WORKDIR /home/user
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8

# create folder for /file-upload API endpoint with write permissions, this might be adjusted depending on FILE_UPLOAD_PATH
RUN mkdir -p /home/user/file-upload && chmod 777 /home/user/file-upload

# Install software dependencies
RUN apt-get update && apt-get install -y software-properties-common && \
add-apt-repository ppa:deadsnakes/ppa && \
Expand Down Expand Up @@ -36,24 +33,26 @@ RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
update-alternatives --set python3 /usr/bin/python3.7

# Copy Haystack code
COPY haystack /home/user/haystack
COPY haystack /home/user/haystack/
# Copy package files & models
COPY setup.py setup.cfg pyproject.toml VERSION.txt LICENSE README.md models* /home/user/
# Copy REST API code
COPY rest_api /home/user/

RUN pip install --upgrade pip
RUN echo "Install required packages" && \
# Install PyTorch for CUDA 11
pip3 install --no-cache-dir torch==1.10.1+cu111 -f https://download.pytorch.org/whl/torch_stable.html
COPY rest_api /home/user/rest_api/

# Install package
RUN pip install --no-cache .[docstores-gpu,crawler,preprocessing,ocr,ray]
RUN pip install --no-cache rest_api/
RUN pip install --upgrade pip
RUN pip install --no-cache-dir .[docstores-gpu,crawler,preprocessing,ocr,ray]
RUN pip install --no-cache-dir rest_api/
# Install PyTorch for CUDA 11
RUN pip3 install --no-cache-dir torch==1.10.1+cu111 -f https://download.pytorch.org/whl/torch_stable.html

# Cache Roberta and NLTK data
RUN python3 -c "from haystack.utils.docker import cache_models;cache_models()"

# create folder for /file-upload API endpoint with write permissions, this might be adjusted depending on FILE_UPLOAD_PATH
RUN mkdir -p /home/user/rest_api/file-upload
RUN chmod 777 /home/user/rest_api/file-upload

# optional : copy sqlite db if needed for testing
#COPY qa.db /home/user/

Expand Down
4 changes: 2 additions & 2 deletions docker-compose-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
- driver: nvidia
count: 1
capabilities: [gpu]
# Mount custom Pipeline YAML and custom Components.
# # Mount custom Pipeline YAML and custom Components.
# volumes:
# - ./rest_api/pipeline:/home/user/rest_api/pipeline
ports:
Expand Down Expand Up @@ -59,4 +59,4 @@ services:
- DEFAULT_QUESTION_AT_STARTUP
- DEFAULT_DOCS_FROM_RETRIEVER
- DEFAULT_NUMBER_OF_ANSWERS
command: "/bin/bash -c 'sleep 15 && streamlit run webapp.py'"
command: "/bin/bash -c 'sleep 15 && python -m streamlit run ui/webapp.py'"
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ services:
- DEFAULT_QUESTION_AT_STARTUP
- DEFAULT_DOCS_FROM_RETRIEVER
- DEFAULT_NUMBER_OF_ANSWERS
command: "/bin/bash -c 'sleep 15 && streamlit run webapp.py'"
command: "/bin/bash -c 'sleep 15 && python -m streamlit run ui/webapp.py'"
24 changes: 9 additions & 15 deletions rest_api/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,15 @@
logging.getLogger("elasticsearch").setLevel(logging.WARNING)
logging.getLogger("haystack").setLevel(logging.INFO)

try:
import uvicorn
from fastapi import FastAPI, HTTPException
from fastapi.routing import APIRoute
from fastapi.openapi.utils import get_openapi
from starlette.middleware.cors import CORSMiddleware

from rest_api.controller.errors.http_error import http_error_handler
from rest_api.config import ROOT_PATH
from rest_api.controller.router import router as api_router

except (ImportError, ModuleNotFoundError) as ie:
from haystack.utils.import_utils import _optional_component_not_installed

_optional_component_not_installed("rest_api", "rest", ie)
import uvicorn
from fastapi import FastAPI, HTTPException
from fastapi.routing import APIRoute
from fastapi.openapi.utils import get_openapi
from starlette.middleware.cors import CORSMiddleware

from rest_api.controller.errors.http_error import http_error_handler
from rest_api.config import ROOT_PATH
from rest_api.controller.router import router as api_router


def get_application() -> FastAPI:
Expand Down
12 changes: 7 additions & 5 deletions ui/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ WORKDIR /home/user
RUN apt-get update && apt-get install -y curl git pkg-config cmake

# copy code
COPY setup.py /home/user/
COPY utils.py /home/user/
COPY webapp.py /home/user/
RUN mkdir ui/
COPY setup.py /home/user/ui
COPY utils.py /home/user/ui
COPY webapp.py /home/user/ui
COPY eval_labels_example.csv /home/user/

# install as a package
RUN pip install .
RUN pip install --upgrade pip
RUN pip install ui/

EXPOSE 8501

# cmd for running the API
CMD ["streamlit", "run", "webapp.py"]
CMD ["python", "-m", "streamlit", "run", "ui/webapp.py"]
8 changes: 1 addition & 7 deletions ui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
import requests
from time import sleep
from uuid import uuid4

try:
import streamlit as st
except (ImportError, ModuleNotFoundError) as ie:
from haystack.utils.import_utils import _optional_component_not_installed

_optional_component_not_installed(__name__, "ui", ie)
import streamlit as st


API_ENDPOINT = os.getenv("API_ENDPOINT", "http:https://localhost:8000")
Expand Down
15 changes: 4 additions & 11 deletions ui/webapp.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import os
import sys

import logging
import pandas as pd
from json import JSONDecodeError
from pathlib import Path
import streamlit as st
from annotated_text import annotation
from markdown import markdown

try:
import streamlit as st
from annotated_text import annotation
from markdown import markdown

from ui.utils import haystack_is_ready, query, send_feedback, upload_doc, haystack_version, get_backlink
except (ImportError, ModuleNotFoundError) as ie:
from haystack.utils.import_utils import _optional_component_not_installed

_optional_component_not_installed(__name__, "ui", ie)
from ui.utils import haystack_is_ready, query, send_feedback, upload_doc, haystack_version, get_backlink


# Adjust to a question that you would like users to see in the search bar when they load the UI:
Expand Down

0 comments on commit 9dc89d2

Please sign in to comment.