Skip to content

3.0 release, move to python3.10, upgrades, refactor, sqlalchemy models and Dockerfile #9

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

Merged
merged 20 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
835d9e2
move to python3.10, upgrades, refactor sqlalchemy models and Dockerfile
rafsaf May 3, 2022
4354821
reformated tokens, added trusted hosts and rewritten tests
rafsaf May 5, 2022
c977021
Finished 3.0 refactoring of a template, cleanup requriements, changed…
rafsaf May 7, 2022
d2ec745
updated tests.yml job, removed cookiecutter from template minimal dev…
rafsaf May 7, 2022
3574ba5
Fix tests.yml python version typo
rafsaf May 7, 2022
181430b
Fixed conftest issue with fixtures template minimal
rafsaf May 7, 2022
eb7507e
Updated docs image, cookiecutter params and tests.yml file name
rafsaf May 7, 2022
0abb1b9
Fix typo in branch name in build_docker_image workflow
rafsaf May 7, 2022
fb0ada7
try fix escape problem in build docker workflows with envs
rafsaf May 7, 2022
55f411e
Final fix for build docker images workflow context
rafsaf May 7, 2022
940c8a4
Next try context docker build workflows
rafsaf May 7, 2022
a41229c
Final fix for invalid context in docker image workflows - use cp -r
rafsaf May 7, 2022
d433f86
Fix manual and build docker images workflows
rafsaf May 7, 2022
2bac2af
rename user table to user_model to avoid postgresql issues
rafsaf May 7, 2022
55a8e5f
nginx unit config root user
rafsaf May 7, 2022
81b5287
Finish new Readme
rafsaf May 10, 2022
48a2e92
removed name param in endpoints, cleaner default_user_headers fixture…
rafsaf May 10, 2022
e742590
Added more default values to core Settings - test database and tokens…
rafsaf May 10, 2022
df03b55
Fix token data issued_at and expires_at validation
rafsaf May 10, 2022
b8d356f
Final update Readme - fix few typos
rafsaf May 10, 2022
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
19 changes: 15 additions & 4 deletions .github/workflows/build_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
workflows:
- "Run tests"
branches:
- master
- main
types:
- completed

Expand All @@ -16,16 +16,27 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: Generate projects from templates using cookiecutter
# minimal_project folder
run: |
pip install cookiecutter
python tests/create_minimal_project.py

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}

- name: Build and push image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
with:
file: Dockerfile
context: ./{{cookiecutter.project_name}}/template_minimal
file: minimal_project/Dockerfile
context: minimal_project
push: true
tags: rafsaf/minimal-fastapi-postgres-template:latest
17 changes: 14 additions & 3 deletions .github/workflows/manual_build_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,27 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: Generate projects from templates using cookiecutter
# minimal_project folder
run: |
pip install cookiecutter
python tests/create_minimal_project.py

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}

- name: Build and push image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
with:
file: Dockerfile
context: ./{{cookiecutter.project_name}}/template_minimal
file: minimal_project/Dockerfile
context: minimal_project
push: true
tags: rafsaf/minimal-fastapi-postgres-template:${{ github.event.inputs.tag }}
122 changes: 61 additions & 61 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,94 +2,94 @@ name: Run tests

on:
push:
pull_request:

jobs:
build:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.9", "3.10"]

services:
postgres:
image: postgres
env:
POSTGRES_DB: test
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 30000:5432
- 5432:5432
steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Load cached venv1
id: cached-poetry-dependencies1
uses: actions/cache@v2
with:
path: .venv1
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('{{cookiecutter.project_name}}/template_minimal/poetry.lock') }}
- name: Install dependencies and actiavte virtualenv
if: steps.cached-poetry-dependencies1.outputs.cache-hit != 'true'
python-version: "3.10"

- name: Generate projects from templates using cookiecutter
# fastapi_users_project folder
# minimal_project folder
run: |
python -m venv .venv1
source .venv1/bin/activate
pip install -r {{cookiecutter.project_name}}/template_minimal/requirements-dev.txt
pip install cookiecutter
- name: Load cached venv2
id: cached-poetry-dependencies2
python tests/create_minimal_project.py
python tests/create_fastapi_users_project.py

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true

### template minimal ###

- name: Load cached venv-1
id: cached-poetry-dependencies-template-1
uses: actions/cache@v2
with:
path: .venv2
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('{{cookiecutter.project_name}}/template_fastapi_users/poetry.lock') }}
- name: Install dependencies and actiavte virtualenv
if: steps.cached-poetry-dependencies2.outputs.cache-hit != 'true'
run: |
python -m venv .venv2
source .venv2/bin/activate
pip install -r {{cookiecutter.project_name}}/template_fastapi_users/requirements-dev.txt
pip install cookiecutter
- name: Lint with flake8 minimal project
run: |
source .venv1/bin/activate
# stop the build if there are Python syntax errors or undefined names
cd \{\{cookiecutter.project_name\}\}/template_minimal
flake8 app --count --exit-zero --statistics
- name: Lint with flake8 fastapi_users project
path: minimal_project/.venv
key: venv-${{ runner.os }}-${{ hashFiles('minimal_project/poetry.lock') }}

- name: Install template minimal dependencies
if: steps.cached-poetry-dependencies-template-1.outputs.cache-hit != 'true'
run: |
source .venv2/bin/activate
# stop the build if there are Python syntax errors or undefined names
cd \{\{cookiecutter.project_name\}\}/template_fastapi_users
flake8 app --count --exit-zero --statistics
- name: Test minimal project is passing pytest test
cd minimal_project
poetry install --no-interaction --no-root

- name: Run template minimal flake8 and then tests
env:
TEST_DATABASE_HOSTNAME: localhost
TEST_DATABASE_PASSWORD: postgres
TEST_DATABASE_PORT: 5432
TEST_DATABASE_USER: postgres
TEST_DATABASE_DB: postgres
run: |
source .venv1/bin/activate
python tests/create_minimal_project.py
export TEST_DATABASE_HOSTNAME=localhost
export TEST_DATABASE_USER=test
export TEST_DATABASE_PASSWORD=test
export TEST_DATABASE_PORT=30000
export TEST_DATABASE_DB=test
cd minimal_project
poetry run flake8 app --count --exit-zero --statistics
poetry run coverage run -m pytest

pytest minimal_project
### template fastapi users ###

- name: Test fastapi_users project is passing pytest test
- name: Load cached venv-2
id: cached-poetry-dependencies-template-2
uses: actions/cache@v2
with:
path: fastapi_users_project/.venv
key: venv-${{ runner.os }}-${{ hashFiles('fastapi_users_project/poetry.lock') }}

- name: Install template fastapi users dependencies
if: steps.cached-poetry-dependencies-template-1.outputs.cache-hit != 'true'
run: |
source .venv2/bin/activate
python tests/create_fastapi_users_project.py
export TEST_DATABASE_HOSTNAME=localhost
export TEST_DATABASE_USER=test
export TEST_DATABASE_PASSWORD=test
export TEST_DATABASE_PORT=30000
export TEST_DATABASE_DB=test
cd fastapi_users_project
poetry install --no-interaction --no-root

pytest fastapi_users_project
- name: Run template fastapi users flake8 and then tests
env:
TEST_DATABASE_HOSTNAME: localhost
TEST_DATABASE_PASSWORD: postgres
TEST_DATABASE_PORT: 5432
TEST_DATABASE_USER: postgres
TEST_DATABASE_DB: postgres
run: |
cd fastapi_users_project
poetry run flake8 app --count --exit-zero --statistics
poetry run coverage run -m pytest
Loading