-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb8fd43
commit 2f905e1
Showing
27 changed files
with
826 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
build | ||
dist | ||
htmlcov | ||
venv | ||
.coverage | ||
.tox | ||
.idea | ||
**/__pycache__ | ||
**/*.pyc | ||
**/*.swp | ||
**/*.egg-info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Run tox | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
include: | ||
- python-version: '3.12' | ||
tox-env: py312 | ||
codecov: codecov | ||
- python-version: '3.12' | ||
tox-env: lint | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip setuptools wheel | ||
python -m pip install --upgrade tox | ||
- name: Run tox | ||
run: | | ||
tox run -e ${{ matrix.tox-env }} | ||
- name: Upload to codecov | ||
if: ${{ matrix.codecov == 'codecov' }} | ||
uses: codecov/codecov-action@v4 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
fail_ci_if_error: false | ||
files: ./coverage.xml | ||
flags: pytest | ||
verbose: true | ||
name: "${{ github.repository }}-${{ matrix.tox-env }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
*.pyc | ||
*.swp | ||
coverage.xml | ||
*.egg-info | ||
.coverage | ||
.tox | ||
build | ||
dist | ||
venv | ||
tmp | ||
.eggs | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
FROM python:3.12 | ||
SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"] | ||
|
||
ARG INSTALL_DEBUG_TOOLS | ||
RUN \ | ||
if [[ "${INSTALL_DEBUG_TOOLS}" == "true" ]]; then \ | ||
SYSTEM_DEBUG_TOOLS="vim less curl jq htop strace net-tools iproute2" && \ | ||
PYTHON_DEBUG_TOOLS="py-spy memory-profiler" && \ | ||
echo "Installing tools for profiling and inspection..." && \ | ||
apt-get update && \ | ||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ${SYSTEM_DEBUG_TOOLS} && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* && \ | ||
pip install --no-cache-dir --upgrade ${PYTHON_DEBUG_TOOLS} ; \ | ||
fi | ||
|
||
RUN useradd -ms /bin/sh -u 1001 app | ||
ENV PATH="${PATH}:/home/app/.local/bin" | ||
USER app | ||
|
||
WORKDIR /src | ||
COPY --chown=app:app requirements.txt . | ||
COPY --chown=app:app docker-entrypoint.sh . | ||
|
||
RUN \ | ||
pip install --user --no-cache-dir --upgrade pip setuptools wheel && \ | ||
pip install --user --no-cache-dir --upgrade -r requirements.txt | ||
|
||
COPY --chown=app:app ./src/app app | ||
|
||
ARG APP_NAME | ||
ARG APP_VERSION | ||
ARG COMMIT_SHA | ||
ENV APP_NAME=${APP_NAME} | ||
ENV APP_VERSION=${APP_VERSION} | ||
ENV COMMIT_SHA=${COMMIT_SHA} | ||
|
||
ENTRYPOINT ["./docker-entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# accounting-service | ||
|
||
## Description | ||
|
||
This service is composed by: | ||
|
||
- `accounting-service`: main service, listening on port 8900. | ||
|
||
## Local build and deployment | ||
|
||
To build and start the Docker image locally, you can execute: | ||
|
||
```bash | ||
tox -e build-image,run-image | ||
``` | ||
|
||
Possible tox environments (run `tox list` for the full list): | ||
|
||
``` | ||
# build-image -> Build a local docker image | ||
# run-image -> Run a local docker image previously built | ||
# logs-image -> Tail the logs of a local docker container | ||
``` | ||
|
||
## Remote deployment | ||
|
||
To make a release, build and publish the Docker image to the registry, you need to: | ||
|
||
- push a tag to the main branch using git, or | ||
- create a release through the GitHub UI. | ||
|
||
The format of the tag should be `YYYY.MM.DD`, where: | ||
|
||
- `YYYY` is the full year (2024, 2025 ...) | ||
- `MM` is the short month, not zero-padded (1, 2 ... 11, 12) | ||
- `DD` is any incremental number, not zero-padded (it doesn't need to be the day number) | ||
|
||
The new Docker images are automatically deployed after a few minutes. | ||
|
||
See also the configuration files at <https://bbpgitlab.epfl.ch/project/sbo/k8s>. | ||
|
||
## Documentation | ||
|
||
The API documentation is available locally at <https://127.0.0.1:8900/docs> after the local deployment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# docker-compose.yml for local deployment | ||
|
||
services: | ||
app: | ||
container_name: accounting-service | ||
build: | ||
dockerfile: Dockerfile | ||
ports: | ||
- "127.0.0.1:8900:8900" | ||
cap_add: | ||
- SYS_PTRACE | ||
environment: | ||
- APP_DEBUG=true | ||
- LOGGING_LEVEL=DEBUG | ||
- UVICORN_RELOAD=True | ||
develop: | ||
watch: | ||
- action: sync | ||
path: ./src/app | ||
target: /src/app | ||
- action: rebuild | ||
path: requirements.txt | ||
- action: rebuild | ||
path: docker-entrypoint.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
set -e -o errexit | ||
|
||
#alembic upgrade head | ||
uvicorn app.main:app --host 0.0.0.0 --port 8900 --proxy-headers --log-config app/data/logging.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
[build-system] | ||
requires = ["setuptools>=64", "setuptools-scm>=8"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
|
||
[project] | ||
name = "accounting-service" | ||
description = "Accounting Service" | ||
readme = "README.md" | ||
requires-python = ">=3.12" | ||
dependencies = [ | ||
"fastapi", | ||
"pydantic>=2", | ||
"pydantic-settings>=2.2.1", | ||
"uvicorn[standard]", | ||
] | ||
dynamic = ["version"] | ||
|
||
|
||
[project.optional-dependencies] | ||
cli = [ | ||
"click", | ||
] | ||
|
||
|
||
[tool.setuptools_scm] | ||
|
||
|
||
[tool.black] | ||
line-length = 100 | ||
target-version = ['py312'] | ||
include = 'src/.*\.py$|tests/.*\.py$|doc/source/conf\.py$|setup\.py$' | ||
|
||
|
||
[tool.isort] | ||
profile = "black" | ||
line_length = 100 | ||
|
||
|
||
[tool.ruff] | ||
line-length = 100 | ||
target-version = "py312" | ||
|
||
[tool.ruff.lint] | ||
preview = true | ||
select = ["ALL"] | ||
ignore = [ | ||
"ANN002", # Missing type annotation for `*args` | ||
"ANN003", # Missing type annotation for `**kwargs` | ||
"CPY001", # Missing copyright notice at top of file | ||
'N802', # function name should be lowercase | ||
"RUF029", # Function is declared `async`, but doesn't `await` or use `async` features. | ||
] | ||
|
||
[tool.ruff.lint.pydocstyle] | ||
convention = "google" | ||
|
||
[tool.ruff.lint.pylint] | ||
# Maximum number of arguments for function / method | ||
max-args = 8 | ||
# Maximum number of locals for function / method body | ||
max-locals = 15 | ||
# Maximum number of return / yield for function / method body | ||
max-returns = 6 | ||
# Maximum number of branch for function / method body | ||
max-branches = 12 | ||
# Maximum number of statements in function / method body | ||
max-statements = 50 | ||
# Maximum number of public methods for a class (see R0904). | ||
max-public-methods = 60 | ||
|
||
|
||
[tool.pytest.ini_options] | ||
addopts = [ | ||
"--import-mode=importlib", | ||
] | ||
|
||
|
||
[tool.coverage.paths] | ||
source = [ | ||
"src", | ||
"*/site-packages", | ||
] | ||
|
||
[tool.coverage.run] | ||
branch = true | ||
parallel = false | ||
|
||
[tool.coverage.report] | ||
show_missing = true | ||
precision = 0 | ||
fail_under = 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# | ||
# This file is autogenerated by pip-compile with Python 3.12 | ||
# by the following command: | ||
# | ||
# pip-compile --allow-unsafe --no-emit-index-url --output-file=requirements.txt --strip-extras pyproject.toml | ||
# | ||
annotated-types==0.7.0 | ||
# via pydantic | ||
anyio==4.4.0 | ||
# via | ||
# httpx | ||
# starlette | ||
# watchfiles | ||
certifi==2024.6.2 | ||
# via | ||
# httpcore | ||
# httpx | ||
click==8.1.7 | ||
# via | ||
# typer | ||
# uvicorn | ||
dnspython==2.6.1 | ||
# via email-validator | ||
email-validator==2.1.1 | ||
# via fastapi | ||
fastapi==0.111.0 | ||
# via accounting-service (pyproject.toml) | ||
fastapi-cli==0.0.4 | ||
# via fastapi | ||
h11==0.14.0 | ||
# via | ||
# httpcore | ||
# uvicorn | ||
httpcore==1.0.5 | ||
# via httpx | ||
httptools==0.6.1 | ||
# via uvicorn | ||
httpx==0.27.0 | ||
# via fastapi | ||
idna==3.7 | ||
# via | ||
# anyio | ||
# email-validator | ||
# httpx | ||
jinja2==3.1.4 | ||
# via fastapi | ||
markdown-it-py==3.0.0 | ||
# via rich | ||
markupsafe==2.1.5 | ||
# via jinja2 | ||
mdurl==0.1.2 | ||
# via markdown-it-py | ||
orjson==3.10.3 | ||
# via fastapi | ||
pydantic==2.7.3 | ||
# via | ||
# accounting-service (pyproject.toml) | ||
# fastapi | ||
# pydantic-settings | ||
pydantic-core==2.18.4 | ||
# via pydantic | ||
pydantic-settings==2.3.0 | ||
# via accounting-service (pyproject.toml) | ||
pygments==2.18.0 | ||
# via rich | ||
python-dotenv==1.0.1 | ||
# via | ||
# pydantic-settings | ||
# uvicorn | ||
python-multipart==0.0.9 | ||
# via fastapi | ||
pyyaml==6.0.1 | ||
# via uvicorn | ||
rich==13.7.1 | ||
# via typer | ||
shellingham==1.5.4 | ||
# via typer | ||
sniffio==1.3.1 | ||
# via | ||
# anyio | ||
# httpx | ||
starlette==0.37.2 | ||
# via fastapi | ||
typer==0.12.3 | ||
# via fastapi-cli | ||
typing-extensions==4.12.1 | ||
# via | ||
# fastapi | ||
# pydantic | ||
# pydantic-core | ||
# typer | ||
ujson==5.10.0 | ||
# via fastapi | ||
uvicorn==0.30.1 | ||
# via | ||
# accounting-service (pyproject.toml) | ||
# fastapi | ||
uvloop==0.19.0 | ||
# via uvicorn | ||
watchfiles==0.22.0 | ||
# via uvicorn | ||
websockets==12.0 | ||
# via uvicorn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""App package.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Endpoints.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""V1 endpoints.""" |
Oops, something went wrong.