Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup fastapi htmx #8

Merged
merged 55 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
823b7ad
Add fastapi
berrydenhartog May 1, 2024
2369fcd
Setup sqlmodel
berrydenhartog May 1, 2024
9bd890e
Add alembic
berrydenhartog May 2, 2024
3007af9
Setup Alembic
berrydenhartog May 6, 2024
eae3750
Add database
berrydenhartog May 6, 2024
835c365
Update dependencies
berrydenhartog May 7, 2024
c94b3e5
Add alembic test version
berrydenhartog May 8, 2024
b7d42d5
Add devcontainer vscode settings for python
berrydenhartog May 8, 2024
3ca72c2
Update vscode settings to improve integration with project
berrydenhartog May 8, 2024
c95f572
Update project dependencies and filter warnings for pytest
berrydenhartog May 8, 2024
5a9e0bb
Add codecoverage html and lcov generation to test script
berrydenhartog May 8, 2024
4eece34
Rename database scheme variable
berrydenhartog May 8, 2024
849ad42
Move dockerfile cmd to granian
berrydenhartog May 8, 2024
2bf3467
Add logging, masking and exceptions
berrydenhartog May 8, 2024
63c49a5
Add tests for masking, logging and exceptions
berrydenhartog May 8, 2024
98bf40e
Add lcov generation to code coverage
berrydenhartog May 8, 2024
76a2f2e
Add favicon
berrydenhartog May 8, 2024
d03903e
Fix python3.10 problem with Self type
berrydenhartog May 8, 2024
734c660
Fix docker build
berrydenhartog May 8, 2024
292cf89
Add sonarcloud exclusion of tests and alembic
berrydenhartog May 8, 2024
bca492c
Add package cleaner for github
berrydenhartog May 8, 2024
8891b87
Set correct labels for docker image
berrydenhartog May 8, 2024
e5be9ca
Add badges for sonarcloud
berrydenhartog May 8, 2024
b21bd45
Renamed actions
berrydenhartog May 8, 2024
4a43a23
Rename ci to test
berrydenhartog May 8, 2024
3d94c67
Rename middleware
berrydenhartog May 10, 2024
451f4e5
Add exception handler file
berrydenhartog May 10, 2024
7ee42a9
Move migrations
berrydenhartog May 10, 2024
d0655f6
Move dockerfile
berrydenhartog May 10, 2024
990e525
Update sonar-porject and pyproject
berrydenhartog May 10, 2024
41a7956
Add pythonpath to devcontainer
berrydenhartog May 10, 2024
571164f
Add log to file tad.log
berrydenhartog May 10, 2024
4edd149
Move test to root
berrydenhartog May 10, 2024
4d97273
Start debugger from root
berrydenhartog May 10, 2024
334069c
Add routes
berrydenhartog May 10, 2024
39d43f7
Add logging variable to app
berrydenhartog May 10, 2024
f9204fd
Make models a folder
berrydenhartog May 10, 2024
6f8addf
Add ruff formatter to alembic
berrydenhartog May 10, 2024
4e5e061
Add __init__
berrydenhartog May 10, 2024
f8d13fe
Added a test .env file
berrydenhartog May 13, 2024
0dd830c
Make models dynamicly imported for alembic
berrydenhartog May 13, 2024
9f1b180
Add SQLite plugin for vscode
berrydenhartog May 13, 2024
90fbd94
Monkeypatch env in tests
berrydenhartog May 13, 2024
c570ef2
Add basic template setup
berrydenhartog May 13, 2024
11c523b
Add htmx
berrydenhartog May 13, 2024
f2da393
Fix typo for migrations in app database filename
berrydenhartog May 14, 2024
b8d5ed4
Fix ci workflow for dockerfile location
berrydenhartog May 14, 2024
6e89834
Update dependencies
berrydenhartog May 14, 2024
437368e
Fix trivy image scanning
berrydenhartog May 14, 2024
82b2b14
Fix build step in documentation
berrydenhartog May 14, 2024
47efa5e
Fix typo in state-pr-schedule
berrydenhartog May 14, 2024
4d32b55
Fix fatal role error in compose postgres setup
berrydenhartog May 14, 2024
b14b676
Add healthchecks
berrydenhartog May 14, 2024
bf943a9
Fix database healthcheck from cmd-exec to cmd
berrydenhartog May 14, 2024
ad1e39a
Remove downloads from readme
berrydenhartog May 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
"containerEnv": {
"DEVCONTAINER": "1",
"PYTHONASYNCIODEBUG": "1",
"POETRY_VIRTUALENVS_CREATE": "false"
"POETRY_VIRTUALENVS_CREATE": "false",
"PYTHONPATH": "/workspaces/tad/"
},
"remoteUser": "root",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},
"forwardPorts": [8000,8080],
"postCreateCommand": ".devcontainer/postCreateCommand.sh",
"customizations": {
"vscode": {
Expand All @@ -17,7 +22,9 @@
"redhat.vscode-yaml",
"charliermarsh.ruff",
"github.vscode-github-actions",
"mhutchie.git-graph"
"mhutchie.git-graph",
"markis.code-coverage",
"qwtel.sqlite-viewer"
],
"settings": {
"editor.formatOnPaste": false,
Expand All @@ -35,7 +42,9 @@
"terminal.integrated.defaultProfile.linux": "zsh",
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
}
},
"python.analysis.typeCheckingMode": "strict",
"markiscodecoverage.searchCriteria": "coverage.lcov"
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Domain
DOMAIN=localhost

# Environment: local, staging, production
ENVIRONMENT=local
PROJECT_NAME="TAD"

# TAD backend
BACKEND_CORS_ORIGINS="http://localhost,https://localhost,http://127.0.0.1,https://127.0.0.1"
SECRET_KEY=changethis
APP_DATABASE_SCHEME="postgresql"
APP_DATABASE_USER=tad
APP_DATABASE_DB=tad
APP_DATABASE_PASSWORD=changethis

# Postgres database
POSTGRES_SERVER=db
POSTGRES_PORT=5432
POSTGRES_DB=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=changethis

# Database viewer
PGADMIN_DEFAULT_PASSWORD=changethis
24 changes: 24 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Domain
DOMAIN=localhost

# Environment: local, staging, production
ENVIRONMENT=local
PROJECT_NAME="TAD"

# TAD backend
BACKEND_CORS_ORIGINS="http://localhost,https://localhost,http://127.0.0.1,https://127.0.0.1"
SECRET_KEY=changethis
APP_DATABASE_SCHEME="sqlite"
APP_DATABASE_USER=tad
APP_DATABASE_DB=tad
APP_DATABASE_PASSWORD=changethis

# Postgres database
POSTGRES_SERVER=db
POSTGRES_PORT=5432
POSTGRES_DB=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=changethis

# Database viewer
PGADMIN_DEFAULT_PASSWORD=changethis
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto
*.sh text eol=lf
19 changes: 14 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: continuous-integration

on:
push:
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
run: poetry install

- name: Generate SBOM
run: poetry run cyclonedx-py poetry > sbom.json
run: poetry run cyclonedx-py poetry --without test,dev > sbom.json

- name: Generate licenses file
run: |
Expand Down Expand Up @@ -165,18 +165,28 @@ jobs:
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
env:
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index

- name: print metadata
run: |
echo "tags: ${{ steps.meta.outputs.tags }}"
echo "labels: ${{ steps.meta.outputs.labels }}"
echo "annotations: ${{ steps.meta.outputs.annotations }}"


- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
platforms: linux/amd64,linux/arm64,darwin/amd64

- name: Run Trivy vulnerability scanner
if: github.event_name != 'pull_request'
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ steps.meta.outputs.tags }}
Expand All @@ -190,7 +200,6 @@ jobs:
TRIVY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Trivy scan results to GitHub Security tab
if: github.event_name != 'pull_request'
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/cleanup-package-schedule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: cleanup-package-schedule
on:
schedule:
- cron: "0 4 * * *"
workflow_dispatch:

jobs:
cleanup-package-versions:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
packages: write
steps:
- uses: actions/delete-package-versions@v5
with:
package-name: 'tad'
package-type: 'container'
min-versions-to-keep: 0
ignore-versions: 'main'
delete-only-untagged-versions: true
32 changes: 0 additions & 32 deletions .github/workflows/codeql.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/first-interaction.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Greetings
name: first-interaction

on: [pull_request, issues]

Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/pr-close.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: pr-close

on:
pull_request:
types:
- closed
workflow_dispatch:
inputs:
pr_number:
description: 'PR Number'
required: true
type: string

jobs:
cleanup-package-versions:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
packages: write
steps:
- uses: actions/delete-package-versions@v5
if: ${{ github.event_name != 'pull_request' }}
with:
package-name: 'tad'
package-type: 'container'
package-version-ids: ${{ inputs.pr_number }}

- uses: actions/delete-package-versions@v5
if: ${{ github.event_name == 'pull_request' }}
with:
package-name: 'tad'
package-type: 'container'
package-version-ids: PR-${{ github.event.number }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Close stale"
name: stale-schedule
on:
schedule:
- cron: "0 4 * * *"
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dist/
.coverage.*
coverage.xml
htmlcov/
coverage.lcov

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
Expand All @@ -26,3 +27,10 @@ __pypackages__/

#mypyr
.mypy_cache/

# macos
.DS_Store

# tad tool
tad.log*
database.sqlite3
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ default_language_version:
python: python3.11
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: end-of-file-fixer
exclude: ^tad/static/vendor/*
- id: trailing-whitespace
- id: check-yaml
- id: check-json
- id: check-toml
- id: check-added-large-files
- id: check-merge-conflict
- id: check-toml
- id: detect-private-key
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.3
rev: v0.4.4
hooks:
- id: ruff
- id: ruff-format
Expand Down
6 changes: 5 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"recommendations": [
"ms-python.python",
"ms-python.vscode-pylance",
"editorconfig.editorconfig",
"streetsidesoftware.code-spell-checker",
"redhat.vscode-yaml",
"charliermarsh.ruff",
"github.vscode-github-actions"
"github.vscode-github-actions",
"mhutchie.git-graph",
"markis.code-coverage",
"qwtel.sqlite-viewer"
]
}
15 changes: 10 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@
"version": "0.2.0",
"configurations": [
{
"name": "tad",
"name": "tad - fastapi",
"type": "debugpy",
"request": "launch",
"module": "tad",
"justMyCode": false,
"args": []
"module": "granian",
"justMyCode": true,
"args": ["--interface","asgi","tad.main:app", "--reload"],
"cwd": "${workspaceFolder}/",
"env": {
"PYTHONPATH": "${workspaceFolder}"
},
"envFile": "${workspaceFolder}/.env.test"
},
{
"name": "Project: tests",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"cwd": "${workspaceFolder}",
"justMyCode": false,
"justMyCode": true,
"args": []
}
]
Expand Down
24 changes: 18 additions & 6 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"label": "PyRight",
"detail": "typecheck code.",
"type": "shell",
"command": "pyright",
"command": "poetry run pyright",
"group": "test",
"presentation": {
"reveal": "always",
Expand All @@ -14,10 +14,22 @@
"problemMatcher": []
},
{
"label": "Ruff",
"detail": "format and lint code.",
"label": "Ruff lint",
"detail": "lint code.",
"type": "shell",
"command": "ruff format && ruff check",
"command": "poetry run ruff check --fix",
"group": "test",
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": []
},
{
"label": "Ruff format",
"detail": "format code.",
"type": "shell",
"command": "poetry run ruff format",
"group": "test",
"presentation": {
"reveal": "always",
Expand All @@ -29,7 +41,7 @@
"label": "Code Coverage",
"detail": "Generate code coverage report.",
"type": "shell",
"command": "coverage report --fail-under 95",
"command": "poetry run coverage report && poetry run coverage html && poetry run coverage lcov",
"group": "test",
"presentation": {
"reveal": "always",
Expand All @@ -41,7 +53,7 @@
"label": "PyTest",
"detail": "test all code",
"type": "shell",
"command": "coverage run -m pytest ./tests",
"command": "poetry run coverage run -m pytest",
"group": {
"kind": "test",
"isDefault": true
Expand Down
Loading
Loading