Skip to content

Commit

Permalink
Add skeleton files (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaFicarelli authored Jun 6, 2024
1 parent bb8fd43 commit 2f905e1
Show file tree
Hide file tree
Showing 27 changed files with 826 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
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
46 changes: 46 additions & 0 deletions .github/workflows/run-tox.yml
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 }}"
12 changes: 12 additions & 0 deletions .gitignore
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
38 changes: 38 additions & 0 deletions Dockerfile
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"]
Empty file removed README
Empty file.
44 changes: 44 additions & 0 deletions README.md
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.
24 changes: 24 additions & 0 deletions docker-compose.yml
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
5 changes: 5 additions & 0 deletions docker-entrypoint.sh
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
92 changes: 92 additions & 0 deletions pyproject.toml
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
103 changes: 103 additions & 0 deletions requirements.txt
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
1 change: 1 addition & 0 deletions src/app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""App package."""
1 change: 1 addition & 0 deletions src/app/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Endpoints."""
1 change: 1 addition & 0 deletions src/app/api/v1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""V1 endpoints."""
Loading

0 comments on commit 2f905e1

Please sign in to comment.