Skip to content

Commit

Permalink
feat: add minimal project
Browse files Browse the repository at this point in the history
  • Loading branch information
abusquets committed Jan 3, 2024
1 parent 0f8ef7c commit 0a15bb0
Show file tree
Hide file tree
Showing 176 changed files with 10,409 additions and 1 deletion.
53 changes: 53 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Check code and Pytest

on: [push]

jobs:
build:

runs-on: ubuntu-latest

services:
postgres:
image: postgres:16.1
env:
POSTGRES_USER: northwind
POSTGRES_PASSWORD: northwind
POSTGRES_DB: northwind
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5


steps:
- uses: actions/checkout@v3

- name: psycopg prerequisites
run: sudo apt-get install libpq-dev

- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: 3.12

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install poetry ruff
poetry install
- name: Lint with ruff
run: |
ruff check ./src
- name: Test with pytest
working-directory: ./src
run: |
poetry run pytest -c pytest.github.ini
# - name: SonarCloud Scan
# uses: SonarSource/sonarcloud-github-action@master
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
140 changes: 140 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
env-local
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# History extension
.history

# Custom
\!*
.DS_Store
src/debug_scripts/
env-api-dev
.vscode
57 changes: 57 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
exclude: "docs|node_modules|migrations|shared|.git|.tox|.hbs"
default_stages: [commit]
fail_fast: true

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks # Refer to this repository for futher documentation about official pre-commit hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: trailing-whitespace
- id: end-of-file-fixer
- id: double-quote-string-fixer
- id: mixed-line-ending
- id: check-toml
- id: check-yaml
args:
- --unsafe # Instead of loading the files, simply parse them for syntax.
- id: detect-private-key


- repo: https://github.com/myint/autoflake
rev: v2.2.1
hooks:
- id: autoflake
args:
[
"--in-place",
"--remove-all-unused-imports",
"--remove-unused-variable",
]

# - repo: https://github.com/psf/black # Refer to this repository for futher documentation about black hook
# rev: 23.12.1
# hooks:
# - id: black

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.11
hooks:
# Run the linter.
- id: ruff
args: [--fix] # Enables autofix
# Run the formatter.
- id: ruff-format

- repo: https://github.com/pycqa/bandit
rev: 1.7.6
hooks:
- id: bandit
args: [ "-iii", "-ll" ]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
args: [--config-file=mypy.ini, --ignore-missing-imports]
additional_dependencies: [types-redis, types-pyyaml, types-sqlalchemy, types-click, types-python-jose]
43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
ARG PYTHON_VERSION=3.12.1

FROM python:${PYTHON_VERSION}-bookworm AS build-image

# Update and install dependencies
RUN apt-get -qq update && apt-get -qq install lsb-release && apt-get -qq install git

RUN mkdir -m 700 /root/.ssh; \
touch -m 600 /root/.ssh/known_hosts; \
ssh-keyscan github.com > /root/.ssh/known_hosts

# poetry
WORKDIR /srv
RUN pip install pip --upgrade && pip install poetry==1.4.2
COPY poetry.lock pyproject.toml /srv/
ARG POETRY_DEV=false
RUN --mount=type=ssh,id=default --mount=type=cache,mode=0777,target=/root/.cache/pip \
poetry export -f requirements.txt -o requirements.txt --without-hashes $(test "$POETRY_DEV" = "true" && echo "--with dev,test") \
&& python -m venv venv && . venv/bin/activate && pip install -r requirements.txt
# end poetry

# Optimized build
FROM python:${PYTHON_VERSION}-slim-bookworm
ARG WAIT_BIN=wait

# Add wait script
ADD "https://github.com/ufoscout/docker-compose-wait/releases/download/2.12.0/${WAIT_BIN}" /wait
RUN chmod +x /wait
# wait script

COPY --from=build-image /srv/venv/ /srv/venv/

ENV PATH="/srv/venv/bin:$PATH"

# Set working directory to function root directory
WORKDIR /app

# Copy the rest of the working directory contents into the container at /app
COPY src/ .
COPY docker/entrypoint.sh /entrypoint.sh

ENTRYPOINT [ "/entrypoint.sh" ]
CMD ["run-asgi"]
Binary file added ER.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 55 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,55 @@
# abusquets-nothwind
# abusquets-northwind

To execute any command
```bash
docker-compose exec api bash
```


# Users

## Create admin User
```bash
python manage.py {user_email} {name}
```

# Migrations


```bash
alembic init -t async migrations
```

## Create the initial migration or add a migration
```bash
alembic revision --autogenerate -m "init"

```

```bash

alembic revision --autogenerate -m 'add northwind models'

```

## Apply the migrations to the database:

```bash
alembic upgrade head

```

# Populate

```bash
docker-compose up
```

```bash
docker-compose exec api alembic upgrade head
docker-compose exec postgres bash -c 'export PGPASSWORD=northwind && psql -U northwind northwind < /data/northwind_data.sql'
```

```bash
docker-compose exec api python manage.py {user_email} {name}
```
Loading

0 comments on commit 0a15bb0

Please sign in to comment.