-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(deployment) Docker and fly settings
- Loading branch information
1 parent
fa31a4e
commit 147699e
Showing
4 changed files
with
55 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,46 @@ | ||
# https://pythonspeed.com/articles/base-image-python-docker-images/ | ||
# https://testdriven.io/blog/docker-best-practices/ | ||
FROM python:3.10-slim-bullseye | ||
FROM python:3.11-slim-bullseye | ||
|
||
RUN apt-get update && apt-get install -y build-essential | ||
COPY --from=ghcr.io/astral-sh/uv:0.4.9 /uv /bin/uv | ||
|
||
# Set Working directory | ||
WORKDIR /app | ||
|
||
# https://stackoverflow.com/questions/53835198/integrating-python-poetry-with-docker | ||
ENV PYTHONFAULTHANDLER=1 \ | ||
PYTHONUNBUFFERED=1 \ | ||
PYTHONHASHSEED=random \ | ||
PIP_NO_CACHE_DIR=off \ | ||
PIP_DISABLE_PIP_VERSION_CHECK=on \ | ||
PIP_DEFAULT_TIMEOUT=100 \ | ||
POETRY_VERSION=1.4.1 | ||
RUN addgroup --system app && adduser --system --group app | ||
RUN chown -R app:app /app | ||
USER app | ||
|
||
# Enable bytecode compilation | ||
ENV UV_COMPILE_BYTECODE=1 | ||
|
||
# Copy from the cache instead of linking since it's a mounted volume | ||
ENV UV_LINK_MODE=copy | ||
|
||
RUN pip install "poetry==$POETRY_VERSION" | ||
# Install the project's dependencies using the lockfile and settings | ||
RUN --mount=type=cache,target=/root/.cache/uv \ | ||
--mount=type=bind,source=uv.lock,target=uv.lock \ | ||
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \ | ||
--mount=type=bind,source=api/,target=api/ \ | ||
--mount=type=bind,source=agent/,target=agent/ \ | ||
--mount=type=bind,source=bot/,target=bot/ \ | ||
uv sync --frozen --no-dev | ||
|
||
# Copy only requirements to cache them in docker layer | ||
WORKDIR /app | ||
COPY poetry.lock pyproject.toml /app/ | ||
COPY --chown=app:app uv.lock /app/ | ||
COPY --chown=app:app pyproject.toml /app/ | ||
|
||
# Project initialization: | ||
RUN poetry config virtualenvs.create false \ | ||
&& poetry install --no-root --no-interaction --no-ansi --without dev | ||
# Place executables in the environment at the front of the path | ||
ENV PATH="/app/.venv/bin:$PATH" | ||
|
||
WORKDIR /app | ||
EXPOSE 8000 | ||
|
||
RUN addgroup --system app && adduser --system --group app | ||
USER app | ||
COPY --chown=app:app agent/ /app/agent/ | ||
COPY --chown=app:app bot/ /app/bot/ | ||
COPY --chown=app:app api/ /app/api/ | ||
|
||
COPY agent/ agent/ | ||
COPY common/ common/ | ||
COPY bot/ bot/ | ||
COPY api/ api/ | ||
# RUN --mount=type=cache,target=/root/.cache/uv \ | ||
RUN uv pip install -r /app/api/pyproject.toml | ||
|
||
# https://stackoverflow.com/questions/29663459/python-app-does-not-print-anything-when-running-detached-in-docker | ||
CMD ["python", "-m", "uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8000"] | ||
# CMD ["python", "-u", "-m", "bot.app"] | ||
CMD ["fastapi", "run", "--host", "0.0.0.0", "api/main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,33 @@ | ||
# fly.toml app configuration file generated for vineeth-test-py on 2023-09-09T17:18:22-04:00 | ||
# fly.toml app configuration file generated for bloom-staging on 2024-10-22T01:01:35-04:00 | ||
# | ||
# See https://fly.io/docs/reference/configuration/ for information about how to use this file. | ||
# | ||
primary_region = "bos" | ||
kill_signal = "SIGINT" | ||
kill_timeout = "5s" | ||
primary_region = 'bos' | ||
kill_signal = 'SIGINT' | ||
kill_timeout = '5s' | ||
|
||
[experimental] | ||
auto_rollback = true | ||
|
||
[build] | ||
|
||
[processes] | ||
discord = "python -u -m bot.app" | ||
api = "python -m uvicorn api.main:app --host 0.0.0.0 --port 8000" | ||
api = 'fastapi run api/main.py --host 0.0.0.0 --port 8000' | ||
|
||
[http_service] | ||
internal_port = 8000 | ||
force_https = true | ||
auto_stop_machines = true | ||
auto_stop_machines = 'stop' | ||
auto_start_machines = true | ||
min_machines_running = 1 | ||
processes = ["api"] | ||
processes = ['api'] | ||
|
||
[http_service.concurrency] | ||
type = "requests" | ||
type = 'requests' | ||
hard_limit = 250 | ||
soft_limit = 200 | ||
|
||
[[vm]] | ||
memory = '1gb' | ||
cpu_kind = 'shared' | ||
cpus = 1 |