Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging Changes for #161 #162

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/fly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Deploy Production App
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy -c fly.toml --app bloom-bot --remote-only
env:
Expand All @@ -20,8 +20,8 @@ jobs:
name: Deploy Staging App
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy -c fly.toml --app tutor-gpt --remote-only
- run: flyctl deploy -c fly.toml --app bloom-staging --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
56 changes: 31 additions & 25 deletions Dockerfile
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"]
7 changes: 5 additions & 2 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dotenv import load_dotenv
from api.routers import conversation, chat, messages

load_dotenv()
load_dotenv(override=True)

SENTRY_DSN = os.getenv("SENTRY_DN")

Expand All @@ -20,9 +20,12 @@

app = FastAPI()

URL = os.getenv("URL", "http://localhost:3000")
print("URL:", URL)

app.add_middleware(
CORSMiddleware,
allow_origin_regex=os.environ["URL"],
allow_origin_regex=URL,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
Expand Down
25 changes: 16 additions & 9 deletions fly.toml
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
Loading