-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2ed0c9c
Showing
60 changed files
with
7,565 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Build and push 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@v4 | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
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={{date 'YYYY-MM-DD_HH:mm:ss'}},enable=true | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
file: cicd/Dockerfile | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
build-args: | | ||
APP_VERSION=${{ github.ref_name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
name: Test packages | ||
|
||
|
||
on: | ||
push: | ||
branches: ['main'] | ||
pull_request: | ||
|
||
|
||
jobs: | ||
unittest-backend: | ||
name: Unit tests (backend) | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
working-directory: ./backend | ||
services: | ||
postgres: | ||
image: postgres:15-alpine | ||
env: | ||
POSTGRES_HOST_AUTH_METHOD: trust | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
-p 5432:5432 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- 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 --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=my_app_api tests/ | tee pytest-coverage.txt | ||
- name: Print report | ||
if: always() | ||
run: | | ||
cat pytest-coverage.txt | ||
- name: Pytest coverage comment | ||
uses: MishaKav/pytest-coverage-comment@main | ||
if: github.event_name == 'pull_request' | ||
with: | ||
pytest-coverage-path: ./pytest-coverage.txt | ||
title: Coverage Report | ||
badge-title: Code Coverage | ||
hide-badge: false | ||
hide-report: false | ||
create-new-comment: false | ||
hide-comment: false | ||
report-only-changed-files: false | ||
remove-link-from-badge: false | ||
junitxml-path: ./pytest.xml | ||
junitxml-title: Summary | ||
|
||
|
||
linting-backend: | ||
name: Style tests (backend) | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
working-directory: ./backend | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.11 | ||
- uses: isort/isort-action@master | ||
with: | ||
requirementsFiles: "requirements.txt requirements.dev.txt" | ||
- uses: psf/black@stable | ||
- name: Comment if linting failed | ||
if: failure() && github.event_name == 'pull_request' | ||
uses: thollander/actions-comment-pull-request@v2 | ||
with: | ||
message: | | ||
:poop: Code linting failed, use `black` and `isort` to fix it. | ||
linting-frontend: | ||
name: Style tests (frontend) | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
working-directory: ./frontend | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: cd into folder | ||
run: cd frontend | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18' | ||
- name: Install | ||
run: npm ci | ||
- name: Check | ||
run: npm run check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
BSD 3-Clause License | ||
|
||
Copyright (c) 2024 | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
build: | ||
docker compose --file ./cicd/docker-compose.yml build | ||
|
||
up: start | ||
run: start | ||
start: stop | ||
docker compose --file ./cicd/docker-compose.yml up --detach | ||
|
||
stop: | ||
docker compose --file ./cicd/docker-compose.yml down | ||
|
||
configure: | ||
cd backend && python3.11 -m venv venv | ||
cd backend && source ./venv/bin/activate && pip install -r requirements.dev.txt -r requirements.txt | ||
cd frontend && npm install | ||
|
||
format: | ||
cd backend && source ./venv/bin/activate && autoflake -r --in-place --remove-all-unused-imports ./my_app_api | ||
cd backend && source ./venv/bin/activate && isort ./my_app_api | ||
cd backend && source ./venv/bin/activate && black ./my_app_api | ||
cd frontend && npm run lint | ||
cd frontend && npm run format | ||
cd frontend && npm run stylelint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Пример приложения | ||
|
||
В этом репозитории представлен пример простейшего сервиса с использованием Python FastAPI приложения | ||
в качестве бэкэнда приложения, и Vue.js приложения в качестве фронтенда. | ||
|
||
|
||
## Рекомендуемые пакеты для разработки | ||
- Git | ||
- Make | ||
- Docker | ||
- Docker Compose | ||
- Python 3.12 | ||
- Node.js v18 | ||
- VS Code | ||
|
||
|
||
## Инструкции | ||
### Получение кода на свой компьютер | ||
Для работы с данным примером необходимо забрать его к себе на ПК. Для этого нужно: | ||
1. *(Опционально)* Если вы хотите далее опубликовать код на GitHub полезно сначала скопировать | ||
репозиторий к себе кнопкой Fork на GitHub. Кнопка доступна в правом верхнем углу | ||
[страницы репозитория](https://github.com/profcomff/app-template). | ||
2. Создайте папку в удобном вам расположении. | ||
- *Удобно создать папку на рабочем столе с названием вашего приложения.* | ||
3. Откройте приложение "Командная строка" или "Терминал", в зависимости от операционной системы. | ||
4. Прейдите в папку проекта командой `cd /путь/к/папке`. | ||
- Если вы пользователь windows и создали на рабочем столе папку `my_app`, то команда будет | ||
выглядеть так: `cd %userprofile%/Desktop/my_app` | ||
- Если вы пользователь linux или MacOS и создали на рабочем столе папку `my_app`, то команда | ||
будет выглядеть сделующим образом: `cd ~/Desktop/my_app` | ||
5. Склонируйте код репозитория к себе на ПК командой | ||
`git clone https://github.com/profcomff/app-template.git .` (точка в конце означает скачивание | ||
кода в текущую папку). Если вы выполнили пункт 1 используйте в команде ссылку из зеленой кнопки | ||
"Code" в правом верхнем углу вашего репозитория. | ||
6. Откройте код в удобной среде разработки. Рекомендуем использовать VSCode, который можно открыть | ||
из терминала командой `code .` | ||
|
||
### Сборка и запуск приложения для публикации | ||
Сборка исходного кода в один пакет производится с помощью Docker. В этом случае создается | ||
независимый от операционной системы пакет, который можно без проблем разместить на любом сервере. | ||
|
||
Выполните команду `make` для сборки приложения. После окончания выполнения этой команды будет создан | ||
новый Docker образ с названием `my_app`, который можно запустить командой `make run` | ||
|
||
### Разработка API на Python | ||
Код приложения находится в папке `backend`. Подробную инструкцию можно найти в [README.md](backend/README.md). | ||
|
||
### Frontend разработка на Vue.js | ||
Код приложения находится в папке `frontend`. Подробную инструкцию можно найти в [README.md](frontend/README.md). | ||
|
||
### Написание документации | ||
Код документации находится в папке `docs`. Подробную инструкцию можно найти в [README.md](docs/README.md). | ||
|
||
### Автосборка | ||
Коммит в main запускает автоматическую сборку проекта средствами GitHub Actions. Настройки автосборки находятся в | ||
файле [.github/workflows/build_and_publish.yml](.github/workflows/build_and_publish.yml). | ||
|
||
### Тесты на Pull Request | ||
При создании запроса на слияние, автоматически создаются проверки кода юниттестами и на стили. | ||
Следующие тесты будут запущены: | ||
- Проверки `isort` на верную сортировку импортов в папке `backend` | ||
- Проверки `black` на верный стиль написания кода в папке `backend` | ||
- Юнит тесты `pytest` из папки [tests](backend/tests) на код в папке `backend` | ||
- Проверки стилей `eslint`, `prettier`, `stylelint` на код в папке `frontend` | ||
|
||
Настройки автотестов находятся в файле[.github/workflows/checks.yml](.github/workflows/checks.yml). | ||
|
||
### Публикация готового приложения | ||
TODO: Предложить быстрый и бесплатный способ деплоя Docker контейнеров |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
venv/ | ||
requirements.dev.txt |
Oops, something went wrong.