Skip to content

Commit

Permalink
First release (#247)
Browse files Browse the repository at this point in the history
Co-authored-by: merkme <[email protected]>
Co-authored-by: Anton Braun <[email protected]>
Co-authored-by: DianaKim9319 <[email protected]>
Co-authored-by: Pavel Nesterov <[email protected]>
Co-authored-by: Павел Нестеров <[email protected]>
Co-authored-by: Dmitriy Bratkov <[email protected]>
Co-authored-by: Mitsushidu <[email protected]>
Co-authored-by: Mitsushidu <[email protected]>
Co-authored-by: Евгений Фастунов <[email protected]>
Co-authored-by: Aleksandr Bynkov <[email protected]>
Co-authored-by: «Дмитрий <«[email protected]»>
Co-authored-by: frailtynine <[email protected]>
Co-authored-by: Sergey Mazilin <[email protected]>
Co-authored-by: alexpunder <[email protected]>
Co-authored-by: serega-zhulanov <[email protected]>
Co-authored-by: Калаганов Артём <[email protected]>
Co-authored-by: Ilya <[email protected]>
Co-authored-by: Дмитрий Петров <[email protected]>
Co-authored-by: Neizalik <[email protected]>
Co-authored-by: Ruslan Kuznetsov <[email protected]>
Co-authored-by: MrGosling <[email protected]>
Co-authored-by: Юшко Юрий <[email protected]>
Co-authored-by: Valera Shankorenko <[email protected]>
Co-authored-by: Valeriya Fedorova <[email protected]>
Co-authored-by: root <root@DESKTOP-7UFPFK6>
Co-authored-by: kudralexandr <[email protected]>
Co-authored-by: kudralexandr <[email protected]>
Co-authored-by: anastasia-D <[email protected]>
Co-authored-by: Daniil V. <[email protected]>
  • Loading branch information
1 parent 37abfb1 commit 64089df
Show file tree
Hide file tree
Showing 135 changed files with 9,885 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
venv
.git
db.sqlite3
**/.env
db copy.sqlite3
collected_static/
.env.dev
sent_emails/
__pycache__/
.env/
.env
45 changes: 45 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Название, логин и пароль для БД postgres
POSTGRES_DB=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
DB_ENGINE=django.db.backends.postgresql_psycopg2
# Данные для подключения к БД
DB_HOST=localhost
DB_PORT=5432

# Переменные Django
# Базовый URL
BASE_URL=https://127.0.0.1:8000
# ПРЕДУПРЕЖДЕНИЕ: Хранить секретный ключ не должен попадать в общий доступ
SECRET_KEY=secret_key
# ПРЕДУПРЕЖДЕНИЕ: Debug = true использовать только при разработке
DEBUG=false
# Список разрешенных хостов
ALLOWED_HOSTS=localhost,127.0.0.1
CSRF_TRUSTED_ORIGINS=https://yourdomain.org

# Переменные бота
# Токен для подключения к Telegram API
TELEGRAM_TOKEN=token

# Конфигурация superuser django
DJANGO_SUPERUSER_USERNAME=admin
DJANGO_SUPERUSER_EMAIL=[email protected]
DJANGO_SUPERUSER_PASSWORD=adminpassword
DJANGO_SUPERUSER_FIRSTNAME=Admin
DJANGO_SUPERUSER_LASTNAME=User
DJANGO_SUPERUSER_PHONE=+74950000000

# Конфигурация почтового агента
EMAIL_BACKEND=django.core.mail.backends.console.EmailBackend
EMAIL_HOST=smtp.yandex.ru
EMAIL_PORT=465
# реквизиты для аутентификации в почтовом сервисе
EMAIL_HOST_USER=[email protected]
EMAIL_HOST_PASSWORD=your_yandex_smtp_password
EMAIL_USE_SSL=True
# в настройках аккаунта откуда отправляется письмо подключите протокол IMAP
# адрес по умолчанию для отправки вопросов от пользователей
DEFAULT_EMAIL_ADDRESS=NOT_SET
# Запустить бота
RUN_BOT=true
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Bug report
about: Шаблон для описания бага в приложении
title: ''
labels: bug
assignees: ''

---

# Где был обнаружен баг ?

*Описание места и возможных причин бага.*

# Скриншоты

*Сюда добавить возможные скрины с описанием.*

# Предложения и предположения как исправить

*Возможные догадки, как исправить.*
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/docs-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Docs template
about: Оформление Readme и документации
title: ''
labels: documentation
assignees: ''

---

# Что нужно описать?

*Какую часть функционала описываем.*


# Где?

*В какой части репозитория пишем.*
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/new-feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: New feature
about: Шаблон на реализацию нового функционала
title: ''
labels: enhancement
assignees: ''

---

# Зачем?

*Зачем выполняется реализация задачи и какую проблему она решает.*

# Как нужно делать?

*Как мы выполняем реализацию данной задачи, какие действия нужны для достижения цели.*

# Где?

*Где делаем реализацию задачи, какие сервисы задействованы, ссылка на требования, сcылка на API, скриншоты.*
50 changes: 50 additions & 0 deletions .github/workflows/build_and_push_github_packages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build and push Docker image

on:
push:
branches:
- master
- dev

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build_and_push:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image for Production
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v5
with:
context: .
file: infra/prod/prod.Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Build and push Docker image for Stage
if: github.ref == 'refs/heads/dev'
uses: docker/build-push-action@v5
with:
context: .
file: infra/stage/stage.Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
29 changes: 29 additions & 0 deletions .github/workflows/codestyle_ruff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI

on: pull_request

jobs:
ruff:
runs-on: ubuntu-latest
name: ruff
steps:
- name: Установка Python
uses: actions/setup-python@v4
with:
python-version: 3.12

- name: Установка Poetry
uses: snok/install-poetry@v1
with:
poetry-version: 1.7.1

- name: Извлечение репозитория
uses: actions/checkout@v4

- name: Установка зависимостей
run: |
poetry install
- name: ruff
run: |
poetry run ruff check
94 changes: 94 additions & 0 deletions .github/workflows/stage_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Bot stage deploy

on:
workflow_run:
workflows:
- Build and push Docker image
types:
- completed

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
DEPLOY_PATH: Goodstart_telegram_bot

defaults:
run:
working-directory: .

jobs:
deploy:
name: Deploy changes on server
runs-on: ubuntu-latest
environment:
name: stage
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
ref: dev

- name: Set up SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_KNOWN_HOSTS }}" > ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
echo "${{ secrets.HOST_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
- name: Create folder for deploy
run: ssh ${{ secrets.HOST_USERNAME }}@${{ secrets.HOST_IP }} mkdir -p ${{ env.DEPLOY_PATH }}/infra

- name: Copy dev folder to VPS
run: scp -r $GITHUB_WORKSPACE/infra/stage/ ${{ secrets.HOST_USERNAME }}@${{ secrets.HOST_IP }}:${{ env.DEPLOY_PATH }}/infra/

- name: Execute commands on VPS
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_IP }}
username: ${{ secrets.HOST_USERNAME }}
key: ${{ secrets.HOST_SSH_PRIVATE_KEY }}
script: |
cd ${{ env.DEPLOY_PATH }}
rm .env
touch .env
echo POSTGRES_DB=${{ secrets.POSTGRES_DB }} >> .env
echo POSTGRES_USER=${{ secrets.POSTGRES_USER }} >> .env
echo POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} >> .env
echo DB_ENGINE=${{ secrets.DB_ENGINE }} >> .env
echo DB_HOST=${{ secrets.DB_HOST }} >> .env
echo DB_PORT=${{ secrets.DB_PORT }} >> .env
echo BASE_URL=${{ secrets.BASE_URL }} >> .env
echo SECRET_KEY=${{ secrets.SECRET_KEY }} >> .env
echo DEBUG=${{ secrets.DEBUG }} >> .env
echo ALLOWED_HOSTS=${{ secrets.ALLOWED_HOSTS }} >> .env
echo CSRF_TRUSTED_ORIGINS=${{ secrets.CSRF_TRUSTED_ORIGINS }} >> .env
echo TELEGRAM_TOKEN=${{ secrets.TELEGRAM_TOKEN }} >> .env
echo EMAIL_BACKEND=${{ secrets.EMAIL_BACKEND }} >> .env
echo EMAIL_HOST=${{ secrets.EMAIL_HOST }} >> .env
echo EMAIL_PORT=${{ secrets.EMAIL_PORT }} >> .env
echo EMAIL_HOST_USER=${{ secrets.EMAIL_HOST_USER }} >> .env
echo EMAIL_HOST_PASSWORD=${{ secrets.EMAIL_HOST_PASSWORD }} >> .env
echo DEFAULT_EMAIL_ADDRESS=${{ secrets.DEFAULT_EMAIL_ADDRESS }} >> .env
echo NGINX_PORT=${{ secrets.NGINX_PORT }} >> .env
# удалить после мержа в dev
echo DB_NAME=${{ secrets.DB_NAME }} >> .env
echo DB_USERNAME=${{ secrets.DB_USERNAME }} >> .env
echo DB_PASSWORD=${{ secrets.DB_PASSWORD }} >> .env
echo RUN_BOT=${{ secrets.RUN_BOT }} >> .env
# Installing defend service for app
sudo cp -f /home/dev/Goodstart_telegram_bot/infra/stage/goodstart_bot.service /etc/systemd/system/goodstart_bot.service
sudo systemctl daemon-reload
sudo systemctl restart goodstart_bot.service
sleep 10
cd infra/stage
docker-compose -f docker-compose.stage.yaml exec goodstart-bot sh -c "export RUN_BOT=false"
docker-compose -f docker-compose.stage.yaml exec goodstart-bot python manage.py collectstatic --noinput
docker-compose -f docker-compose.stage.yaml exec goodstart-bot cd .. && cd static/material/admin/css/ && sed -i 's/readonly-label{width:170px;height:10px}/readonly-label{width:170px;height:auto}/' change_form.min.css
docker-compose -f docker-compose.stage.yaml exec goodstart-bot python manage.py migrate
docker-compose -f docker-compose.stage.yaml exec goodstart-bot sh -c "export RUN_BOT=true"
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,24 @@ dmypy.json
# Cython debug symbols
cython_debug/

#IDE
wenv/
.vscode

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
.DS_Store
# Django equipments

static/

#SSL certificates
*.pem
# persistence_data
persistence_data/persistence_file
.python-version
.env:Zone.Identifier
41 changes: 41 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: no-commit-to-branch
name: Check to see if a commit is pushed to a safe branch
- id: check-toml
name: Check the files with `.toml` format
- id: check-yaml
name: Check the files with `.yaml` format
args: ['--allow-multiple-documents']
- id: end-of-file-fixer
name: Check for an empty line at the end of a file
- id: trailing-whitespace
name: Check for unnecessary white space
args: ['--markdown-linebreak-ext=md']
- id: check-docstring-first
name: Check docstrings location in python files
- id: check-merge-conflict
name: Сheck for no conflicts in the branch

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.2
hooks:
- id: ruff
types_or: [ python ]

- repo: local
hooks:
- id: export-dev-dependencies
name: Export dev Dependencies
language: system
pass_filenames: false
entry: poetry export --without-hashes --dev --output requirements/dev.txt
files: ^(pyproject.toml|poetry.lock)$
- id: export-prod-dependencies
name: Export prod Dependencies
language: system
pass_filenames: false
entry: poetry export --without-hashes --output requirements/prod.txt
files: ^(pyproject.toml|poetry.lock)$
Loading

0 comments on commit 64089df

Please sign in to comment.