Spaces:
Runtime error
Runtime error
Soutrik
commited on
Commit
•
7c37fc5
1
Parent(s):
0f27535
added: docker compose
Browse files- Dockerfile +42 -29
- docker-compose.yaml +54 -66
- main.py +2 -27
- src/train.py +1 -5
- src/utils/logging_utils.py +1 -1
Dockerfile
CHANGED
@@ -1,35 +1,48 @@
|
|
1 |
-
#
|
2 |
-
FROM python:3.10.15-slim
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
# Set working directory
|
18 |
WORKDIR /app
|
19 |
|
20 |
-
# Copy
|
21 |
-
COPY pyproject.toml poetry.lock
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
# Install dependencies
|
24 |
-
RUN poetry install --no-root
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
-
#
|
32 |
-
|
33 |
|
34 |
-
#
|
35 |
-
CMD ["
|
|
|
1 |
+
# Stage 1: Build environment with Poetry and dependencies
|
2 |
+
FROM python:3.10.15-slim as builder
|
3 |
+
|
4 |
+
LABEL maintainer="Soutrik soutrik1991@gmail.com" \
|
5 |
+
description="Docker image for running a Python app with dependencies managed by Poetry."
|
6 |
+
|
7 |
+
# Install Poetry and necessary system dependencies
|
8 |
+
RUN apt-get update && apt-get install -y --no-install-recommends curl && \
|
9 |
+
curl -sSL https://install.python-poetry.org | python3 - && \
|
10 |
+
apt-get clean && rm -rf /var/lib/apt/lists/*
|
11 |
+
|
12 |
+
# Add Poetry to the PATH explicitly
|
13 |
+
ENV PATH="/root/.local/bin:$PATH"
|
14 |
+
|
15 |
+
# Set the working directory to /app
|
|
|
|
|
16 |
WORKDIR /app
|
17 |
|
18 |
+
# Copy pyproject.toml and poetry.lock to install dependencies
|
19 |
+
COPY pyproject.toml poetry.lock /app/
|
20 |
+
|
21 |
+
# Configure Poetry environment
|
22 |
+
ENV POETRY_NO_INTERACTION=1 \
|
23 |
+
POETRY_VIRTUALENVS_IN_PROJECT=1 \
|
24 |
+
POETRY_CACHE_DIR=/tmp/poetry_cache
|
25 |
|
26 |
+
# Install dependencies without installing the package itself
|
27 |
+
RUN --mount=type=cache,target=/tmp/poetry_cache poetry install --only main --no-root
|
28 |
|
29 |
+
# Stage 2: Runtime environment
|
30 |
+
FROM python:3.10.15-slim as runner
|
31 |
+
|
32 |
+
# Copy application source code and necessary files
|
33 |
+
COPY src /app/src
|
34 |
+
COPY configs /app/configs
|
35 |
+
COPY .project-root /app/.project-root
|
36 |
+
COPY main.py /app/main.py
|
37 |
+
|
38 |
+
# Copy virtual environment from the builder stage
|
39 |
+
COPY --from=builder /app/.venv /app/.venv
|
40 |
+
|
41 |
+
# Set the working directory to /app
|
42 |
+
WORKDIR /app
|
43 |
|
44 |
+
# Set the environment path to use the virtual environment
|
45 |
+
ENV PATH="/app/.venv/bin:$PATH"
|
46 |
|
47 |
+
# Default command
|
48 |
+
CMD ["python", "-m", "main"]
|
docker-compose.yaml
CHANGED
@@ -1,81 +1,69 @@
|
|
1 |
version: '3.8'
|
2 |
|
3 |
services:
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
DOCKER_ENV: 1
|
11 |
-
ports:
|
12 |
-
- "5432:5432"
|
13 |
volumes:
|
14 |
-
-
|
15 |
-
|
16 |
-
-
|
17 |
-
|
18 |
-
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
|
19 |
-
interval: 30s
|
20 |
-
timeout: 10s
|
21 |
-
retries: 5
|
22 |
-
|
23 |
-
redis:
|
24 |
-
image: redis/redis-stack:latest
|
25 |
-
ports:
|
26 |
-
- "6379:6379"
|
27 |
-
- "8001:8001"
|
28 |
environment:
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
networks:
|
33 |
-
-
|
34 |
-
|
35 |
-
|
36 |
-
interval: 30s
|
37 |
-
timeout: 5s
|
38 |
-
retries: 5
|
39 |
|
40 |
-
|
41 |
-
image: mher/flower:0.9.7
|
42 |
-
environment:
|
43 |
-
DOCKER_ENV: 1
|
44 |
-
command: ["flower", "--broker=${BROKER_URL}", "--port=5555"]
|
45 |
-
ports:
|
46 |
-
- 5557:5555
|
47 |
-
depends_on:
|
48 |
-
- redis
|
49 |
-
networks:
|
50 |
-
- my_network
|
51 |
-
|
52 |
-
app:
|
53 |
build:
|
54 |
context: .
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
environment:
|
57 |
-
-
|
58 |
-
-
|
59 |
-
|
60 |
-
- FLOWER_BASIC_AUTH=${FLOWER_BASIC_AUTH}
|
61 |
-
- POSTGRES_DB=${POSTGRES_DB}
|
62 |
-
- POSTGRES_USER=${POSTGRES_USER}
|
63 |
-
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
64 |
-
- DOCKER_ENV=1
|
65 |
-
depends_on:
|
66 |
-
postgres:
|
67 |
-
condition: service_healthy
|
68 |
-
redis:
|
69 |
-
condition: service_healthy
|
70 |
networks:
|
71 |
-
-
|
72 |
-
|
73 |
-
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
volumes:
|
77 |
-
|
|
|
|
|
|
|
78 |
|
79 |
networks:
|
80 |
-
|
81 |
-
driver: bridge
|
|
|
1 |
version: '3.8'
|
2 |
|
3 |
services:
|
4 |
+
train:
|
5 |
+
build:
|
6 |
+
context: .
|
7 |
+
command: |
|
8 |
+
python -m src.train experiment=catdog_experiment ++task_name=train ++train=True ++test=False && \
|
9 |
+
touch /app/checkpoints/train_done.flag
|
|
|
|
|
|
|
10 |
volumes:
|
11 |
+
- ./data:/app/data
|
12 |
+
- ./checkpoints:/app/checkpoints
|
13 |
+
- ./artifacts:/app/artifacts
|
14 |
+
- ./logs:/app/logs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
environment:
|
16 |
+
- PYTHONUNBUFFERED=1
|
17 |
+
- PYTHONPATH=/app
|
18 |
+
shm_size: '4g'
|
19 |
networks:
|
20 |
+
- default
|
21 |
+
env_file:
|
22 |
+
- .env
|
|
|
|
|
|
|
23 |
|
24 |
+
eval:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
build:
|
26 |
context: .
|
27 |
+
command: |
|
28 |
+
sh -c 'while [ ! -f ./checkpoints/train_done.flag ]; do sleep 10; done && python -m src.train experiment=catdog_experiment ++task_name=eval ++train=False ++test=True'
|
29 |
+
volumes:
|
30 |
+
- ./data:/app/data
|
31 |
+
- ./checkpoints:/app/checkpoints
|
32 |
+
- ./artifacts:/app/artifacts
|
33 |
+
- ./logs:/app/logs
|
34 |
environment:
|
35 |
+
- PYTHONUNBUFFERED=1
|
36 |
+
- PYTHONPATH=/app
|
37 |
+
shm_size: '4g'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
networks:
|
39 |
+
- default
|
40 |
+
env_file:
|
41 |
+
- .env
|
42 |
+
|
43 |
+
# inference:
|
44 |
+
# build:
|
45 |
+
# context: .
|
46 |
+
# command: |
|
47 |
+
# sh -c 'while [ ! -f ./checkpoints/train_done.flag ]; do sleep 10; done && python -m src.infer experiment=catdog_experiment'
|
48 |
+
# volumes:
|
49 |
+
# - ./data:/app/data
|
50 |
+
# - ./checkpoints:/app/checkpoints
|
51 |
+
# - ./artifacts:/app/artifacts
|
52 |
+
# - ./logs:/app/logs
|
53 |
+
# environment:
|
54 |
+
# - PYTHONUNBUFFERED=1
|
55 |
+
# - PYTHONPATH=/app
|
56 |
+
# shm_size: '4g'
|
57 |
+
# networks:
|
58 |
+
# - default
|
59 |
+
# env_file:
|
60 |
+
# - .env
|
61 |
|
62 |
volumes:
|
63 |
+
data:
|
64 |
+
checkpoints:
|
65 |
+
artifacts:
|
66 |
+
logs:
|
67 |
|
68 |
networks:
|
69 |
+
default:
|
|
main.py
CHANGED
@@ -1,28 +1,3 @@
|
|
1 |
-
from
|
2 |
-
from app.api import chat
|
3 |
-
from app.db.database import Base, engine
|
4 |
-
from app.core.config import settings
|
5 |
-
from aiocache import caches
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
# Create tables on startup
|
11 |
-
@app.on_event("startup")
|
12 |
-
async def startup():
|
13 |
-
async with engine.begin() as conn:
|
14 |
-
await conn.run_sync(Base.metadata.create_all)
|
15 |
-
|
16 |
-
# Configure aiocache with in-memory backend
|
17 |
-
caches.set_config(
|
18 |
-
{
|
19 |
-
"default": {
|
20 |
-
"cache": settings.cache_backend,
|
21 |
-
"ttl": 300, # Default Time-To-Live for cache entries (in seconds)
|
22 |
-
}
|
23 |
-
}
|
24 |
-
)
|
25 |
-
|
26 |
-
|
27 |
-
# Include the chat route
|
28 |
-
app.include_router(chat.router)
|
|
|
1 |
+
from loguru import logger
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
logger.info("Hello, World!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/train.py
CHANGED
@@ -23,12 +23,8 @@ import rootutils
|
|
23 |
load_dotenv(find_dotenv(".env"))
|
24 |
|
25 |
# Setup root directory
|
26 |
-
try:
|
27 |
-
root = rootutils.setup_root(__file__, indicator=".project-root")
|
28 |
-
except Exception as e:
|
29 |
-
root = os.getcwd()
|
30 |
|
31 |
-
|
32 |
|
33 |
|
34 |
def initialize_callbacks(cfg: DictConfig) -> List[L.Callback]:
|
|
|
23 |
load_dotenv(find_dotenv(".env"))
|
24 |
|
25 |
# Setup root directory
|
|
|
|
|
|
|
|
|
26 |
|
27 |
+
root = rootutils.setup_root(__file__, indicator=".project-root")
|
28 |
|
29 |
|
30 |
def initialize_callbacks(cfg: DictConfig) -> List[L.Callback]:
|
src/utils/logging_utils.py
CHANGED
@@ -15,7 +15,7 @@ def setup_logger(log_file):
|
|
15 |
sys.stderr,
|
16 |
format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>",
|
17 |
)
|
18 |
-
logger.add(log_file, rotation="1MB")
|
19 |
|
20 |
|
21 |
def task_wrapper(func):
|
|
|
15 |
sys.stderr,
|
16 |
format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>",
|
17 |
)
|
18 |
+
logger.add(log_file, rotation="1MB", retention="7 days", encoding="utf-8")
|
19 |
|
20 |
|
21 |
def task_wrapper(func):
|