generated from one-zero-eight/fastapi-template
-
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.
- Loading branch information
0 parents
commit 44d4d10
Showing
53 changed files
with
2,683 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/[email protected] | ||
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. |
Oops, something went wrong.