Skip to content

Commit

Permalink
Merge pull request #10 from mihamieat/develop
Browse files Browse the repository at this point in the history
feat: merge develop into master
  • Loading branch information
mihamieat authored Aug 29, 2024
2 parents 3ab2b5c + 1a1e6d9 commit 887990d
Show file tree
Hide file tree
Showing 24 changed files with 853 additions and 63 deletions.
Binary file added .coverage
Binary file not shown.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = src/gpac_api/app/db/database.py, src/gpac_api/app/utils/lifespan.py
80 changes: 80 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: GPacAPI FastAPI CI
'on':
push:
branches:
- master
- develop
- feature/*
- fix/*
- hotfix/*
- refactor/*
- test/*
- ci/*
jobs:
code-quality:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.11.6
- name: Install dependencies
run: |
python -m pip install --upgrade pipx
pipx install poetry
poetry install
- name: Run pylint
run: poetry run pylint src/
- name: Run black check
run: poetry run black . --check --diff -v
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.11.6
- name: Install dependencies
run: |
python -m pip install --upgrade pipx
pipx install poetry
poetry install
- name: run build
run: poetry build
test:
runs-on: ubuntu-latest
strategy:
matrix:
mongodb-version: ['5.0', '6.0', '7.0']
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.11.6
- name: Install dependencies
run: |
python -m pip install --upgrade pipx
pipx install poetry
poetry install
- name: Install and run MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: ${{ matrix.mongodb-version }}
- name: Run Tests
run: poetry run pytest --cov=src tests/ --junitxml=junit.xml -o junit_family=legacy
- name: Upload coverage report
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: junit.xml
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
21 changes: 21 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: GPacAPI FastAPI CD
'on':
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: '${{ vars.DOCKERHUB_USERNAME }}'
password: '${{ secrets.DOCKERHUB_TOKEN }}'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: '${{ vars.DOCKERHUB_USERNAME }}/gpac-api:0.1.0'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ coverage.xml
*.cover
*.py,cover
*.hypothesis/
junit.xml

# Old files
*_old*
14 changes: 6 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ repos:
args: [--max-line-length=110]

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 24.8.0
hooks:
- id: black
language_version: python3.11.6
Expand All @@ -44,10 +44,8 @@ repos:
language: system
types: [python]
require_serial: true
# - id: pytest
# name: pytest
# entry: poetry run pytest
# language: system
# pass_filenames: false
# always_run: true
# types: [python]
- id: pytest-mongodb
name: Run pytest with MongoDB in a docker container
entry: ./unittest.sh
language: script
types: [python]
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10.12
FROM python:3.11.6
WORKDIR /code
COPY ./requirements.txt /code/requirements.txt
RUN pip install --upgrade setuptools
Expand Down
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
[![codecov](https://codecov.io/gh/mihamieat/gpac-api/graph/badge.svg?token=5UM8L15FL1)](https://codecov.io/gh/mihamieat/gpac-api)
![CI](https://github.com/mihamieat/gpac-api/actions/workflows/ci.yml/badge.svg)
# Gpac API documentation
## Overview
GpacAPI is a service for interacting with gpac application.
See API documentation for details.
> GpacAPI is a service for interacting with the GPAC application.
See the API documentation for details.
## Installation
It is recommended to run the server in a separate environment.
```sh
pip install -r requirements.txt
```
## Run the server
## Running the server
### In production
```sh
fastapi run src/gpac_api/app/main.py --port 80
Expand All @@ -17,17 +20,19 @@ fastapi run src/gpac_api/app/main.py --port 80
fastapi dev src/gpac_api/app/main.py --reload
```
## Docker
Make sure to have Docker installed.

To run the server in a docker container.

Create a Docker image.
```sh
docker build -t gpac_api_image
docker build -t gpac_api_image .
```
Run the server container.
```sh
docker run -d --name gpac_api_container -p 80:80 gpac_api_image
```
## Contribute
## Contributing
### pre-commit
Pre-commit is a tool that helps developers automatically run checks and formatting on their code before they commit changes to a version control system like Git.
#### Install
Expand All @@ -37,3 +42,16 @@ curl -sSL https://bootstrap.pypa.io/get-pip.py | python -
python -m pip install --user pre-commit
pre-commit install
```
#### Unit Test
Unit test is an essential tool for the pre-commit action. It could also be launched alone.

Again, make sure to have Docker installed as well as [Docker Compose](https://docs.docker.com/compose/install/)

Make sure that the shell script is executable for the current user
```sh
chmod u+x ./unittest.sh
```
You can now run
```sh
./unittest.sh
```
13 changes: 13 additions & 0 deletions docker-compose.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.8'

services:
mongodb:
image: mongo:6.0
container_name: mongodb_test
ports:
- "27017:27017"
volumes:
- mongo_data:/data/db

volumes:
mongo_data:
Loading

0 comments on commit 887990d

Please sign in to comment.