Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fivan999 authored Oct 29, 2024
0 parents commit 44d4d10
Show file tree
Hide file tree
Showing 53 changed files with 2,683 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .dockerignore
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__
1 change: 1 addition & 0 deletions .example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
POSTGRES_PASSWORD=postgres
23 changes: 23 additions & 0 deletions .github/dependabot.yaml
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"
19 changes: 19 additions & 0 deletions .github/workflows/add-issues-to-project.yaml
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/[email protected]
with:
project-url: https://github.com/orgs/one-zero-eight/projects/4
github-token: ${{ secrets.ACTIONS_PAT_PROJECTS }}
57 changes: 57 additions & 0 deletions .github/workflows/pre-commit.yaml
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
15 changes: 15 additions & 0 deletions .gitignore
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
57 changes: 57 additions & 0 deletions .pre-commit-config.yaml
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
63 changes: 63 additions & 0 deletions Dockerfile
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" ]
21 changes: 21 additions & 0 deletions LICENSE
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.
Loading

0 comments on commit 44d4d10

Please sign in to comment.