mirror of
				https://github.com/deepset-ai/haystack.git
				synced 2025-10-31 09:49:48 +00:00 
			
		
		
		
	Fix dependency related build issues in Dockerfiles (#2135)
				
					
				
			* 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>
This commit is contained in:
		
							parent
							
								
									aca52ea39c
								
							
						
					
					
						commit
						9dc89d2bd2
					
				
							
								
								
									
										1
									
								
								.github/workflows/docker_build.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.github/workflows/docker_build.yml
									
									
									
									
										vendored
									
									
								
							| @ -1,6 +1,7 @@ | |||||||
| name: docker-build | name: docker-build | ||||||
| 
 | 
 | ||||||
| on: | on: | ||||||
|  |   workflow_dispatch: | ||||||
|   push: |   push: | ||||||
|     branches: |     branches: | ||||||
|       - master |       - master | ||||||
|  | |||||||
| @ -22,7 +22,7 @@ COPY haystack /home/user/haystack/ | |||||||
| # Copy package files & models | # Copy package files & models | ||||||
| COPY setup.py setup.cfg pyproject.toml VERSION.txt LICENSE README.md models* /home/user/ | COPY setup.py setup.cfg pyproject.toml VERSION.txt LICENSE README.md models* /home/user/ | ||||||
| # Copy REST API code | # Copy REST API code | ||||||
| COPY rest_api /home/user/rest_api | COPY rest_api /home/user/rest_api/ | ||||||
| 
 | 
 | ||||||
| # Install package | # Install package | ||||||
| RUN pip install --upgrade pip | RUN pip install --upgrade pip | ||||||
| @ -33,8 +33,8 @@ RUN pip freeze | |||||||
| RUN python3 -c "from haystack.utils.docker import cache_models;cache_models()" | 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 | # 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 mkdir -p /home/user/rest_api/file-upload | ||||||
| RUN chmod 777 /home/user/file-upload | RUN chmod 777 /home/user/rest_api/file-upload | ||||||
| 
 | 
 | ||||||
| # optional : copy sqlite db if needed for testing | # optional : copy sqlite db if needed for testing | ||||||
| #COPY qa.db /home/user/ | #COPY qa.db /home/user/ | ||||||
|  | |||||||
| @ -5,9 +5,6 @@ WORKDIR /home/user | |||||||
| ENV LC_ALL=C.UTF-8 | ENV LC_ALL=C.UTF-8 | ||||||
| ENV LANG=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 | # Install software dependencies | ||||||
| RUN apt-get update && apt-get install -y software-properties-common && \ | RUN apt-get update && apt-get install -y software-properties-common && \ | ||||||
|     add-apt-repository ppa:deadsnakes/ppa && \ |     add-apt-repository ppa:deadsnakes/ppa && \ | ||||||
| @ -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 |     update-alternatives --set python3 /usr/bin/python3.7 | ||||||
| 
 | 
 | ||||||
| # Copy Haystack code | # Copy Haystack code | ||||||
| COPY haystack /home/user/haystack | COPY haystack /home/user/haystack/ | ||||||
| # Copy package files & models | # Copy package files & models | ||||||
| COPY setup.py setup.cfg pyproject.toml VERSION.txt LICENSE README.md models* /home/user/ | COPY setup.py setup.cfg pyproject.toml VERSION.txt LICENSE README.md models* /home/user/ | ||||||
| # Copy REST API code | # Copy REST API code | ||||||
| COPY rest_api /home/user/ | COPY rest_api /home/user/rest_api/ | ||||||
| 
 |  | ||||||
| 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 |  | ||||||
| 
 | 
 | ||||||
| # Install package | # Install package | ||||||
| RUN pip install --no-cache .[docstores-gpu,crawler,preprocessing,ocr,ray] | RUN pip install --upgrade pip | ||||||
| RUN pip install --no-cache rest_api/ | 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 | # Cache Roberta and NLTK data | ||||||
| RUN python3 -c "from haystack.utils.docker import cache_models;cache_models()" | 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 | # optional : copy sqlite db if needed for testing | ||||||
| #COPY qa.db /home/user/ | #COPY qa.db /home/user/ | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -14,7 +14,7 @@ services: | |||||||
|           - driver: nvidia |           - driver: nvidia | ||||||
|             count: 1 |             count: 1 | ||||||
|             capabilities: [gpu] |             capabilities: [gpu] | ||||||
|     # Mount custom Pipeline YAML and custom Components. |     # # Mount custom Pipeline YAML and custom Components. | ||||||
|     # volumes: |     # volumes: | ||||||
|     #   - ./rest_api/pipeline:/home/user/rest_api/pipeline |     #   - ./rest_api/pipeline:/home/user/rest_api/pipeline | ||||||
|     ports: |     ports: | ||||||
| @ -59,4 +59,4 @@ services: | |||||||
|       - DEFAULT_QUESTION_AT_STARTUP |       - DEFAULT_QUESTION_AT_STARTUP | ||||||
|       - DEFAULT_DOCS_FROM_RETRIEVER |       - DEFAULT_DOCS_FROM_RETRIEVER | ||||||
|       - DEFAULT_NUMBER_OF_ANSWERS |       - 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'" | ||||||
|  | |||||||
| @ -48,4 +48,4 @@ services: | |||||||
|       - DEFAULT_QUESTION_AT_STARTUP |       - DEFAULT_QUESTION_AT_STARTUP | ||||||
|       - DEFAULT_DOCS_FROM_RETRIEVER |       - DEFAULT_DOCS_FROM_RETRIEVER | ||||||
|       - DEFAULT_NUMBER_OF_ANSWERS |       - 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'" | ||||||
|  | |||||||
| @ -5,21 +5,15 @@ logger = logging.getLogger(__name__) | |||||||
| logging.getLogger("elasticsearch").setLevel(logging.WARNING) | logging.getLogger("elasticsearch").setLevel(logging.WARNING) | ||||||
| logging.getLogger("haystack").setLevel(logging.INFO) | logging.getLogger("haystack").setLevel(logging.INFO) | ||||||
| 
 | 
 | ||||||
| try: | import uvicorn | ||||||
|     import uvicorn | from fastapi import FastAPI, HTTPException | ||||||
|     from fastapi import FastAPI, HTTPException | from fastapi.routing import APIRoute | ||||||
|     from fastapi.routing import APIRoute | from fastapi.openapi.utils import get_openapi | ||||||
|     from fastapi.openapi.utils import get_openapi | from starlette.middleware.cors import CORSMiddleware | ||||||
|     from starlette.middleware.cors import CORSMiddleware |  | ||||||
| 
 | 
 | ||||||
|     from rest_api.controller.errors.http_error import http_error_handler | from rest_api.controller.errors.http_error import http_error_handler | ||||||
|     from rest_api.config import ROOT_PATH | from rest_api.config import ROOT_PATH | ||||||
|     from rest_api.controller.router import router as api_router | 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) |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def get_application() -> FastAPI: | def get_application() -> FastAPI: | ||||||
|  | |||||||
| @ -5,15 +5,17 @@ WORKDIR /home/user | |||||||
| RUN apt-get update && apt-get install -y curl git pkg-config cmake | RUN apt-get update && apt-get install -y curl git pkg-config cmake | ||||||
| 
 | 
 | ||||||
| # copy code | # copy code | ||||||
| COPY setup.py /home/user/ | RUN mkdir ui/ | ||||||
| COPY utils.py /home/user/ | COPY setup.py /home/user/ui | ||||||
| COPY webapp.py /home/user/ | COPY utils.py /home/user/ui | ||||||
|  | COPY webapp.py /home/user/ui | ||||||
| COPY eval_labels_example.csv /home/user/ | COPY eval_labels_example.csv /home/user/ | ||||||
| 
 | 
 | ||||||
| # install as a package | # install as a package | ||||||
| RUN pip install . | RUN pip install --upgrade pip | ||||||
|  | RUN pip install ui/ | ||||||
| 
 | 
 | ||||||
| EXPOSE 8501 | EXPOSE 8501 | ||||||
| 
 | 
 | ||||||
| # cmd for running the API | # cmd for running the API | ||||||
| CMD ["streamlit", "run", "webapp.py"] | CMD ["python", "-m", "streamlit", "run", "ui/webapp.py"] | ||||||
|  | |||||||
| @ -5,13 +5,7 @@ import logging | |||||||
| import requests | import requests | ||||||
| from time import sleep | from time import sleep | ||||||
| from uuid import uuid4 | from uuid import uuid4 | ||||||
| 
 | import streamlit as st | ||||||
| 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) |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| API_ENDPOINT = os.getenv("API_ENDPOINT", "http://localhost:8000") | API_ENDPOINT = os.getenv("API_ENDPOINT", "http://localhost:8000") | ||||||
|  | |||||||
							
								
								
									
										15
									
								
								ui/webapp.py
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								ui/webapp.py
									
									
									
									
									
								
							| @ -1,21 +1,14 @@ | |||||||
| import os | import os | ||||||
| import sys | import sys | ||||||
| 
 |  | ||||||
| import logging | import logging | ||||||
| import pandas as pd | import pandas as pd | ||||||
| from json import JSONDecodeError | from json import JSONDecodeError | ||||||
| from pathlib import Path | from pathlib import Path | ||||||
|  | import streamlit as st | ||||||
|  | from annotated_text import annotation | ||||||
|  | from markdown import markdown | ||||||
| 
 | 
 | ||||||
| try: | from ui.utils import haystack_is_ready, query, send_feedback, upload_doc, haystack_version, get_backlink | ||||||
|     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) |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # Adjust to a question that you would like users to see in the search bar when they load the UI: | # Adjust to a question that you would like users to see in the search bar when they load the UI: | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Sara Zan
						Sara Zan