From 78a7acbe3e7a103ad35becca4673951204e2fee5 Mon Sep 17 00:00:00 2001 From: Anibal Angulo Date: Sat, 27 Sep 2025 03:33:29 +0000 Subject: [PATCH] Add CI --- .github/workflows/ci.yaml | 31 ++++++++++++++++ .github/workflows/deploy.yaml | 64 ++++++++++++++++++++++++++++++++++ .github/workflows/release.yaml | 36 +++++++++++++++++++ .k8s/deployment.yaml | 24 +++++++++++++ Dockerfile | 29 +++++++++++++++ pyproject.toml | 4 +++ 6 files changed, 188 insertions(+) create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/deploy.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .k8s/deployment.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..ae763cb --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,31 @@ +name: CI + +on: + push: + branches: + - main + +jobs: + ci: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v5 + + - name: Install uv + uses: astral-sh/setup-uv@v6.5.0 + with: + enable-cache: true + + - name: Install the project + run: uv sync --locked --all-extras --dev + + - name: Run formatter + run: uv run ruff format --check + + - name: Run linter + run: uv run ruff check + + - name: Run tests with coverage + run: uv run pytest diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..5483033 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,64 @@ +name: Deploy + +on: + push: + tags: + - 'v*' + +jobs: + ci: + uses: ./.github/workflows/ci.yaml + + push: + needs: ci + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: gitea.ia-innovacion.work + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: gitea.ia-innovacion.work/innovacion/searchbox-mcp + tags: | + type=ref,event=branch + type=ref,event=pr + type=sha,prefix={{branch}}- + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + # deploy: + # needs: release + # runs-on: ubuntu-latest + # steps: + # - name: Checkout code + # uses: actions/checkout@v4 + + # - name: Install kubectl + # uses: azure/setup-kubectl@v3 + + # - name: Deploy to cluster + # env: + # KUBECONFIG_CONTENT: ${{ secrets.KUBECONFIG_CONTENT }} + # run: | + # echo "$KUBECONFIG_CONTENT" > kubeconfig + # export KUBECONFIG=$PWD/kubeconfig + # kubectl apply -f .k8s/ + # kubectl rollout restart deployment/python-demo + # kubectl rollout status deployment/python-demo diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..4a048e0 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,36 @@ +name: Release + +on: + push: + tags: + - 'v*' + +jobs: + ci: + uses: ./.github/workflows/ci.yaml + + release: + needs: ci + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v5 + + - name: Install uv + uses: astral-sh/setup-uv@v6.5.0 + with: + enable-cache: true + + - name: Install the project + run: uv sync --locked + + - name: Build package + run: uv build + + - name: Publish to registry + env: + UV_PUBLISH_URL: ${{ vars.UV_PUBLISH_URL }} + UV_PUBLISH_USERNAME: ${{ vars.UV_PUBLISH_USERNAME }} + UV_PUBLISH_PASSWORD: ${{ secrets.UV_PUBLISH_PASSWORD }} + run: uv publish diff --git a/.k8s/deployment.yaml b/.k8s/deployment.yaml new file mode 100644 index 0000000..1e567ba --- /dev/null +++ b/.k8s/deployment.yaml @@ -0,0 +1,24 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: searchbox-mcp + namespace: apps + labels: + app: searchbox-mcp +spec: + replicas: 1 + selector: + matchLabels: + app: searchbox-mcp + template: + metadata: + labels: + app: searchbox-mcp + spec: + imagePullSecrets: + - name: gitea-registry-cred + containers: + - name: searchbox-mcp + image: gitea.ia-innovacion.work/innovacion/searchbox-mcp:latest + ports: + - containerPort: 8000 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ea6e0f1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim AS builder + +ENV UV_COMPILE_BYTECODE=1 \ + UV_LINK_MODE=copy \ + UV_PYTHON_DOWNLOADS=0 + +WORKDIR /app + +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 \ + uv sync --locked --no-install-project --no-dev + +COPY . /app + +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --extra mcp --locked --no-dev + +FROM python:3.13-slim-bookworm AS runtime + +COPY --from=builder --chown=app:app /app /app + +RUN echo '[tool.vault-settings]\nsecret="qdrant-mcp"' > pyproject.toml + +ENV PATH="/app/.venv/bin:$PATH" + +EXPOSE 8000 + +CMD [ "searchbox-mcp" ] diff --git a/pyproject.toml b/pyproject.toml index 96b8450..e18bc1e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,3 +73,7 @@ precision = 2 [tool.coverage.html] directory = "htmlcov" + +[[tool.uv.index]] +name = "innovacion" +url = "https://innovacion:9afcfaab597db77f75ce5f08f7fca8ef69800b10@gitea.ia-innovacion.work/api/packages/innovacion/pypi/simple"