Skip to content

Commit

Permalink
stage commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Reagent992 committed Jan 27, 2024
1 parent 1de2b8a commit b36ec5d
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ venv
db.sqlite3
.idea
.vscode
.env
.env
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
with:
context: .
push: true
tags: ${{ secrets.DOCKER_NICKNAME }}/ipr_backend:latest
tags: ${{ secrets.DOCKER_NICKNAME }}/backend_ipr:latest

build_gateway_and_push_to_docker_hub:
if: github.ref == 'refs/heads/master'
Expand All @@ -48,7 +48,7 @@ jobs:
with:
context: ./nginx/
push: true
tags: ${{ secrets.DOCKER_NICKNAME }}/ipr_gateway:latest
tags: ${{ secrets.DOCKER_NICKNAME }}/gateway_ipr:latest

deploy:
if: github.ref == 'refs/heads/master'
Expand Down Expand Up @@ -82,4 +82,4 @@ jobs:
sudo docker compose -f docker-compose.production.yml up -d
sudo docker compose -f docker-compose.production.yml exec backend python manage.py migrate
sudo docker compose -f docker-compose.production.yml exec backend python manage.py collectstatic
sudo docker compose -f docker-compose.production.yml exec backend cp -r /app/collected_static/. /static/static_backend/
sudo docker compose -f docker-compose.production.yml exec backend cp -r /app/static/. /static/
23 changes: 18 additions & 5 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
USE_POSTGRESQL = env.bool("USE_POSTGRESQL", default=False)
DEBUG = env.bool("DEBUG", default=False)
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=["localhost", "127.0.0.1"])
DB_NAME = env.str("DB_NAME", default="IPR")
DB_USER = env.str("POSTGRES_USER", default="username")
DB_PASSWORD = env.str("POSTGRES_PASSWORD", default="smart-password123")
DB_HOST = env.str("DB_HOST", default="db")
DB_PORT = env.int("DB_PORT", default=5432)
CORS_ALLOWED_ORIGINS = [
"https://ipr.ddns.net",
"http://ipr.ddns.net",
"ipr.ddns.net",
]

# -----------------------------------------------------------------------------
BASE_DIR = Path(__file__).resolve().parent.parent

Expand Down Expand Up @@ -79,11 +90,11 @@
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.getenv("DB_NAME"),
"USER": os.getenv("POSTGRES_USER"),
"PASSWORD": os.getenv("POSTGRES_PASSWORD"),
"HOST": os.getenv("DB_HOST"),
"PORT": os.getenv("DB_PORT"),
"NAME": DB_NAME,
"USER": DB_USER,
"PASSWORD": DB_PASSWORD,
"HOST": DB_HOST,
"PORT": DB_PORT,
}
}
else:
Expand Down Expand Up @@ -135,6 +146,8 @@
],
"PAGE_SIZE": 10,
"DEFAULT_AUTHENTICATION_CLASSES": [
"rest_framework.authentication.BasicAuthentication",
"rest_framework.authentication.BasicAuthentication",
"rest_framework_simplejwt.authentication.JWTAuthentication",
],
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
Expand Down
17 changes: 14 additions & 3 deletions docker-compose.production.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
version: '3'

volumes:
pg_data:
static:
media:

services:
db:
image: postgres:13
env_file: .env
volumes:
- pg_data:/var/lib/postgresql/data
backend:
image: reamisd/backend_ipr:latest
env_file: .env
depends_on:
- db
volumes:
- static:/app/static
- media:/app/media
gateway:
image: nginx:latest
depends_on:
- backend
image: reamisd/gateway_ipr:latest
env_file: .env
ports:
- "8000:80"
- "8080:80"
volumes:
- static:/static
- media:/media
- media:/media
- ./default.conf:/etc/nginx/conf.d/default.conf
- ./error.log:/var/log/nginx/error.log
- ./access.log:/var/log/nginx/access.log
10 changes: 9 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
version: '3'

volumes:
pg_data:
static:
media:

services:
db:
image: postgres:13
env_file: .env
volumes:
- pg_data:/var/lib/postgresql/data
backend:
build: .
env_file: .env
depends_on:
- db
volumes:
- static:/app/static
- media:/app/media
Expand All @@ -20,4 +28,4 @@ services:
- "80:80"
volumes:
- static:/static
- media:/media
- media:/media
72 changes: 2 additions & 70 deletions ipr/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,14 @@
# Generated by Django 5.0.1 on 2024-01-21 17:20
# Generated by Django 5.0.1 on 2024-01-27 13:53

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
dependencies = []

operations = [
migrations.CreateModel(
name="Comment",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
],
),
migrations.CreateModel(
name="Task",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
],
),
migrations.CreateModel(
name="IPR",
fields=[
Expand Down Expand Up @@ -103,42 +71,6 @@ class Migration(migrations.Migration):
default=0, verbose_name="Удобство создания ИПР"
),
),
(
"comment",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="comment_ipr",
to="ipr.comment",
verbose_name="Комментарий к ИПР",
),
),
(
"creator",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="creator_ipr",
to=settings.AUTH_USER_MODEL,
verbose_name="Создатель ИПР",
),
),
(
"executor",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="executor_ipr",
to=settings.AUTH_USER_MODEL,
verbose_name="Исполнитель ИПР",
),
),
(
"task",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="task_ipr",
to="ipr.task",
verbose_name="Задача",
),
),
],
options={
"verbose_name": "ИПР",
Expand Down
13 changes: 13 additions & 0 deletions nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
server {
listen 80;
server_name _;

location / {
proxy_pass http://backend:8000;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 10m;
}
}
33 changes: 14 additions & 19 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
server {
listen 80;
index index.html;
client_max_body_size 20M;
server_tokens off;
listen 80;
server_name _;

location /static/ {
alias /static/;
}

location /api/v1/ {
proxy_set_header Host $http_host;
proxy_pass http://backend:8000/api/v1/;
}
location /admin/ {
proxy_set_header Host $http_host;
proxy_pass http://backend:8000/admin/;
}
location /media/ {
alias /media/;
}
location /static/ {
alias /static/;
}
}
location / {
proxy_pass http://backend:8000;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 10m;
}
}

0 comments on commit b36ec5d

Please sign in to comment.