feat: Docker Workflow for Tags and Main (#61)
* fix: patching error handling and error handling in routes * Docker Github Action
This commit is contained in:
parent
6c31fed873
commit
5689973b01
|
|
@ -7,3 +7,8 @@ docs/**
|
|||
supabase/**
|
||||
LICENSE
|
||||
__pycache__
|
||||
docker-compose.yml.example
|
||||
.github/**
|
||||
.vscode/**
|
||||
data/**
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
name: Build and Push Docker Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- v*
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_NAME: ${{ github.repository }}
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
packages: write
|
||||
contents: read
|
||||
attestations: write
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@3
|
||||
with:
|
||||
platforms: linux/amd64, linux/arm64
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.registry }}/${{ env.image_name }}
|
||||
tags: |
|
||||
type=ref,event=tag
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
- name: Log in to GitHub Container Registry
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Build and Push
|
||||
id: push
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
- name: Generate artifact attestation
|
||||
uses: actions/attest-build-provenance@v1
|
||||
with:
|
||||
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
subject-digest: ${{ steps.push.outputs.digest }}
|
||||
push-to-registry: true
|
||||
|
|
@ -33,6 +33,8 @@ USER app
|
|||
|
||||
COPY --chown=app:app src/ /app/src/
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
# https://stackoverflow.com/questions/29663459/python-app-does-not-print-anything-when-running-detached-in-docker
|
||||
CMD ["python", "-m", "uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -7,15 +7,15 @@ readme = "README.md"
|
|||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.9"
|
||||
fastapi = "^0.109.0"
|
||||
uvicorn = "^0.24.0.post1"
|
||||
fastapi = "^0.111.0"
|
||||
uvicorn = "^0.29.0"
|
||||
python-dotenv = "^1.0.0"
|
||||
sqlalchemy = "^2.0.25"
|
||||
slowapi = "^0.1.8"
|
||||
fastapi-pagination = "^0.12.14"
|
||||
sqlalchemy = "^2.0.30"
|
||||
slowapi = "^0.1.9"
|
||||
fastapi-pagination = "^0.12.24"
|
||||
pgvector = "^0.2.5"
|
||||
openai = "^1.12.0"
|
||||
sentry-sdk = {extras = ["fastapi", "sqlalchemy"], version = "^1.40.5"}
|
||||
sentry-sdk = "^2.3.0"
|
||||
opentelemetry-instrumentation-fastapi = "^0.44b0"
|
||||
opentelemetry-api = "^1.23.0"
|
||||
opentelemetry-sdk = "^1.23.0"
|
||||
|
|
@ -23,11 +23,11 @@ opentelemetry-exporter-otlp = "^1.23.0"
|
|||
opentelemetry-instrumentation-sqlalchemy = "^0.44b0"
|
||||
opentelemetry-instrumentation-logging = "^0.44b0"
|
||||
greenlet = "^3.0.3"
|
||||
psycopg = {extras = ["binary"], version = "^3.1.18"}
|
||||
psycopg = {extras= ["binary"], version="^3.1.19"}
|
||||
httpx = "^0.27.0"
|
||||
uvloop = "^0.19.0"
|
||||
httptools = "^0.6.1"
|
||||
mirascope = {extras = ["openai"], version = "^0.12.3"}
|
||||
mirascope = "^0.14.0"
|
||||
|
||||
[tool.ruff.lint]
|
||||
# from https://docs.astral.sh/ruff/linter/#rule-selection example
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ async def delete_session(
|
|||
result = await db.execute(stmt)
|
||||
honcho_session = result.scalar_one_or_none()
|
||||
if honcho_session is None:
|
||||
return False
|
||||
raise ValueError("Session not found or does not belong to user")
|
||||
honcho_session.is_active = False
|
||||
await db.commit()
|
||||
return True
|
||||
|
|
@ -627,7 +627,7 @@ async def delete_collection(
|
|||
result = await db.execute(stmt)
|
||||
honcho_collection = result.scalar_one_or_none()
|
||||
if honcho_collection is None:
|
||||
return False
|
||||
raise ValueError("collection not found or does not belong to user")
|
||||
await db.delete(honcho_collection)
|
||||
await db.commit()
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -174,12 +174,12 @@ async def delete_collection(
|
|||
db=db,
|
||||
auth=Depends(auth),
|
||||
):
|
||||
response = await crud.delete_collection(
|
||||
db, app_id=app_id, user_id=user_id, collection_id=collection_id
|
||||
)
|
||||
if response:
|
||||
try:
|
||||
await crud.delete_collection(
|
||||
db, app_id=app_id, user_id=user_id, collection_id=collection_id
|
||||
)
|
||||
return {"message": "Collection deleted successfully"}
|
||||
else:
|
||||
except ValueError:
|
||||
raise HTTPException(
|
||||
status_code=404, detail="collection not found or does not belong to user"
|
||||
)
|
||||
) from None
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ async def get_message(
|
|||
db, app_id=app_id, session_id=session_id, user_id=user_id, message_id=message_id
|
||||
)
|
||||
if honcho_message is None:
|
||||
raise HTTPException(status_code=404, detail="Session not found")
|
||||
raise HTTPException(status_code=404, detail="Message not found")
|
||||
return honcho_message
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -83,10 +83,13 @@ async def create_session(
|
|||
schemas.Session: The Session object of the new Session
|
||||
|
||||
"""
|
||||
value = await crud.create_session(
|
||||
db, app_id=app_id, user_id=user_id, session=session
|
||||
)
|
||||
return value
|
||||
try:
|
||||
value = await crud.create_session(
|
||||
db, app_id=app_id, user_id=user_id, session=session
|
||||
)
|
||||
return value
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e)) from e
|
||||
|
||||
|
||||
@router.put("/{session_id}", response_model=schemas.Session)
|
||||
|
|
@ -146,13 +149,13 @@ async def delete_session(
|
|||
HTTPException: If the session is not found
|
||||
|
||||
"""
|
||||
response = await crud.delete_session(
|
||||
db, app_id=app_id, user_id=user_id, session_id=session_id
|
||||
)
|
||||
if response:
|
||||
try:
|
||||
await crud.delete_session(
|
||||
db, app_id=app_id, user_id=user_id, session_id=session_id
|
||||
)
|
||||
return {"message": "Session deleted successfully"}
|
||||
else:
|
||||
raise HTTPException(status_code=404, detail="Session not found")
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail="Session not found") from e
|
||||
|
||||
|
||||
@router.get("/{session_id}", response_model=schemas.Session)
|
||||
|
|
|
|||
|
|
@ -92,7 +92,10 @@ async def get_user_by_name(
|
|||
schemas.User: User object
|
||||
|
||||
"""
|
||||
return await crud.get_user_by_name(db, app_id=app_id, name=name)
|
||||
user = await crud.get_user_by_name(db, app_id=app_id, name=name)
|
||||
if user is None:
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
return user
|
||||
|
||||
|
||||
@router.get("/{user_id}", response_model=schemas.User)
|
||||
|
|
@ -114,7 +117,10 @@ async def get_user(
|
|||
schemas.User: User object
|
||||
|
||||
"""
|
||||
return await crud.get_user(db, app_id=app_id, user_id=user_id)
|
||||
user = await crud.get_user(db, app_id=app_id, user_id=user_id)
|
||||
if user is None:
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
return user
|
||||
|
||||
|
||||
@router.get("/get_or_create/{name}", response_model=schemas.User)
|
||||
|
|
@ -161,4 +167,7 @@ async def update_user(
|
|||
schemas.User: Updated User object
|
||||
|
||||
"""
|
||||
return await crud.update_user(db, app_id=app_id, user_id=user_id, user=user)
|
||||
try:
|
||||
return await crud.update_user(db, app_id=app_id, user_id=user_id, user=user)
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=406, detail=str(e)) from e
|
||||
|
|
|
|||
Loading…
Reference in New Issue