Skip to content

Commit 1225637

Browse files
authored
Merge pull request #9 from rafsaf/3.0-release
3.0 release, move to python3.10, upgrades, refactor, sqlalchemy models and Dockerfile
2 parents 62a5cba + b8d356f commit 1225637

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1285
-1053
lines changed

.github/workflows/build_docker_image.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
workflows:
66
- "Run tests"
77
branches:
8-
- master
8+
- main
99
types:
1010
- completed
1111

@@ -16,16 +16,27 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v2
1818

19+
- name: Set up Python
20+
uses: actions/setup-python@v2
21+
with:
22+
python-version: "3.10"
23+
24+
- name: Generate projects from templates using cookiecutter
25+
# minimal_project folder
26+
run: |
27+
pip install cookiecutter
28+
python tests/create_minimal_project.py
29+
1930
- name: Login to DockerHub
2031
uses: docker/login-action@v1
2132
with:
2233
username: ${{ secrets.DOCKER_USER }}
2334
password: ${{ secrets.DOCKER_PASS }}
2435

2536
- name: Build and push image
26-
uses: docker/build-push-action@v2
37+
uses: docker/build-push-action@v3
2738
with:
28-
file: Dockerfile
29-
context: ./{{cookiecutter.project_name}}/template_minimal
39+
file: minimal_project/Dockerfile
40+
context: minimal_project
3041
push: true
3142
tags: rafsaf/minimal-fastapi-postgres-template:latest

.github/workflows/manual_build_docker_image.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,27 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v2
1616

17+
- name: Set up Python
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: "3.10"
21+
22+
- name: Generate projects from templates using cookiecutter
23+
# minimal_project folder
24+
run: |
25+
pip install cookiecutter
26+
python tests/create_minimal_project.py
27+
1728
- name: Login to DockerHub
1829
uses: docker/login-action@v1
1930
with:
2031
username: ${{ secrets.DOCKER_USER }}
2132
password: ${{ secrets.DOCKER_PASS }}
2233

2334
- name: Build and push image
24-
uses: docker/build-push-action@v2
35+
uses: docker/build-push-action@v3
2536
with:
26-
file: Dockerfile
27-
context: ./{{cookiecutter.project_name}}/template_minimal
37+
file: minimal_project/Dockerfile
38+
context: minimal_project
2839
push: true
2940
tags: rafsaf/minimal-fastapi-postgres-template:${{ github.event.inputs.tag }}

.github/workflows/tests.yml

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,94 +2,94 @@ name: Run tests
22

33
on:
44
push:
5-
pull_request:
65

76
jobs:
87
build:
98
runs-on: ubuntu-20.04
10-
strategy:
11-
matrix:
12-
python-version: ["3.9", "3.10"]
13-
149
services:
1510
postgres:
1611
image: postgres
1712
env:
18-
POSTGRES_DB: test
19-
POSTGRES_USER: test
20-
POSTGRES_PASSWORD: test
13+
POSTGRES_PASSWORD: postgres
2114
options: >-
2215
--health-cmd pg_isready
2316
--health-interval 10s
2417
--health-timeout 5s
2518
--health-retries 5
2619
ports:
27-
- 30000:5432
20+
- 5432:5432
2821
steps:
2922
- uses: actions/checkout@v2
3023

3124
- name: Set up Python
3225
uses: actions/setup-python@v2
3326
with:
34-
python-version: ${{ matrix.python-version }}
35-
- name: Load cached venv1
36-
id: cached-poetry-dependencies1
37-
uses: actions/cache@v2
38-
with:
39-
path: .venv1
40-
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('{{cookiecutter.project_name}}/template_minimal/poetry.lock') }}
41-
- name: Install dependencies and actiavte virtualenv
42-
if: steps.cached-poetry-dependencies1.outputs.cache-hit != 'true'
27+
python-version: "3.10"
28+
29+
- name: Generate projects from templates using cookiecutter
30+
# fastapi_users_project folder
31+
# minimal_project folder
4332
run: |
44-
python -m venv .venv1
45-
source .venv1/bin/activate
46-
pip install -r {{cookiecutter.project_name}}/template_minimal/requirements-dev.txt
4733
pip install cookiecutter
48-
- name: Load cached venv2
49-
id: cached-poetry-dependencies2
34+
python tests/create_minimal_project.py
35+
python tests/create_fastapi_users_project.py
36+
37+
- name: Install Poetry
38+
uses: snok/install-poetry@v1
39+
with:
40+
virtualenvs-create: true
41+
virtualenvs-in-project: true
42+
43+
### template minimal ###
44+
45+
- name: Load cached venv-1
46+
id: cached-poetry-dependencies-template-1
5047
uses: actions/cache@v2
5148
with:
52-
path: .venv2
53-
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('{{cookiecutter.project_name}}/template_fastapi_users/poetry.lock') }}
54-
- name: Install dependencies and actiavte virtualenv
55-
if: steps.cached-poetry-dependencies2.outputs.cache-hit != 'true'
56-
run: |
57-
python -m venv .venv2
58-
source .venv2/bin/activate
59-
pip install -r {{cookiecutter.project_name}}/template_fastapi_users/requirements-dev.txt
60-
pip install cookiecutter
61-
- name: Lint with flake8 minimal project
62-
run: |
63-
source .venv1/bin/activate
64-
# stop the build if there are Python syntax errors or undefined names
65-
cd \{\{cookiecutter.project_name\}\}/template_minimal
66-
flake8 app --count --exit-zero --statistics
67-
- name: Lint with flake8 fastapi_users project
49+
path: minimal_project/.venv
50+
key: venv-${{ runner.os }}-${{ hashFiles('minimal_project/poetry.lock') }}
51+
52+
- name: Install template minimal dependencies
53+
if: steps.cached-poetry-dependencies-template-1.outputs.cache-hit != 'true'
6854
run: |
69-
source .venv2/bin/activate
70-
# stop the build if there are Python syntax errors or undefined names
71-
cd \{\{cookiecutter.project_name\}\}/template_fastapi_users
72-
flake8 app --count --exit-zero --statistics
73-
- name: Test minimal project is passing pytest test
55+
cd minimal_project
56+
poetry install --no-interaction --no-root
57+
58+
- name: Run template minimal flake8 and then tests
59+
env:
60+
TEST_DATABASE_HOSTNAME: localhost
61+
TEST_DATABASE_PASSWORD: postgres
62+
TEST_DATABASE_PORT: 5432
63+
TEST_DATABASE_USER: postgres
64+
TEST_DATABASE_DB: postgres
7465
run: |
75-
source .venv1/bin/activate
76-
python tests/create_minimal_project.py
77-
export TEST_DATABASE_HOSTNAME=localhost
78-
export TEST_DATABASE_USER=test
79-
export TEST_DATABASE_PASSWORD=test
80-
export TEST_DATABASE_PORT=30000
81-
export TEST_DATABASE_DB=test
66+
cd minimal_project
67+
poetry run flake8 app --count --exit-zero --statistics
68+
poetry run coverage run -m pytest
8269
83-
pytest minimal_project
70+
### template fastapi users ###
8471

85-
- name: Test fastapi_users project is passing pytest test
72+
- name: Load cached venv-2
73+
id: cached-poetry-dependencies-template-2
74+
uses: actions/cache@v2
75+
with:
76+
path: fastapi_users_project/.venv
77+
key: venv-${{ runner.os }}-${{ hashFiles('fastapi_users_project/poetry.lock') }}
78+
79+
- name: Install template fastapi users dependencies
80+
if: steps.cached-poetry-dependencies-template-1.outputs.cache-hit != 'true'
8681
run: |
87-
source .venv2/bin/activate
88-
python tests/create_fastapi_users_project.py
89-
export TEST_DATABASE_HOSTNAME=localhost
90-
export TEST_DATABASE_USER=test
91-
export TEST_DATABASE_PASSWORD=test
92-
export TEST_DATABASE_PORT=30000
93-
export TEST_DATABASE_DB=test
82+
cd fastapi_users_project
83+
poetry install --no-interaction --no-root
9484
95-
pytest fastapi_users_project
85+
- name: Run template fastapi users flake8 and then tests
86+
env:
87+
TEST_DATABASE_HOSTNAME: localhost
88+
TEST_DATABASE_PASSWORD: postgres
89+
TEST_DATABASE_PORT: 5432
90+
TEST_DATABASE_USER: postgres
91+
TEST_DATABASE_DB: postgres
92+
run: |
93+
cd fastapi_users_project
94+
poetry run flake8 app --count --exit-zero --statistics
95+
poetry run coverage run -m pytest

0 commit comments

Comments
 (0)