-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add user info and training info endpoints
- Loading branch information
0 parents
commit d5a4dc5
Showing
38 changed files
with
1,850 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,14 @@ | ||
# Ignore everything | ||
* | ||
|
||
# Except code | ||
!/src/ | ||
!/deploy/ | ||
!/alembic/ | ||
!/alembic.ini | ||
!/pyproject.toml | ||
!/poetry.lock | ||
!logging.yaml | ||
|
||
# And ignore cache files in the code | ||
__pycache__ |
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 @@ | ||
POSTGRES_PASSWORD=postgres |
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,23 @@ | ||
version: 2 | ||
updates: | ||
# Enable version updates for python packages | ||
- package-ecosystem: "pip" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
groups: | ||
poetry: | ||
patterns: | ||
- "*" | ||
|
||
# Enable version updates for Docker | ||
- package-ecosystem: "docker" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
|
||
# Enable version updates for Actions | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" |
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,19 @@ | ||
name: Link issue to InNoHassle project | ||
|
||
on: | ||
issues: | ||
types: | ||
- opened | ||
- reopened | ||
- transferred | ||
|
||
jobs: | ||
add-to-project: | ||
name: Add issue to project | ||
if: github.repository_owner == 'one-zero-eight' # Do not run in forks | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/add-to-project@v1.0.2 | ||
with: | ||
project-url: https://github.com/orgs/one-zero-eight/projects/4 | ||
github-token: ${{ secrets.ACTIONS_PAT_PROJECTS }} |
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,57 @@ | ||
name: pre-commit | ||
|
||
on: [ push, pull_request ] | ||
|
||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
#---------------------------------------------- | ||
# Check-out repo and set-up python | ||
#---------------------------------------------- | ||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.12' | ||
#---------------------------------------------- | ||
# Install Poetry if not cached | ||
#---------------------------------------------- | ||
- name: Load cached Poetry installation | ||
id: cached-poetry | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.local # the path depends on the OS | ||
key: poetry-1.8.3 # increment to reset cache | ||
- name: Install Poetry | ||
if: steps.cached-poetry.outputs.cache-hit != 'true' | ||
uses: snok/install-poetry@v1 | ||
with: | ||
version: '1.8.3' | ||
virtualenvs-create: true | ||
virtualenvs-in-project: true | ||
#---------------------------------------------- | ||
# Install project dependencies if not cached | ||
#---------------------------------------------- | ||
- name: Load cached Poetry dependencies | ||
id: cached-poetry-dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: .venv | ||
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} | ||
- name: Install Poetry dependencies | ||
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | ||
run: poetry install --no-interaction | ||
#---------------------------------------------- | ||
# Run pre-commit with cache | ||
#---------------------------------------------- | ||
- name: Load pre-commit caches | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.cache/pre-commit | ||
key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} | ||
- name: Run pre-commit | ||
run: poetry run pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage manual | ||
env: | ||
RUFF_FORMAT: github |
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,15 @@ | ||
### PyCharm ### | ||
.idea | ||
|
||
### Cache ### | ||
__pycache__ | ||
.ruff_cache | ||
|
||
### Environment ### | ||
.env | ||
settings.yaml | ||
static | ||
|
||
### Sensible ### | ||
/private.pem | ||
/public.pem |
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,57 @@ | ||
# Pre-commit configuration. | ||
# https://pre-commit.com | ||
|
||
# pre-commit install | ||
# pre-commit run --all-files | ||
|
||
default_stages: | ||
- pre-commit | ||
- pre-push | ||
- commit-msg | ||
- manual | ||
|
||
repos: | ||
# Fix some errors with Ruff | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.6.7 | ||
hooks: | ||
- id: ruff | ||
args: [ --fix, --exit-zero ] | ||
name: "ruff: fixing" | ||
- id: ruff-format | ||
name: "ruff: formatting" | ||
|
||
# Lint Python files with Ruff | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.6.7 | ||
hooks: | ||
- id: ruff | ||
name: "ruff: linting" | ||
|
||
# Check other files | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.6.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
exclude: alembic/ | ||
- id: end-of-file-fixer | ||
exclude: alembic/ | ||
- id: check-added-large-files | ||
|
||
# Generate settings.schema.yaml | ||
- repo: local | ||
hooks: | ||
- id: generate-settings-schema | ||
name: generate settings.schema.yaml | ||
language: system | ||
entry: poetry run python ./scripts/generate_settings_schema.py | ||
pass_filenames: false | ||
files: ^src/config_schema.py$ | ||
- id: alembic-auto-migrations | ||
name: generate alembic auto migrations files | ||
language: system | ||
entry: poetry run python ./scripts/alembic_auto_migrations.py | ||
pass_filenames: false | ||
files: storages/ | ||
stages: | ||
- commit-msg |
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,63 @@ | ||
# Based on https://github.com/svx/poetry-fastapi-docker/blob/main/Dockerfile | ||
|
||
########################################################### | ||
# Base Python image. Set shared environment variables. | ||
FROM python:3.12-slim-bullseye AS base | ||
ENV PYTHONUNBUFFERED=1 \ | ||
PYTHONDONTWRITEBYTECODE=1 \ | ||
PIP_NO_CACHE_DIR=off \ | ||
PIP_DISABLE_PIP_VERSION_CHECK=on \ | ||
PIP_DEFAULT_TIMEOUT=100 \ | ||
POETRY_HOME="/opt/poetry" \ | ||
POETRY_VIRTUALENVS_IN_PROJECT=true \ | ||
POETRY_NO_INTERACTION=1 \ | ||
POETRY_INSTALLER_MAX_WORKERS=10 \ | ||
PYSETUP_PATH="/opt/pysetup" \ | ||
VENV_PATH="/opt/pysetup/.venv" | ||
|
||
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH" | ||
|
||
|
||
########################################################### | ||
# Builder stage. Build dependencies. | ||
FROM base AS builder | ||
RUN apt-get update \ | ||
&& apt-get install --no-install-recommends -y \ | ||
build-essential \ | ||
curl \ | ||
netcat \ | ||
vim \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install Poetry. Respects $POETRY_VERSION and $POETRY_HOME | ||
ENV POETRY_VERSION=1.8.3 | ||
SHELL ["/bin/bash", "-o", "pipefail", "-c"] | ||
RUN curl -sS https://install.python-poetry.org | POETRY_HOME=${POETRY_HOME} python3 - --version ${POETRY_VERSION} && \ | ||
chmod a+x /opt/poetry/bin/poetry | ||
|
||
# We copy our Python requirements here to cache them | ||
# and install only runtime deps using poetry | ||
WORKDIR $PYSETUP_PATH | ||
COPY ./poetry.lock ./pyproject.toml ./ | ||
RUN poetry install --no-interaction | ||
|
||
|
||
########################################################### | ||
# Production stage. Copy only runtime deps that were installed in the Builder stage. | ||
FROM base AS production | ||
|
||
COPY --from=builder $VENV_PATH $VENV_PATH | ||
|
||
COPY --chmod=755 ./deploy/docker-entrypoint.sh / | ||
|
||
# Create user with the name poetry | ||
RUN groupadd -g 1500 poetry && \ | ||
useradd -m -u 1500 -g poetry poetry | ||
|
||
COPY --chown=poetry:poetry . /code | ||
USER poetry | ||
WORKDIR /code | ||
|
||
EXPOSE 8000 | ||
ENTRYPOINT [ "/docker-entrypoint.sh" ] | ||
CMD [ "gunicorn", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8000", "--workers", "1", "src.api.app:app" ] |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 one-zero-eight | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,85 @@ | ||
# InnoSport API | ||
|
||
## About | ||
|
||
This is API for proxying requests in InnoSport website. | ||
It checks Accounts user token and make request to InnoSport API on behave of the user. | ||
|
||
### Technologies | ||
|
||
- [Python 3.12](https://www.python.org/downloads/) & [Poetry](https://python-poetry.org/docs/) | ||
- [FastAPI](https://fastapi.tiangolo.com/) | ||
- Formatting and linting: [Ruff](https://docs.astral.sh/ruff/), [pre-commit](https://pre-commit.com/) | ||
- Deployment: [Docker](https://www.docker.com/), [Docker Compose](https://docs.docker.com/compose/), | ||
[GitHub Actions](https://github.com/features/actions) | ||
|
||
## Development | ||
|
||
### Getting started | ||
|
||
1. Install [Python 3.12+](https://www.python.org/downloads/) | ||
2. Install [Poetry](https://python-poetry.org/docs/) | ||
3. Install project dependencies with [Poetry](https://python-poetry.org/docs/cli/#options-2). | ||
```bash | ||
poetry install | ||
``` | ||
4. Set up [pre-commit](https://pre-commit.com/) hooks: | ||
|
||
```bash | ||
poetry run pre-commit install --install-hooks -t pre-commit -t commit-msg | ||
``` | ||
5. Set up project settings file (check [settings.schema.yaml](settings.schema.yaml) for more info). | ||
```bash | ||
cp settings.example.yaml settings.yaml | ||
``` | ||
Edit `settings.yaml` according to your needs. | ||
|
||
**Set up PyCharm integrations** | ||
|
||
1. Ruff ([plugin](https://plugins.jetbrains.com/plugin/20574-ruff)). | ||
It will lint and format your code. Make sure to enable `Use ruff format` option in plugin settings. | ||
2. Pydantic ([plugin](https://plugins.jetbrains.com/plugin/12861-pydantic)). It will fix PyCharm issues with | ||
type-hinting. | ||
3. Conventional commits ([plugin](https://plugins.jetbrains.com/plugin/13389-conventional-commit)). It will help you | ||
to write [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/). | ||
|
||
### Run for development | ||
|
||
Run the ASGI server | ||
```bash | ||
poetry run python -m src.api | ||
``` | ||
OR using uvicorn directly | ||
```bash | ||
poetry run uvicorn src.api.app:app --use-colors --proxy-headers --forwarded-allow-ips=* | ||
``` | ||
|
||
Now the API is running on http://localhost:8000. Good job! | ||
|
||
### Deployment | ||
|
||
We use Docker with Docker Compose plugin to run the service on servers. | ||
|
||
1. Copy the file with environment variables: `cp .example.env .env` | ||
2. Change environment variables in the `.env` file | ||
3. Copy the file with settings: `cp settings.example.yaml settings.yaml` | ||
4. Change settings in the `settings.yaml` file according to your needs | ||
(check [settings.schema.yaml](settings.schema.yaml) for more info) | ||
5. Install Docker with Docker Compose | ||
6. Build a Docker image: `docker compose build --pull` | ||
7. Run the container: `docker compose up --detach` | ||
8. Check the logs: `docker compose logs -f` | ||
|
||
# How to update dependencies | ||
|
||
## Project dependencies | ||
|
||
1. Run `poetry update` to update all dependencies (it may update nothing, so double-check) | ||
2. Run `poetry show --outdated --all` to check for outdated dependencies | ||
3. Run `poetry add <package>@latest` to add a new dependency if needed | ||
|
||
## Pre-commit hooks | ||
|
||
1. Run `poetry run pre-commit autoupdate` | ||
|
||
Also, Dependabot will help you to keep your dependencies up-to-date, see [dependabot.yml](.github/dependabot.yml). |
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 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
# activate our virtual environment here | ||
. /opt/pysetup/.venv/bin/activate | ||
|
||
# You can put other setup logic here | ||
|
||
# Evaluating passed command: | ||
exec "$@" |
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,10 @@ | ||
services: | ||
api: | ||
build: . | ||
volumes: | ||
- "./settings.yaml:/code/settings.yaml:ro" # Read-only settings file | ||
restart: always | ||
ports: | ||
- "8000:8000" | ||
env_file: .env | ||
|
Oops, something went wrong.