Skip to content

Commit

Permalink
Merge pull request #1 from FNNDSC/wip
Browse files Browse the repository at this point in the history
WIP stuff and automatic testing in GitHub Actions
  • Loading branch information
jennydaman authored Jul 27, 2024
2 parents bf3d75c + c66139e commit 50ebf94
Show file tree
Hide file tree
Showing 30 changed files with 898 additions and 69 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.gitignore
.dockerignore
.idea
.venv
Dockerfile
docker-compose.yml
README.md
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test

on:
push:
branches: [ master ]
paths:
- '.github/workflows/test.yml'
- '**.py'
pull_request:

jobs:
test:
name: Tests
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Spin up ChRIS
uses: FNNDSC/miniChRIS-docker@master
with:
# for testing, we need to create plugin instances, but we don't need the plugins to actually run.
services: chris oxidicom graphql-engine
- name: Build
run: docker compose build test
- name: Test
id: test
continue-on-error: true # we want to upload coverage, even on failure
run: docker compose run -T --use-aliases test
- name: Copy coverage.xml from container
run: docker cp "$(docker compose ps -a test -q | tail -n 1):/app/coverage.xml" coverage.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.idea
__pycache__
/src/serie/version.txt
/.test_data
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
FROM python:3.12.3-alpine

WORKDIR /app
COPY requirements.lock ./
RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -r requirements.lock
ARG REQUIREMENTS_FILE=requirements.lock
COPY ${REQUIREMENTS_FILE} ./requirements.txt
RUN --mount=type=cache,sharing=locked,target=/root/.cache/pip \
sed -i' ' -e '/-e file:\./d' requirements.txt \
&& env PYTHONDONTWRITEBYTECODE=1 pip install -r requirements.txt

COPY src .
CMD ["fastapi", "run", "main.py"]
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,19 @@ docker compose --profile hasura up -d

### Testing

Run unit tests on-the-metal:

```shell
rye run pytest
```

End-to-end tests require _SERIE_ to run in the same docker network as _CUBE_ and Hasura,
so we need to run them with Docker Compose:

```shell
docker compose run test
```

### Deployment

See https://github.com/FNNDSC/charts
31 changes: 28 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Run SERIE in development mode in an existing miniChRIS network.

services:
# Run SERIE in development mode in an existing miniChRIS network.
dev:
build:
context: .
Expand All @@ -12,8 +12,33 @@ services:
networks:
minichris-local:
aliases:
- poc.handler.chris

- dev.serie
# End-to-end testing
test:
build:
context: .
args:
REQUIREMENTS_FILE: requirements-dev.lock
command: pytest --color=yes --run-e2e --cov=serie --cov-report=xml
working_dir: /app
volumes:
# /app is a volume and the source code files are binded as subdirectories
# instead of directly mounting `.:/app` so that pytest and coverage can
# write temporary files to /app
- test:/app
- ./src/serie:/app/serie:ro
- ./tests:/app/tests:ro
- /var/run/docker.sock:/var/run/docker.sock
environment:
CHRIS_URL: http://chris:8000/api/v1/
networks:
minichris-local:
aliases:
- test.serie
profiles:
- test
networks:
minichris-local:
external: true
volumes:
test:
20 changes: 16 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
[project]
name = "serie"
version = "0.1.0"
version = "0.0.0" # <-- version in pyproject.toml is ignored. Set the version in src/serie/version.txt
description = "Specific Endpoints for Research Integration Events"
authors = [
{ name = "FNNDSC", email = "[email protected]" }
]
dependencies = [
"fastapi>=0.111.1",
"aiochris~=0.5.0",
"aiochris~=0.8.0",
"yarl>=1.9.4",
"asyncstdlib>=3.12.4",
"pydantic-settings>=2.3.4",
"requests>=2.32.3",
]
readme = "README.md"
requires-python = ">= 3.12"
Expand All @@ -19,8 +22,17 @@ build-backend = "hatchling.build"

[tool.rye]
managed = true
dev-dependencies = []
virtual = true
dev-dependencies = [
"pytest>=8.3.2",
"pytest-asyncio>=0.23.8",
"asyncio>=3.4.3",
"aiohttp>=3.9.5",
"pydicom>=2.4.4",
"asyncer>=0.0.7",
"pynetdicom>=2.1.0",
"docker>=7.1.0",
"pytest-cov>=5.0.0",
]

[tool.hatch.metadata]
allow-direct-references = true
Expand Down
42 changes: 41 additions & 1 deletion requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,26 @@
# generate-hashes: false
# universal: false

aiochris==0.5.0
-e file:.
aiochris==0.8.0
# via serie
aiohttp==3.9.5
# via aiochris
aiosignal==1.3.1
# via aiohttp
annotated-types==0.7.0
# via pydantic
anyio==4.4.0
# via asyncer
# via httpx
# via starlette
# via watchfiles
async-property==0.2.2
# via aiochris
asyncer==0.0.7
asyncio==3.4.3
asyncstdlib==3.12.4
# via serie
attrs==23.2.0
# via aiohttp
beartype==0.19.0rc0
Expand All @@ -32,14 +39,21 @@ casefy==0.1.7
certifi==2024.7.4
# via httpcore
# via httpx
# via requests
charset-normalizer==3.3.2
# via requests
click==8.1.7
# via typer
# via uvicorn
coverage==7.6.0
# via pytest-cov
dnspython==2.6.1
# via email-validator
docker==7.1.0
email-validator==2.2.0
# via fastapi
fastapi==0.111.1
# via serie
fastapi-cli==0.0.4
# via fastapi
frozenlist==1.4.1
Expand All @@ -58,7 +72,10 @@ idna==3.7
# via anyio
# via email-validator
# via httpx
# via requests
# via yarl
iniconfig==2.0.0
# via pytest
jinja2==3.1.4
# via fastapi
# via pyserde
Expand All @@ -73,22 +90,41 @@ multidict==6.0.5
# via yarl
mypy-extensions==1.0.0
# via typing-inspect
packaging==24.1
# via pytest
pluggy==1.5.0
# via pytest
plum-dispatch==2.2.2
# via pyserde
pydantic==2.8.2
# via fastapi
# via pydantic-settings
pydantic-core==2.20.1
# via pydantic
pydantic-settings==2.3.4
# via serie
pydicom==2.4.4
# via pynetdicom
pygments==2.18.0
# via rich
pynetdicom==2.1.0
pyserde==0.19.3
# via aiochris
pytest==8.3.2
# via pytest-asyncio
# via pytest-cov
pytest-asyncio==0.23.8
pytest-cov==5.0.0
python-dotenv==1.0.1
# via pydantic-settings
# via uvicorn
python-multipart==0.0.9
# via fastapi
pyyaml==6.0.1
# via uvicorn
requests==2.32.3
# via docker
# via serie
rich==13.7.1
# via typer
shellingham==1.5.4
Expand All @@ -109,6 +145,9 @@ typing-extensions==4.12.2
# via typing-inspect
typing-inspect==0.9.0
# via pyserde
urllib3==2.2.2
# via docker
# via requests
uvicorn==0.30.1
# via fastapi
uvloop==0.19.0
Expand All @@ -120,3 +159,4 @@ websockets==12.0
yarl==1.9.4
# via aiochris
# via aiohttp
# via serie
20 changes: 19 additions & 1 deletion requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
# generate-hashes: false
# universal: false

aiochris==0.5.0
-e file:.
aiochris==0.8.0
# via serie
aiohttp==3.9.5
# via aiochris
aiosignal==1.3.1
Expand All @@ -22,6 +24,8 @@ anyio==4.4.0
# via watchfiles
async-property==0.2.2
# via aiochris
asyncstdlib==3.12.4
# via serie
attrs==23.2.0
# via aiohttp
beartype==0.19.0rc0
Expand All @@ -32,6 +36,9 @@ casefy==0.1.7
certifi==2024.7.4
# via httpcore
# via httpx
# via requests
charset-normalizer==3.3.2
# via requests
click==8.1.7
# via typer
# via uvicorn
Expand All @@ -40,6 +47,7 @@ dnspython==2.6.1
email-validator==2.2.0
# via fastapi
fastapi==0.111.1
# via serie
fastapi-cli==0.0.4
# via fastapi
frozenlist==1.4.1
Expand All @@ -58,6 +66,7 @@ idna==3.7
# via anyio
# via email-validator
# via httpx
# via requests
# via yarl
jinja2==3.1.4
# via fastapi
Expand All @@ -77,18 +86,24 @@ plum-dispatch==2.2.2
# via pyserde
pydantic==2.8.2
# via fastapi
# via pydantic-settings
pydantic-core==2.20.1
# via pydantic
pydantic-settings==2.3.4
# via serie
pygments==2.18.0
# via rich
pyserde==0.19.3
# via aiochris
python-dotenv==1.0.1
# via pydantic-settings
# via uvicorn
python-multipart==0.0.9
# via fastapi
pyyaml==6.0.1
# via uvicorn
requests==2.32.3
# via serie
rich==13.7.1
# via typer
shellingham==1.5.4
Expand All @@ -109,6 +124,8 @@ typing-extensions==4.12.2
# via typing-inspect
typing-inspect==0.9.0
# via pyserde
urllib3==2.2.2
# via requests
uvicorn==0.30.1
# via fastapi
uvloop==0.19.0
Expand All @@ -120,3 +137,4 @@ websockets==12.0
yarl==1.9.4
# via aiochris
# via aiohttp
# via serie
Loading

0 comments on commit 50ebf94

Please sign in to comment.