Skip to content

Commit

Permalink
feature: Refactor app, add users and auth
Browse files Browse the repository at this point in the history
  • Loading branch information
renceInbox committed Jun 23, 2024
1 parent 3ade83d commit ec6f581
Show file tree
Hide file tree
Showing 44 changed files with 1,173 additions and 108 deletions.
6 changes: 0 additions & 6 deletions .env.sample

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var/
*.egg
.venv/
venv/
.env
.envs/

# Python debug
pdb/
Expand Down
49 changes: 27 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
exclude: 'docs|node_modules|migrations|.git|.tox|.mypy_cache|frontend'
---
exclude: docs|node_modules|migrations|.git|.tox|.mypy_cache|frontend
default_stages: [commit]
fail_fast: true

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: requirements-txt-fixer
- id: check-merge-conflict
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
- id: autoflake
args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variables', '--ignore-init-module-imports']
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
- repo: https://github.com/PyCQA/bandit
rev: '1.7.5'
hooks:
- id: bandit
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: requirements-txt-fixer
- id: check-merge-conflict
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.2.3 # or other specific tag
hooks:
- id: yamlfmt
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.10
hooks:
# Run the linter.
- id: ruff
args: [--fix]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/PyCQA/bandit
rev: 1.7.9
hooks:
- id: bandit
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Edgecutters

Simple FastAPI template with users and auth.
114 changes: 114 additions & 0 deletions alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# A generic, single database configuration.

[alembic]
# path to migration scripts
script_location = src/database/migrations

# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s

# sys.path path, will be prepended to sys.path if present.
# defaults to the current working directory.
prepend_sys_path = .

# timezone to use when rendering the date within the migration file
# as well as the filename.
# If specified, requires the python>=3.9 or backports.zoneinfo library.
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
# string value is passed to ZoneInfo()
# leave blank for localtime
# timezone =

# max length of characters to apply to the
# "slug" field
# truncate_slug_length = 40

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false

# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false

# version location specification; This defaults
# to src/database/migrations/versions. When using multiple version
# directories, initial revisions must be specified with --version-path.
# The path separator used here should be the separator specified by "version_path_separator" below.
# version_locations = %(here)s/bar:%(here)s/bat:src/database/migrations/versions

# version path separator; As mentioned above, this is the character used to split
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
# Valid values for version_path_separator are:
#
# version_path_separator = :
# version_path_separator = ;
# version_path_separator = space
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.

# set to 'true' to search source files recursively
# in each "version_locations" directory
# new in Alembic version 1.10
# recursive_version_locations = false

# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8

;sqlalchemy.url = driver://user:pass@localhost/dbname


[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run
# on newly generated revision scripts. See the documentation for further
# detail and examples

# format using "black" - use the console_scripts runner, against the "black" entrypoint
# hooks = black
# black.type = console_scripts
# black.entrypoint = black
# black.options = -l 79 REVISION_SCRIPT_FILENAME

# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
# hooks = ruff
# ruff.type = exec
# ruff.executable = %(here)s/.venv/bin/ruff
# ruff.options = --fix REVISION_SCRIPT_FILENAME

# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
24 changes: 0 additions & 24 deletions app/api/endpoints.py

This file was deleted.

6 changes: 0 additions & 6 deletions app/api/routers.py

This file was deleted.

25 changes: 0 additions & 25 deletions app/config/base.py

This file was deleted.

12 changes: 0 additions & 12 deletions app/config/keycloak.py

This file was deleted.

10 changes: 0 additions & 10 deletions app/main.py

This file was deleted.

32 changes: 32 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM python:3.12-slim

ENV PYTHONDONTWRITEBYTECODE 1
ENV DOCKER_BUILDKIT 1
ENV PYTHONUNBUFFERED 1

RUN addgroup --system app && adduser --system --group app

WORKDIR /app

RUN rm -rf /var/lib/apt/lists/* && \
apt-get purge --auto-remove && \
apt-get clean

COPY ./requirements.txt /requirements.txt

RUN --mount=type=cache,target=/root/.cache \
pip install -r /requirements.txt --no-cache-dir

COPY ./docker/run.sh /run.sh
RUN chmod +x /run.sh

COPY ./docker/prestart.sh /prestart.sh
RUN chmod +x /prestart.sh

COPY --chown=app . /app

ENV PYTHONPATH=/app

USER app

ENTRYPOINT ["/prestart.sh"]
10 changes: 10 additions & 0 deletions docker/prestart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -o errexit
set -o pipefail
set -o nounset

# Run migrations
#alembic upgrade head

exec "$@"
11 changes: 11 additions & 0 deletions docker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -o errexit
set -o pipefail
set -o nounset

export APP_MODULE=${APP_MODULE-app.main:app}
export HOST=${HOST:-0.0.0.0}
export PORT=${PORT:-8000}

uvicorn --host $HOST --port $PORT "$APP_MODULE"
29 changes: 29 additions & 0 deletions local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
volumes:
local_postgres_data: {}
local_redis_data: {}

services:
backend:
image: backend_api
build:
context: .
dockerfile: docker/Dockerfile
command: /run.sh
depends_on:
- postgres
ports:
- 8000:8000
env_file:
- .envs/.local
extra_hosts:
- host.docker.internal:host-gateway

postgres:
image: postgres:14
volumes:
- local_postgres_data:/var/lib/postgresql/data
env_file:
- .envs/.local.postgres
ports:
- 5434:5432
Loading

0 comments on commit ec6f581

Please sign in to comment.