Skip to content

Commit

Permalink
Add CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
apognu committed Feb 27, 2025
1 parent 4329a62 commit 5842764
Show file tree
Hide file tree
Showing 8 changed files with 560 additions and 134 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build and test

on:
pull_request:
workflow_call:
inputs:
version:
type: string
description: Version to build
required: true
push:
type: boolean
description: Whether to push the image or not
required: false
default: true

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v4
- name: Install poetry
uses: abatilo/actions-poetry@v4
- name: Setup a local virtual environment
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- uses: actions/cache@v3
name: Define a cache for the virtual environment based on the dependencies lock file
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}
- name: Install the project dependencies
run: poetry install
- name: Run the automated tests (for example)
run: poetry run pytest -v
build:
uses: ./.github/workflows/docker.yml
needs: [test]
with:
image: europe-west1-docker.pkg.dev/marble-infra/marble/marble-ner:${{ inputs.version || 'dev' }}
push: ${{ inputs.push || false }}

28 changes: 28 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build container image

on:
workflow_call:
inputs:
image:
type: string
description: "Version to build"
required: true
push:
type: boolean
description: "Whether to push the container image or not"
default: false

jobs:
build_container_image:
name: Build container image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Docker
uses: docker/setup-buildx-action@v3
- name: Build container image
uses: docker/build-push-action@v5
with:
push: ${{ inputs.push }}
tags: ${{ inputs.image }}
11 changes: 11 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Deploy to staging

on:
push:
branches: [main]

jobs:
deploy:
uses: ./.github/workflows/build.yml
with:
version: latest
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ COPY pyproject.toml poetry.lock /app/
RUN \
poetry install && \
poetry run python -c 'import os, gliner; gliner.GLiNER.from_pretrained(os.getenv("GLINER_MODEL"))' && \
poetry cache clear --all '' && \
poetry cache clear -n --all '' && \
rm -rf /root/.cache/pypoetry/artifacts

COPY . /app
Expand Down
4 changes: 4 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class Match(BaseModel):
model = GLiNER.from_pretrained(MODEL)
app = FastAPI()

@app.get("/-/health")
def healthcheck():
pass

@app.post("/detect")
def detect(query: Query):
labels = LABELS
Expand Down
570 changes: 446 additions & 124 deletions poetry.lock

Large diffs are not rendered by default.

13 changes: 4 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,15 @@ dependencies = [
"uvicorn[default] (>=0.34.0,<0.35.0)",
"gunicorn (>=23.0.0,<24.0.0)",
"torch (>=2.6.0,<3.0.0)",
"gliner (>=0.2.16,<0.3.0)"
"gliner (>=0.2.16,<0.3.0)",
"httpx (>=0.28.1,<0.29.0)",
]

[tool.poetry]
package-mode = false

[[tool.poetry.source]]
name = "pytorch"
url = "https://download.pytorch.org/whl/cpu"
priority = "explicit"

[tool.poetry.dependencies]
torch = { source = "pytorch" }
torchvision = { source = "pytorch" }
[tool.poetry.group.dev.dependencies]
pytest = "^8.3.4"

[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
Expand Down
20 changes: 20 additions & 0 deletions test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from fastapi.testclient import TestClient
from main import app

client = TestClient(app)

def test_healthcheck():
response = client.get('/-/health')

assert response.status_code == 200

def test_detection():
response = client.post('/detect', json={"text": "dinner with joe finnigan"})

assert response.status_code == 200

json = response.json()

assert len(json) == 1
assert json[0]['type'] == "Person"
assert json[0]['text'] == "joe finnigan"

0 comments on commit 5842764

Please sign in to comment.