jatinmehra commited on
Commit
cd8b432
·
1 Parent(s): 4a3438f

Add Dockerfile and .dockerignore for CrawlGPT project setup

Browse files
Files changed (3) hide show
  1. .dockerignore +173 -0
  2. .gitignore +2 -0
  3. Dockerfile +77 -0
.dockerignore ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+ secrets.toml
139
+ .streamlit/
140
+
141
+ # Spyder project settings
142
+ .spyderproject
143
+ .spyproject
144
+
145
+ # Rope project settings
146
+ .ropeproject
147
+
148
+ # mkdocs documentation
149
+ /site
150
+
151
+ # mypy
152
+ .mypy_cache/
153
+ .dmypy.json
154
+ dmypy.json
155
+
156
+ # Pyre type checker
157
+ .pyre/
158
+
159
+ # pytype static type analyzer
160
+ .pytype/
161
+
162
+ # Cython debug symbols
163
+ cython_debug/
164
+
165
+ # PyCharm
166
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
167
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
168
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
169
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
170
+ #.idea/
171
+
172
+ # PyPI configuration file
173
+ .pypirc
.gitignore CHANGED
@@ -135,6 +135,8 @@ venv/
135
  ENV/
136
  env.bak/
137
  venv.bak/
 
 
138
 
139
  # Spyder project settings
140
  .spyderproject
 
135
  ENV/
136
  env.bak/
137
  venv.bak/
138
+ secrets.toml
139
+ .streamlit/
140
 
141
  # Spyder project settings
142
  .spyderproject
Dockerfile ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This Dockerfile is used to build a Docker image for the CrawlGPT project using Streamlit as the front-end
2
+ # Specifically for huggingface spaces
3
+
4
+ # Use Python 3.12 as base image
5
+ FROM python:3.12-slim
6
+
7
+ # Set working directory
8
+ WORKDIR /app
9
+
10
+ # Install system dependencies including Chrome/Playwright dependencies
11
+ RUN apt-get update && apt-get install -y \
12
+ build-essential \
13
+ curl \
14
+ software-properties-common \
15
+ sudo \
16
+ git \
17
+ && rm -rf /var/lib/apt/lists/*
18
+
19
+ # Create a non-root user and set permissions
20
+ RUN useradd -m -s /bin/bash appuser && \
21
+ echo "appuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
22
+ RUN mkdir -p /app/.crawl4ai && chown -R appuser:appuser /app/.crawl4ai
23
+ RUN mkdir -p /app/exports && chown -R appuser:appuser /app/exports
24
+
25
+ # Copy project files
26
+ COPY pyproject.toml setup_env.py ./
27
+ COPY src/ ./src/
28
+ COPY tests/ ./tests/
29
+
30
+ # Gotta tweak some things in our main core code (LLMBasedCrowler.py) Comment out the following line:
31
+ # from dotenv import load_dotenv # line 11 It is not needed in the docker container
32
+ # Because it's trying to load the API credentials from .env file which we don't have in the container
33
+
34
+
35
+ # Accept the secret token as a build argument
36
+ ARG GROQ_API_KEY
37
+ ARG OLLAMA_API_TOKEN
38
+
39
+ # Docs: https://huggingface.co/docs/hub/en/spaces-sdks-docker#secrets-and-variables-management
40
+
41
+ # Expose the secret GROQ_API_KEY and OLLAMA_API_TOKEN at build time and set them as environment variables
42
+ RUN --mount=type=secret,id=GROQ_API_KEY,mode=0444,required=true \
43
+ export GROQ_API_KEY=$(cat /run/secrets/GROQ_API_KEY) && \
44
+ echo "GROQ_API_KEY is set."
45
+
46
+ RUN --mount=type=secret,id=OLLAMA_API_TOKEN,mode=0444,required=true \
47
+ export OLLAMA_API_TOKEN=$(cat /run/secrets/OLLAMA_API_TOKEN) && \
48
+ echo "OLLAMA_API_TOKEN is set."
49
+
50
+ # Set environment variables using the build arguments
51
+ ENV OLLAMA_API_TOKEN=${OLLAMA_API_TOKEN}
52
+ ENV GROQ_API_KEY=${GROQ_API_KEY}
53
+
54
+ # Install Python dependencies
55
+ RUN pip install --no-cache-dir -e .
56
+ RUN pip install --no-cache-dir pytest pytest-mockito black isort flake8
57
+
58
+ # Set environment variables
59
+ ENV PYTHONPATH=/app
60
+ ENV PATH="/app/src:${PATH}"
61
+
62
+ # Switch to non-root user
63
+ USER appuser
64
+
65
+ # Allow appuser to install Python packages locally (user-level installations)
66
+ ENV PATH="/home/appuser/.local/bin:${PATH}"
67
+ RUN mkdir -p /home/appuser/.local && chown -R appuser:appuser /home/appuser
68
+
69
+ # Install Playwright and dependencies
70
+ RUN playwright install
71
+ RUN playwright install-deps
72
+
73
+ # Expose Streamlit port
74
+ EXPOSE 7860
75
+
76
+ # Set default command to run the Streamlit app
77
+ CMD ["python", "-m", "streamlit", "run", "src/crawlgpt/ui/chat_app.py", "--server.port=7860", "--server.address=0.0.0.0"]