forked from LiveCarta/CommentAutomation
Added entrypoint, changed Dockerfile to multi-target variant
This commit is contained in:
33
Dockerfile
33
Dockerfile
@@ -1,18 +1,41 @@
|
|||||||
FROM python:3.12-slim
|
FROM python:3.12-slim AS base
|
||||||
|
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||||
PYTHONUNBUFFERED=1 \
|
PYTHONUNBUFFERED=1 \
|
||||||
UV_LINK_MODE=copy
|
UV_LINK_MODE=copy \
|
||||||
|
PYTHONPATH=/app/src
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN pip install --no-cache-dir uv
|
RUN pip install --no-cache-dir uv
|
||||||
|
|
||||||
COPY pyproject.toml ./
|
COPY pyproject.toml uv.lock ./
|
||||||
RUN uv sync --no-install-project
|
|
||||||
|
|
||||||
|
FROM base AS local_test
|
||||||
|
|
||||||
|
RUN uv sync --all-groups --no-install-project
|
||||||
|
|
||||||
COPY src ./src
|
COPY src ./src
|
||||||
|
COPY tests ./tests
|
||||||
|
COPY entrypoint.sh ./entrypoint.sh
|
||||||
|
RUN chmod +x ./entrypoint.sh
|
||||||
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
CMD ["uv", "run", "uvicorn", "comment_automation.main:app", "--app-dir", "src", "--host", "0.0.0.0", "--port", "8000"]
|
ENTRYPOINT ["./entrypoint.sh"]
|
||||||
|
CMD ["http"]
|
||||||
|
|
||||||
|
|
||||||
|
FROM base AS production
|
||||||
|
|
||||||
|
RUN uv sync --no-dev --no-install-project
|
||||||
|
|
||||||
|
COPY src ./src
|
||||||
|
COPY entrypoint.sh ./entrypoint.sh
|
||||||
|
RUN chmod +x ./entrypoint.sh
|
||||||
|
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
ENTRYPOINT ["./entrypoint.sh"]
|
||||||
|
CMD ["http"]
|
||||||
|
|||||||
26
README.md
26
README.md
@@ -56,3 +56,29 @@ uv run celery -A comment_automation.celery_app:celery_app worker --loglevel=info
|
|||||||
Without uv (venv already created):
|
Without uv (venv already created):
|
||||||
|
|
||||||
./.venv/bin/celery -A comment_automation.celery_app:celery_app worker --loglevel=info
|
./.venv/bin/celery -A comment_automation.celery_app:celery_app worker --loglevel=info
|
||||||
|
|
||||||
|
## Docker targets and entrypoint modes
|
||||||
|
|
||||||
|
The container uses entrypoint.sh and supports two main modes:
|
||||||
|
|
||||||
|
- http: starts the FastAPI app.
|
||||||
|
- celery: starts the Celery worker.
|
||||||
|
|
||||||
|
Build local/test target (installs all dependency groups):
|
||||||
|
|
||||||
|
docker build --target local_test -t comment-automation:local .
|
||||||
|
|
||||||
|
Build production target (installs only non-dev dependencies):
|
||||||
|
|
||||||
|
docker build --target production -t comment-automation:prod .
|
||||||
|
|
||||||
|
Run HTTP app (default mode):
|
||||||
|
|
||||||
|
docker run --rm -p 8000:8000 comment-automation:prod
|
||||||
|
|
||||||
|
Run Celery worker mode:
|
||||||
|
|
||||||
|
docker run --rm \
|
||||||
|
-e CELERY_BROKER_URL=redis://host.docker.internal:6379/0 \
|
||||||
|
-e CELERY_RESULT_BACKEND=redis://host.docker.internal:6379/0 \
|
||||||
|
comment-automation:prod celery
|
||||||
|
|||||||
24
entrypoint.sh
Normal file
24
entrypoint.sh
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
mode="${1:-http}"
|
||||||
|
|
||||||
|
case "$mode" in
|
||||||
|
http)
|
||||||
|
shift || true
|
||||||
|
exec uv run uvicorn comment_automation.main:app \
|
||||||
|
--app-dir src \
|
||||||
|
--host 0.0.0.0 \
|
||||||
|
--port 8000 \
|
||||||
|
"$@"
|
||||||
|
;;
|
||||||
|
celery)
|
||||||
|
shift || true
|
||||||
|
exec uv run celery -A comment_automation.celery_app:celery_app worker \
|
||||||
|
--loglevel "${CELERY_LOG_LEVEL:-info}" \
|
||||||
|
"$@"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
exec "$@"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
Reference in New Issue
Block a user