Skip to content

Commit

Permalink
Merge pull request #103 from Pet-projects-CodePET/develop
Browse files Browse the repository at this point in the history
merge c develop
  • Loading branch information
VladislavCR authored Mar 9, 2024
2 parents ab07608 + 5d72860 commit 2c646c4
Show file tree
Hide file tree
Showing 20 changed files with 453 additions and 95 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Login to Docker
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push to DockerHub
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: ./
push: true
Expand All @@ -30,16 +30,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Login to Docker
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push to DockerHub
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: ./infra/nginx/
push: true
Expand All @@ -52,7 +52,7 @@ jobs:
- build_and_push_to_docker_hub_nginx
steps:
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Create project directory and .env-file
uses: appleboy/ssh-action@master
with:
Expand All @@ -78,6 +78,8 @@ jobs:
EMAIL_HOST=${{ secrets.EMAIL_HOST }}
EMAIL_HOST_USER=${{ secrets.EMAIL_HOST_USER }}
EMAIL_HOST_PASSWORD=${{ secrets.EMAIL_HOST_PASSWORD }}
NEXT_PUBLIC_CAPTCHA_SITE_KEY=${{ secrets.NEXT_PUBLIC_CAPTCHA_SITE_KEY }}
NEXT_SHARP_PATH=${{ secrets.NEXT_SHARP_PATH }}
_EOF_
- name: Copy docker-compose-prod.yaml via ssh
uses: appleboy/scp-action@master
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/qa_deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ jobs:
DOCKERHUB_USERNAME_FRONT=${{ secrets.DOCKERHUB_USERNAME_FRONT }}
DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
ALLOWED_HOSTS=${{ secrets.ALLOWED_HOSTS }}
EMAIL_HOST=${{ secrets.EMAIL_HOST }}
EMAIL_HOST_USER=${{ secrets.EMAIL_HOST_USER }}
EMAIL_HOST_PASSWORD=${{ secrets.EMAIL_HOST_PASSWORD }}
NEXT_PUBLIC_CAPTCHA_SITE_KEY=${{ secrets.NEXT_PUBLIC_CAPTCHA_SITE_KEY }}
NEXT_SHARP_PATH=${{ secrets.NEXT_SHARP_PATH }}
_EOF_
- name: Copy docker-compose-prod.yaml via ssh
uses: appleboy/scp-action@master
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repos:
rev: v4.5.0
hooks:
- id: no-commit-to-branch
args: [-b main, -b develop]
args: [-b, main, -b, develop]
- id: detect-private-key
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
Expand Down
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ RUN apt-get update && apt-get install -y vim

RUN pip install -r requirements.txt --no-cache-dir

COPY . .

WORKDIR /backend/src/backend
COPY /src/backend/. .

CMD gunicorn --bind 0.0.0.0:8000 config.wsgi
17 changes: 9 additions & 8 deletions .env.example → infra/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ ALLOWED_HOSTS=localhost,127.0.0.1,
USE_SQLITE=True

# Для PostgeSQL
# DB_ENGINE=django.db.backends.postgresql
# DB_NAME=
# POSTGRES_USER=
# POSTGRES_PASSWORD=
# DB_HOST=
# DB_PORT=
DB_ENGINE=django.db.backends.postgresql
POSTGRES_DB=
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_HOST=
POSTGRES_PORT=

# Переменные для работы с docker.
DOCKERHUB_USERNAME=username
PROJECT_NAME=project_name
DOCKERHUB_USERNAME_FRONT=
DOCKERHUB_USERNAME=
PROJECT_NAME=
1 change: 0 additions & 1 deletion infra/dir.info

This file was deleted.

20 changes: 7 additions & 13 deletions infra/docker-compose-dev.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
services:

db:
image: postgres:latest
image: postgres:16.2-alpine
restart: always
ports:
- "5432:5432"
env_file: .env
volumes:
- db_value:/var/lib/postgresql/data/
environment:
- POSTGRES_DB=db
- POSTGRES_USER=admin
- POSTGRES_PASSWORD=admin


backend:
image: ${DOCKERHUB_USERNAME}/${PROJECT_NAME}_backend:latest
build: ../.
env_file: .env
ports:
- "8000:8000"
volumes:
- static_volume:/backend_static
- static_volume:/backend_static/
- ./.env:/app
depends_on:
- db

nginx:
image: ${DOCKERHUB_USERNAME}/${PROJECT_NAME}_nginx:latest
build: ./nginx/.
ports:
- "80:80"
- "443:443"
volumes:
- static_volume:/static
- static_volume:/staticfiles/
- /etc/letsencrypt:/etc/letsencrypt
depends_on:
- backend
Expand Down
40 changes: 26 additions & 14 deletions infra/docker-compose-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,53 @@ volumes:

services:
db:
image: postgres:latest
image: postgres:16.2-alpine
restart: unless-stopped
env_file: .env
ports:
- "5432:5432"
healthcheck:
test:
[
"CMD-SHELL",
"pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_PASSWORD}"
]
interval: 5s
timeout: 3s
retries: 5
volumes:
- pg_data:/var/lib/postgresql/data

backend:
image: ${DOCKERHUB_USERNAME}/${PROJECT_NAME}_backend:latest
restart: unless-stopped
env_file: .env
ports:
- "8000:8000"
volumes:
- static_volume:/backend_static/
- media_value:/backend_media/
depends_on:
- db
db:
condition: service_healthy

frontend:
image: ${DOCKERHUB_USERNAME_FRONT}/${PROJECT_NAME}_frontend:latest
command: cp -r out/. /frontend_static/
env_file: .env
volumes:
- static_volume:/frontend_static
depends_on:
db:
condition: service_healthy

nginx:
image: ${DOCKERHUB_USERNAME}/${PROJECT_NAME}_nginx:latest
ports:
- "80:80"
- "443:443"
volumes:
- static_volume:/staticfiles/
- media_value:/var/html/media/
- /etc/letsencrypt:/etc/letsencrypt
depends_on:
- backend

frontend:
image: ${DOCKERHUB_USERNAME_FRONT}/${PROJECT_NAME}_frontend:latest
env_file: .env
ports:
- "3000:3000"
volumes:
- static_volume:/frontend_static
depends_on:
- backend
- frontend
2 changes: 1 addition & 1 deletion infra/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM nginx:latest
FROM nginx:1.25.4-alpine-slim
COPY nginx.conf /etc/nginx/templates/default.conf.template
13 changes: 9 additions & 4 deletions infra/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
server {
listen 80;
listen [::]:80;
server_name 89.23.117.80 devcodepet.tw1.ru 89.23.117.168 testcodepet.tw1.ru;
server_name 89.23.117.80 devcodepet.tw1.ru 89.23.117.168 testcodepet.tw1.ru localhost;

root /staticfiles;

location /api/v1/ {
proxy_set_header Host $http_host;
Expand All @@ -12,8 +14,11 @@ server {
proxy_pass http://backend:8000/admin/;
}
location / {
alias /staticfiles/;
index index.html;
try_files $uri $uri/ /index.html;
try_files $uri $uri.html $uri/ =404;
}

error_page 404 /404.html;
location = /404.html {
internal;
}
}
6 changes: 0 additions & 6 deletions src/backend/apps/general/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,3 @@
TITLE_LENGTH = 100
DESCRIPRION_LENGTH = 250
MAX_LENGTH_EMAIL = 256
EMAIL_HELP_TEXT = (
"Допускается локальная часть 2 - 192 символа, доменная часть 3 - 63 "
"символа, только латинские буквы в нижнем регистре, цифры и символы "
"@/./+/-/_"
)
EMAIL_ERROR_TEXT = "Не корректный email."
11 changes: 0 additions & 11 deletions src/backend/apps/general/validators.py

This file was deleted.

9 changes: 7 additions & 2 deletions src/backend/apps/users/constants.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from django.utils.translation import gettext_lazy as _

MAX_LENGTH_USERNAME = 30
MIN_LENGTH_USERNAME = 2
USERNAME_REGEX = r"^[A-Za-zА-Яа-я0-9_.-]+\Z"
USERNAME_ERROR_REGEX_TEXT = (
"Допустимые символы: кирилические или латинсикие буквы, цифры и /./-/_"
)
USERNAME_HELP_TEXT = (
f"Обязательное поле. {MAX_LENGTH_USERNAME} символов или меньше. Допустимые "
"символы: буквы, цифры и @/./+/-/_"
f"Обязательное поле. От {MIN_LENGTH_USERNAME} до {MAX_LENGTH_USERNAME} "
f" символов. {USERNAME_ERROR_REGEX_TEXT}"
)
USERNAME_ERROR_TEXT = _("A user with that username already exists.")
27 changes: 13 additions & 14 deletions src/backend/apps/users/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 5.0.1 on 2024-02-19 15:25
# Generated by Django 5.0.1 on 2024-03-06 10:16

import apps.general.validators
import apps.users.models
import django.core.validators
from django.db import migrations, models


Expand Down Expand Up @@ -61,26 +61,25 @@ class Migration(migrations.Migration):
),
("created", models.DateTimeField(auto_now_add=True)),
("modified", models.DateTimeField(auto_now=True)),
(
"email",
models.EmailField(
help_text="Допускается локальная часть 2 - 192 символа, доменная часть 3 - 63 символа, только латинские буквы в нижнем регистре, цифры и символы @/./+/-/_",
max_length=256,
unique=True,
validators=[
apps.general.validators.CustomEmailValidator()
],
),
),
("email", models.EmailField(max_length=256, unique=True)),
(
"username",
models.CharField(
error_messages={
"unique": "A user with that username already exists."
},
help_text="Обязательное поле. 30 символов или меньше. Допустимые символы: буквы, цифры и @/./+/-/_",
help_text="Обязательное поле. От 2 до 30 символов. Допустимые символы: кирилические или латинсикие буквы, цифры и /./-/_",
max_length=30,
unique=True,
validators=[
django.core.validators.MinLengthValidator(
limit_value=2
),
django.core.validators.RegexValidator(
message="Допустимые символы: кирилические или латинсикие буквы, цифры и /./-/_",
regex="^[A-Za-zА-Яа-я0-9_.-]+\\Z",
),
],
verbose_name="username",
),
),
Expand Down
15 changes: 11 additions & 4 deletions src/backend/apps/users/models.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from django.contrib.auth.models import AbstractUser, UserManager
from django.core.validators import MinLengthValidator, RegexValidator
from django.db import models
from django.utils.translation import gettext_lazy as _

from apps.general.constants import EMAIL_HELP_TEXT, MAX_LENGTH_EMAIL
from apps.general.constants import MAX_LENGTH_EMAIL
from apps.general.models import CreatedModifiedFields
from apps.general.validators import CustomEmailValidator
from apps.users.constants import (
MAX_LENGTH_USERNAME,
MIN_LENGTH_USERNAME,
USERNAME_ERROR_REGEX_TEXT,
USERNAME_ERROR_TEXT,
USERNAME_HELP_TEXT,
USERNAME_REGEX,
)


Expand Down Expand Up @@ -36,8 +39,6 @@ class User(CreatedModifiedFields, AbstractUser):
max_length=MAX_LENGTH_EMAIL,
unique=True,
blank=False,
help_text=EMAIL_HELP_TEXT,
validators=[CustomEmailValidator()],
)
username = models.CharField(
_("username"),
Expand All @@ -47,6 +48,12 @@ class User(CreatedModifiedFields, AbstractUser):
error_messages={
"unique": USERNAME_ERROR_TEXT,
},
validators=[
MinLengthValidator(limit_value=MIN_LENGTH_USERNAME),
RegexValidator(
regex=USERNAME_REGEX, message=USERNAME_ERROR_REGEX_TEXT
),
],
)

USERNAME_FIELD = "email"
Expand Down
6 changes: 3 additions & 3 deletions src/backend/config/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
DEBUG = False


EMAIL_USE_TLS = False
EMAIL_USE_SSL = True
EMAIL_PORT = 465
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
EMAIL_PORT = 587
1 change: 0 additions & 1 deletion src/backend/data/fixtures/dir.info

This file was deleted.

Loading

0 comments on commit 2c646c4

Please sign in to comment.