diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..06e0a65 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,88 @@ +name: Release - Build & Push Containers + +on: + push: + branches: + - main + paths: + - 'apps/**' + - '.containers/python/Dockerfile' + - 'packages/**' + - 'pyproject.toml' + - 'uv.lock' + +env: + REGISTRY: gitea.ia-innovacion.work + REGISTRY_PATH: innovacion/mayacontigo + +jobs: + detect-changes: + runs-on: ubuntu-latest + outputs: + changed-apps: ${{ steps.detect.outputs.changed-apps }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Detect changed apps + id: detect + run: | + # Get list of changed apps compared to previous commit + if [ "${{ github.event.before }}" = "0000000000000000000000000000000000000000" ]; then + # Initial push - build all apps + CHANGED_APPS=$(ls -d apps/*/ | sed 's|apps/||g' | sed 's|/||g' | jq -R -s -c 'split("\n")[:-1]') + else + # Compare with previous commit + CHANGED_APPS=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep '^apps/' | cut -d/ -f2 | sort -u | jq -R -s -c 'split("\n") | map(select(length > 0))') + fi + + echo "changed-apps=$CHANGED_APPS" >> $GITHUB_OUTPUT + echo "Changed apps: $CHANGED_APPS" + + build-and-push: + needs: detect-changes + if: needs.detect-changes.outputs.changed-apps != '[]' + runs-on: ubuntu-latest + strategy: + matrix: + app: ${{ fromJson(needs.detect-changes.outputs.changed-apps) }} + fail-fast: false + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Gitea Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.GITEA_REGISTRY_USERNAME }} + password: ${{ secrets.GITEA_REGISTRY_PASSWORD }} + + - name: Extract metadata + id: meta + run: | + IMAGE="${{ env.REGISTRY }}/${{ env.REGISTRY_PATH }}-${{ matrix.app }}" + echo "image=$IMAGE" >> $GITHUB_OUTPUT + echo "tags=$IMAGE:latest,$IMAGE:${{ github.sha }}" >> $GITHUB_OUTPUT + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + file: .containers/python/Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + build-args: | + PACKAGE=${{ matrix.app }} + cache-from: type=registry,ref=${{ steps.meta.outputs.image }}:buildcache + cache-to: type=registry,ref=${{ steps.meta.outputs.image }}:buildcache,mode=max + + - name: Image summary + run: | + echo "### ✅ Built and pushed: ${{ matrix.app }}" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "Image: ${{ steps.meta.outputs.image }}" >> $GITHUB_STEP_SUMMARY + echo "Tags: latest, ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY diff --git a/apps/inversionistas/api/server.py b/apps/inversionistas/api/server.py index e9b39c3..0c74fb9 100644 --- a/apps/inversionistas/api/server.py +++ b/apps/inversionistas/api/server.py @@ -6,8 +6,8 @@ from fastapi.responses import StreamingResponse from pydantic import BaseModel from . import services -from .config import config from .agent import MayaInversionistas +from .config import config @asynccontextmanager @@ -49,5 +49,12 @@ async def send(message: Message, stream: bool = False): generator = sse_stream(agent, message.prompt, message.conversation_id) return StreamingResponse(generator, media_type="text/event-stream") else: - response = await services.generate(agent, message.prompt, message.conversation_id) + response = await services.generate( + agent, message.prompt, message.conversation_id + ) return response + + +@app.get("/") +async def health(): + return {"status": "ok"}