Открыть боковую панель
Профком студентов физического факультета МГУ
FastAPI Project Template
Коммиты
c51f4408
Не подтверждена
Коммит
c51f4408
создал
Мар 17, 2023
по автору
Dyakov Roman
Зафиксировано автором
GitHub
Мар 17, 2023
Просмотр файлов
Fix auto CI
владелец
2bb6707d
Изменения
7
Скрыть пробелы
Построчно
Рядом
{{cookiecutter.repo_name}}/.github/workflows/build_and_publish.yml
0 → 100644
Просмотр файла @
c51f4408
name
:
Build, publish and deploy docker
on
:
push
:
branches
:
[
'
main'
]
tags
:
-
'
v*'
env
:
REGISTRY
:
ghcr.io
IMAGE_NAME
:
{{
"
${{
github.repository
}}"
}}
jobs
:
build-and-push-image
:
name
:
Build and push
runs-on
:
ubuntu-latest
permissions
:
contents
:
read
packages
:
write
steps
:
-
name
:
Checkout repository
uses
:
actions/checkout@v2
-
name
:
Log in to the Container registry
uses
:
docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with
:
registry
:
{{
"
${{
env.REGISTRY
}}"
}}
username
:
{{
"
${{
github.actor
}}"
}}
password
:
{{
"
${{
secrets.GITHUB_TOKEN
}}"
}}
-
name
:
Extract metadata (tags, labels) for Docker
id
:
meta
uses
:
docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with
:
images
:
{{
"
${{
env.REGISTRY
}}"
}}
/{{"${{ env.IMAGE_NAME }}"}}
tags
:
|
type=ref,event=tag,enable={{"${{ startsWith(github.ref, 'refs/tags/v') }}"}}
type=raw,value=latest,enable={{"${{ startsWith(github.ref, 'refs/tags/v') }}"}}
type=raw,value=test,enable=true
-
name
:
Build and push Docker image
uses
:
docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with
:
context
:
.
push
:
true
tags
:
{{
"
${{
steps.meta.outputs.tags
}}"
}}
labels
:
{{
"
${{
steps.meta.outputs.labels
}}"
}}
build-args
:
|
APP_VERSION={{"${{ github.ref_name }}"}}
deploy-testing
:
name
:
Deploy Testing
needs
:
build-and-push-image
runs-on
:
[
self-hosted
,
Linux
]
environment
:
name
:
Testing
url
:
https://{{cookiecutter.module_name}}.api.test.profcomff.com/
env
:
CONTAITER_NAME
:
com_profcomff_api_{{cookiecutter.module_name}}_test
permissions
:
packages
:
read
steps
:
-
name
:
Pull new version
run
:
docker pull {{"${{ env.REGISTRY }}"}}/{{"${{ env.IMAGE_NAME }}"}}:test
-
name
:
Migrate DB
run
:
|
docker run \
--rm \
--network=web \
--env DB_DSN={{"${{ secrets.DB_DSN }}"}} \
--name {{"${{ env.CONTAITER_NAME }}"}}_migration \
--workdir="/" \
{{"${{ env.REGISTRY }}"}}/{{"${{ env.IMAGE_NAME }}"}}:test \
alembic upgrade head
-
name
:
Run new version
id
:
run_test
run
:
|
docker stop {{"${{ env.CONTAITER_NAME }}"}} || true && docker rm {{"${{ env.CONTAITER_NAME }}"}} || true
docker run \
--detach \
--restart on-failure:3 \
--network=web \
--env DB_DSN='{{"${{ secrets.DB_DSN }}"}}' \
--env ROOT_PATH='/{{cookiecutter.module_name}}' \
--env AUTH_URL='https://api.test.profcomff.com/auth' \
--env GUNICORN_CMD_ARGS='--log-config logging_test.conf' \
--name {{"${{ env.CONTAITER_NAME }}"}} \
{{"${{ env.REGISTRY }}"}}/{{"${{ env.IMAGE_NAME }}"}}:test
deploy-production
:
name
:
Deploy Production
needs
:
build-and-push-image
if
:
startsWith(github.ref, 'refs/tags/v')
runs-on
:
[
self-hosted
,
Linux
]
environment
:
name
:
Production
url
:
https://{{cookiecutter.module_name}}.api.profcomff.com/
env
:
CONTAITER_NAME
:
com_profcomff_api_{{cookiecutter.module_name}}
permissions
:
packages
:
read
steps
:
-
name
:
Pull new version
run
:
docker pull {{"${{ env.REGISTRY }}"}}/{{"${{ env.IMAGE_NAME }}"}}:latest
-
name
:
Migrate DB
run
:
|
docker run \
--rm \
--network=web \
--env DB_DSN={{"${{ secrets.DB_DSN }}"}} \
--name {{"${{ env.CONTAITER_NAME }}"}}_migration \
--workdir="/" \
{{"${{ env.REGISTRY }}"}}/{{"${{ env.IMAGE_NAME }}"}}:latest \
alembic upgrade head
-
name
:
Run new version
id
:
run_test
run
:
|
docker stop {{"${{ env.CONTAITER_NAME }}"}} || true && docker rm {{"${{ env.CONTAITER_NAME }}"}} || true
docker run \
--detach \
--restart always \
--network=web \
--env DB_DSN='{{"${{ secrets.DB_DSN }}"}}' \
--env ROOT_PATH='/{{cookiecutter.module_name}}' \
--env AUTH_URL='https://api.profcomff.com/auth' \
--env GUNICORN_CMD_ARGS='--log-config logging_prod.conf' \
--name {{"${{ env.CONTAITER_NAME }}"}} \
{{"${{ env.REGISTRY }}"}}/{{"${{ env.IMAGE_NAME }}"}}:latest
{{cookiecutter.repo_name}}/.github/workflows/tests.yml
0 → 100644
Просмотр файла @
c51f4408
name
:
Python package
on
:
pull_request
:
jobs
:
test
:
name
:
Unit tests
runs-on
:
ubuntu-latest
steps
:
-
name
:
Checkout
uses
:
actions/checkout@v3
-
name
:
Set up docker
uses
:
docker-practice/actions-setup-docker@master
-
name
:
Run postgres
run
:
|
docker run -d -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust --name db-test postgres:15-alpine
-
uses
:
actions/setup-python@v4
with
:
python-version
:
'
3.11'
-
name
:
Install dependencies
run
:
|
python -m ensurepip
python -m pip install --upgrade --no-cache-dir pip
python -m pip install --upgrade --no-cache-dir -r requirements.txt -r requirements.dev.txt
-
name
:
Migrate DB
run
:
|
DB_DSN=postgresql://postgres@localhost:5432/postgres alembic upgrade head
-
name
:
Build coverage file
run
:
|
DB_DSN=postgresql://postgres@localhost:5432/postgres pytest --cache-clear --showlocals --cov={{cookiecutter.module_name}} tests > pytest-coverage.txt
-
name
:
Print report
if
:
always()
run
:
|
cat pytest-coverage.txt
-
name
:
Comment coverage
uses
:
coroo/pytest-coverage-commentator@v1.0.2
{{cookiecutter.repo_name}}/Makefile
Просмотр файла @
c51f4408
run
:
source
./venv/bin/activate
&&
uvicorn
--reload
--log-config
logging_test.conf
{{
cookiecutter.module_name
}}
.routes.base:app
source
./venv/bin/activate
&&
uvicorn
--reload
--log-config
logging_dev.conf
{{
cookiecutter.module_name
}}
.routes.base:app
configure
:
venv
source
./venv/bin/activate
&&
pip
install
-r
requirements.dev.txt
-r
requirements.txt
venv
:
python3.11
-m
venv venv
format
:
autoflake
-r
--in-place
--remove-all-unused-imports
./
{{
cookiecutter.module_name
}}
isort ./
{{
cookiecutter.module_name
}}
black ./
{{
cookiecutter.module_name
}}
db
:
docker run
-d
-p
5432:5432
-e
POSTGRES_HOST_AUTH_METHOD
=
trust
--name
db-
{{
cookiecutter.module_name
}}
postgres:15
sleep
3
migrate
:
alembic upgrade
head
{{cookiecutter.repo_name}}/logging_dev.conf
0 → 100644
Просмотр файла @
c51f4408
[
loggers
]
keys
=
root
[
handlers
]
keys
=
all
[
formatters
]
keys
=
main
[
logger_root
]
level
=
DEBUG
handlers
=
all
[
handler_all
]
class
=
StreamHandler
formatter
=
main
level
=
DEBUG
args
=(
sys
.
stdout
,)
[
formatter_main
]
format
=%(
asctime
)
s
%(
levelname
)-
8
s
%(
name
)-
15
s
%(
message
)
s
{{cookiecutter.repo_name}}/pyproject.toml
Просмотр файла @
c51f4408
[tool.black]
line-length
=
120
target-version
=
['py31
0
']
target-version
=
['py31
1
']
skip-string-normalization
=
true
[tool.isort]
...
...
{{cookiecutter.repo_name}}/requirements.dev.txt
Просмотр файла @
c51f4408
autoflake
black
httpx
isort
pytest
pytest-cov
pytest-mock
{{cookiecutter.repo_name}}/requirements.txt
Просмотр файла @
c51f4408
alembic
auth-lib-profcomff[fastapi]
fastapi
fastapi-sqlalchemy
gunicorn
logging-profcomff
psycopg2-binary
pydantic[dotenv]
uvicorn
alembic
SQLAlchemy
gunicorn
logging-profcomff
auth-lib-profcomff[fastapi]
uvicorn
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать