Skip to content

Commit 100e140

Browse files
committed
fastapi boilerplate project setup
1 parent 871ca24 commit 100e140

Some content is hidden

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

42 files changed

+675
-5
lines changed

.env.example

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
PYTHON_ENV=dev
2+
DB_TYPE=postgresql
3+
DB_NAME=""
4+
DB_USER=""
5+
DB_PASSWORD=""
6+
DB_HOST=""
7+
DB_PORT=5432
8+
MYSQL_DRIVER=
9+
DB_URL=postgresql://username:password@host:PORT/dbname
10+
SECRET_KEY=
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
16+
1. Go to '...'
17+
2. Click on '....'
18+
3. Scroll down to '....'
19+
4. See error
20+
21+
**Expected behavior**
22+
A clear and concise description of what you expected to happen.
23+
24+
**Screenshots**
25+
If applicable, add screenshots to help explain your problem.
26+
27+
**Desktop (please complete the following information):**
28+
29+
- OS: [e.g. iOS]
30+
- Browser [e.g. chrome, safari]
31+
- Version [e.g. 22]
32+
33+
**Smartphone (please complete the following information):**
34+
35+
- Device: [e.g. iPhone6]
36+
- OS: [e.g. iOS8.1]
37+
- Browser [e.g. stock browser, safari]
38+
- Version [e.g. 22]
39+
40+
**Additional context**
41+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<!--- Provide a general summary of your changes in the Title above -->
2+
3+
4+
5+
## Description
6+
7+
<!--- Describe your changes in detail -->
8+
9+
10+
11+
## Related Issue (Link to issue ticket)
12+
13+
<!--- This project only accepts pull requests related to open issues -->
14+
<!--- If suggesting a new feature or change, please discuss it in an issue first -->
15+
<!--- If fixing a bug, there should be an issue describing it with steps to reproduce -->
16+
<!--- Please link to the issue here: -->
17+
18+
19+
20+
## Motivation and Context
21+
22+
<!--- Why is this change required? What problem does it solve? -->
23+
24+
25+
26+
## How Has This Been Tested?
27+
28+
<!--- Please describe in detail how you tested your changes. -->
29+
<!--- Include details of your testing environment, and the tests you ran to -->
30+
<!--- see how your change affects other areas of the code, etc. -->
31+
32+
33+
34+
## Screenshots (if appropriate - Postman, etc)
35+
36+
37+
38+
## Types of changes
39+
40+
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
41+
42+
- [ ] Bug fix (non-breaking change which fixes an issue)
43+
- [ ] New feature (non-breaking change which adds functionality)
44+
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
45+
46+
47+
## Checklist
48+
49+
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
50+
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
51+
52+
- [ ] My code follows the code style of this project.
53+
- [ ] My change requires a change to the documentation.
54+
- [ ] I have updated the documentation accordingly.
55+
- [ ] I have read the **CONTRIBUTING** document.
56+
- [ ] I have added tests to cover my changes.
57+
- [ ] All new and existing tests passed.

.github/workflows/cd.dev.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Dev Branch Deployment
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI"]
6+
types:
7+
- completed
8+
branches: [dev]
9+
10+
jobs:
11+
on-success:
12+
runs-on: ubuntu-latest
13+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v3
17+
18+
- name: Use SSH Action
19+
uses: appleboy/ssh-action@v0.1.8
20+
with:
21+
host: ${{ secrets.HOST }}
22+
username: ${{ secrets.USERNAME }}
23+
password: ${{ secrets.PASSWORD }}
24+
script: |
25+
cd python/dev_source_code/
26+
git pull origin dev
27+
source .venv/bin/activate
28+
pip install -r requirements.txt
29+
alembic upgrade head
30+
31+
on-failure:
32+
runs-on: ubuntu-latest
33+
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
34+
steps:
35+
- run: echo 'The triggering workflow failed'

.github/workflows/cd.prod.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Prod Branch Deployment
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI"]
6+
types:
7+
- completed
8+
branches: [main]
9+
10+
jobs:
11+
on-success:
12+
runs-on: ubuntu-latest
13+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v3
17+
18+
- name: Use SSH Action
19+
uses: appleboy/ssh-action@v0.1.8
20+
with:
21+
host: ${{ secrets.HOST }}
22+
username: ${{ secrets.USERNAME }}
23+
password: ${{ secrets.PASSWORD }}
24+
script: |
25+
cd python/prod_source_code/
26+
git pull origin main
27+
source .venv/bin/activate
28+
pip install -r requirements.txt
29+
alembic upgrade head
30+
31+
on-failure:
32+
runs-on: ubuntu-latest
33+
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
34+
steps:
35+
- run: echo 'The triggering workflow failed'

.github/workflows/cd.staging.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Staging Branch Deployment
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI"]
6+
types:
7+
- completed
8+
branches: [staging]
9+
10+
jobs:
11+
on-success:
12+
runs-on: ubuntu-latest
13+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v3
17+
18+
- name: Use SSH Action
19+
uses: appleboy/ssh-action@v0.1.8
20+
with:
21+
host: ${{ secrets.HOST }}
22+
username: ${{ secrets.USERNAME }}
23+
password: ${{ secrets.PASSWORD }}
24+
script: |
25+
cd python/staging_source_code/
26+
git pull origin staging
27+
source .venv/bin/activate
28+
pip install -r requirements.txt
29+
alembic upgrade head
30+
31+
on-failure:
32+
runs-on: ubuntu-latest
33+
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
34+
steps:
35+
- run: echo 'The triggering workflow failed'

.github/workflows/ci.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, staging, dev, devops-main]
6+
pull_request:
7+
branches: [main, staging, dev, devops-main]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
13+
services:
14+
postgres:
15+
image: postgres:latest
16+
env:
17+
POSTGRES_USER: 'username'
18+
POSTGRES_PASSWORD: "password"
19+
POSTGRES_DB: "test"
20+
ports:
21+
- 5432:5432
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v2
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@v4
29+
with:
30+
python-version: "3.9"
31+
virtual-environment: venv
32+
33+
- name: Install dependencies
34+
run: |
35+
pip install -r requirements.txt
36+
37+
- name: Copy env file
38+
run: cp .env.sample .env
39+
40+
- name: Run app
41+
run: |
42+
python3 main.py &
43+
pid=$!
44+
sleep 10
45+
if ps -p $pid > /dev/null; then
46+
echo "main.py started successfully"
47+
kill $pid
48+
else
49+
echo "main.py failed to start"
50+
exit 1
51+
fi
52+
53+
54+
# - name: Run migrations
55+
# run: |
56+
# activate
57+
# alembic upgrade head
58+
59+
# - name: Run tests
60+
# run: |
61+
# activate
62+
# pytest

.pre-commit-config.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.6.0
4+
hooks:
5+
- id: check-added-large-files
6+
- id: check-ast
7+
- id: check-case-conflict
8+
- id: check-docstring-first
9+
- id: check-json
10+
- id: check-merge-conflict
11+
- id: check-toml
12+
- id: check-yaml
13+
- id: detect-private-key
14+
- id: end-of-file-fixer
15+
- id: trailing-whitespace
16+
- id: mixed-line-ending
17+
- id: requirements-txt-fixer
18+
- repo: https://github.com/astral-sh/ruff-pre-commit
19+
rev: v0.5.2
20+
hooks:
21+
- id: ruff
22+
args: [--fix]
23+
- id: ruff-format
24+
- repo: https://github.com/pre-commit/mirrors-mypy
25+
rev: v1.10.1
26+
hooks:
27+
- id: mypy

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
# fastapi_blog
1+
# FastAPI Blog
2+
3+
FastAPI boilerplate setup

0 commit comments

Comments
 (0)