Skip to content

Commit

Permalink
Merge pull request #120 from mikeiken/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Kseen715 authored Dec 10, 2024
2 parents 1c2c55b + 356efb1 commit ce98a5b
Show file tree
Hide file tree
Showing 122 changed files with 5,779 additions and 1,581 deletions.
10 changes: 6 additions & 4 deletions .env-template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## SECRETS --==================================
## SECRETS --------------------------------
RABBITMQ_DEFAULT_USER=
RABBITMQ_DEFAULT_PASS=
# ---
Expand All @@ -15,7 +15,7 @@ DJANGO_SUPER_PASSWORD=
DJANGO_SECRET_KEY=
# ---

## SETTINGS --==================================
## SETTINGS --------------------------------
RABBITMQ_WEB_UI_PORT=15672
RABBITMQ_PORT=5672
RABBITMQ_HOST=rabbitmq
Expand All @@ -26,7 +26,10 @@ POSTGRES_PORT=5432
NGINX_HTTP_PORT=80
NGINX_HTTPS_PORT=443
# ---
REDIS_USER=default
REDIS_PORT=6379
REDIS_DB=0
REDIS_HOST=redis
REDIS_MAXMEMORY=256mb
REDIS_COMMANDER_PORT=8081
# ---
Expand All @@ -49,7 +52,6 @@ CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP=True
CELERY_BROKER_CONNECTION_RETRY=True
CELERY_BROKER_CONNECTION_MAX_RETRIES=10
CELERY_BROKER_HEARTBEAT=10
CELERY_RESULT_BACKEND=rpc://
# Late ack means the task messages will be acknowledged after the task has been executed, not right before [>True</False]
CELERY_TASK_ACKS_LATE=True
# Run tasks synchronously [True/>False<]
Expand All @@ -73,4 +75,4 @@ CELERY_WORKER_REDIRECT_STDOUTS=False
# Log level for task logs [DEBUG/>INFO</WARNING/ERROR/CRITICAL]
CELERY_WORKER_REDIRECT_STDOUTS_LEVEL=INFO
# Custom logging format for tasks
CELERY_WORKER_TASK_LOG_FORMAT=[%(asctime)s: %(levelname)s] Task %(task_name)s[%(task_id)s]: %(message)s
CELERY_WORKER_TASK_LOG_FORMAT="[%(asctime)s: %(levelname)s] Task %(task_name)s[%(task_id)s]: %(message)s"
62 changes: 44 additions & 18 deletions .github/workflows/on-commit-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ on:
branches:
- "**"
- "!main"
pull_request:
branches:
- "**"
- "!main"
types: [opened, synchronize, reopened]
workflow_dispatch:

env:
Expand All @@ -21,50 +16,81 @@ env:
LATEST_TAG: 0.0.0
TOML_VERSION: 0.0.0
#
RABBITMQ_DEFAULT_USER: test
RABBITMQ_DEFAULT_PASS: test
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
REDIS_PASS: test
REDIS_COMMANDER_USER: test
REDIS_COMMANDER_PASS: test
DJANGO_SUPER_USER: test
DJANGO_SUPER_PASSWORD: test
DJANGO_SECRET_KEY: django-insecure-test
#
RABBITMQ_DEFAULT_USER: admin
RABBITMQ_DEFAULT_PASS: password
# ---
POSTGRES_USER: agronom
POSTGRES_PASSWORD: root
POSTGRES_DB: garden
# ---
REDIS_PASS: admin
REDIS_COMMANDER_USER: admin
REDIS_COMMANDER_PASS: admin
# ---
DJANGO_SUPER_USER: admin
DJANGO_SUPER_PASSWORD: admin
DJANGO_SECRET_KEY: django-insecure-sihuf
# ---

RABBITMQ_WEB_UI_PORT: 15672
RABBITMQ_PORT: 5672
RABBITMQ_HOST: rabbitmq
RABBITMQ_VHOST: /
# ---
POSTGRES_PORT: 5432
# ---
NGINX_HTTP_PORT: 80
NGINX_HTTPS_PORT: 443
# ---
REDIS_USER: default
REDIS_PORT: 6379
REDIS_DB: 0
REDIS_HOST: redis
REDIS_MAXMEMORY: 256mb
REDIS_COMMANDER_PORT: 8081
# ---
PORTAINER_PORT: 9000
# ---
SWAGGER_PORT: 8956
# ---
NODEJS_PORT: 3000
# ---
DJANGO_PORT: 8000
DJANGO_DB_HOST: psql
# Web debug interface [True/>False<]
DJANGO_DEBUG: True
DJANGO_ALLOWED_HOSTS: 127.0.0.1,localhost,django
DJANGO_ASYNC_TIMEOUT_S: 30
# ---
# Whether to retry failed connections to the broker on startup [>True</False]
CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP: True
# Whether to retry failed connections to the broker [>True</False]
CELERY_BROKER_CONNECTION_RETRY: True
CELERY_BROKER_CONNECTION_MAX_RETRIES: 10
CELERY_BROKER_HEARTBEAT: 10
CELERY_RESULT_BACKEND: rpc://
# Late ack means the task messages will be acknowledged after the task has been executed, not right before [>True</False]
CELERY_TASK_ACKS_LATE: True
# Run tasks synchronously [True/>False<]
CELERY_TASK_ALWAYS_EAGER: False
# Worker process:
# [
# 'solo' - single process
# >'prefork'< - multiple processes (linux only)
# ]
CELERY_WORKER_POOL: prefork
# Restart worker after each task [>4</tasks]
CELERY_WORKER_MAX_TASKS_PER_CHILD: 4
# Number of worker processes [>2</precesses]
CELERY_WORKER_CONCURRENCY: 2
# Number of tasks to prefetch [>2</tasks]
CELERY_WORKER_PREFETCH_MULTIPLIER: 2
# Whether to store the task return values or not (tombstones) [True/>False<]
CELERY_TASK_IGNORE_RESULT: False
# Configure task logging [True/>False<]
CELERY_WORKER_REDIRECT_STDOUTS: False
# Log level for task logs [DEBUG/>INFO</WARNING/ERROR/CRITICAL]
CELERY_WORKER_REDIRECT_STDOUTS_LEVEL: INFO
# Custom logging format for tasks
CELERY_WORKER_TASK_LOG_FORMAT: "[%(asctime)s: %(levelname)s] Task %(task_name)s[%(task_id)s]: %(message)s"

jobs:
Expand Down
61 changes: 44 additions & 17 deletions .github/workflows/on-commit-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ on:
push:
branches:
- main
pull_request:
branches:
- main
types: [opened, synchronize, reopened]
workflow_dispatch:

env:
Expand All @@ -19,50 +15,81 @@ env:
LATEST_TAG: 0.0.0
TOML_VERSION: 0.0.0
#
RABBITMQ_DEFAULT_USER: test
RABBITMQ_DEFAULT_PASS: test
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
REDIS_PASS: test
REDIS_COMMANDER_USER: test
REDIS_COMMANDER_PASS: test
DJANGO_SUPER_USER: test
DJANGO_SUPER_PASSWORD: test
DJANGO_SECRET_KEY: django-insecure-test
#
RABBITMQ_DEFAULT_USER: admin
RABBITMQ_DEFAULT_PASS: password
# ---
POSTGRES_USER: agronom
POSTGRES_PASSWORD: root
POSTGRES_DB: garden
# ---
REDIS_PASS: admin
REDIS_COMMANDER_USER: admin
REDIS_COMMANDER_PASS: admin
# ---
DJANGO_SUPER_USER: admin
DJANGO_SUPER_PASSWORD: admin
DJANGO_SECRET_KEY: django-insecure-sihuf
# ---

RABBITMQ_WEB_UI_PORT: 15672
RABBITMQ_PORT: 5672
RABBITMQ_HOST: rabbitmq
RABBITMQ_VHOST: /
# ---
POSTGRES_PORT: 5432
# ---
NGINX_HTTP_PORT: 80
NGINX_HTTPS_PORT: 443
# ---
REDIS_USER: default
REDIS_PORT: 6379
REDIS_DB: 0
REDIS_HOST: redis
REDIS_MAXMEMORY: 256mb
REDIS_COMMANDER_PORT: 8081
# ---
PORTAINER_PORT: 9000
# ---
SWAGGER_PORT: 8956
# ---
NODEJS_PORT: 3000
# ---
DJANGO_PORT: 8000
DJANGO_DB_HOST: psql
# Web debug interface [True/>False<]
DJANGO_DEBUG: True
DJANGO_ALLOWED_HOSTS: 127.0.0.1,localhost,django
DJANGO_ASYNC_TIMEOUT_S: 30
# ---
# Whether to retry failed connections to the broker on startup [>True</False]
CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP: True
# Whether to retry failed connections to the broker [>True</False]
CELERY_BROKER_CONNECTION_RETRY: True
CELERY_BROKER_CONNECTION_MAX_RETRIES: 10
CELERY_BROKER_HEARTBEAT: 10
CELERY_RESULT_BACKEND: rpc://
# Late ack means the task messages will be acknowledged after the task has been executed, not right before [>True</False]
CELERY_TASK_ACKS_LATE: True
# Run tasks synchronously [True/>False<]
CELERY_TASK_ALWAYS_EAGER: False
# Worker process:
# [
# 'solo' - single process
# >'prefork'< - multiple processes (linux only)
# ]
CELERY_WORKER_POOL: prefork
# Restart worker after each task [>4</tasks]
CELERY_WORKER_MAX_TASKS_PER_CHILD: 4
# Number of worker processes [>2</precesses]
CELERY_WORKER_CONCURRENCY: 2
# Number of tasks to prefetch [>2</tasks]
CELERY_WORKER_PREFETCH_MULTIPLIER: 2
# Whether to store the task return values or not (tombstones) [True/>False<]
CELERY_TASK_IGNORE_RESULT: False
# Configure task logging [True/>False<]
CELERY_WORKER_REDIRECT_STDOUTS: False
# Log level for task logs [DEBUG/>INFO</WARNING/ERROR/CRITICAL]
CELERY_WORKER_REDIRECT_STDOUTS_LEVEL: INFO
# Custom logging format for tasks
CELERY_WORKER_TASK_LOG_FORMAT: "[%(asctime)s: %(levelname)s] Task %(task_name)s[%(task_id)s]: %(message)s"

jobs:
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
- **Python**
- **Django** (REST API)
- **Celery**
- **RabbitMQ** - брокер сообщений
- **Swagger** - генерация документации для REST API
- **JS**
- **React**
- **PostgreSQL** - СУБД
- **Redis** - LRU-кэш для PostgerSQL
- **Swagger** - генерация документации для REST API
- **RabbitMQ** - брокер сообщений
- **NGINX** - HTTP-сервер и обратный прокси-сервер
- **Docker**

Expand All @@ -29,23 +29,23 @@
После этого необходимо выполнить команду:

### Linux:
```bash
```
./docker-compose-up.sh
```

### Windows:
```powershell
```
./docker-compose-up.ps1
```

При необходимости можно выполнить сборку образов из исходников и запуск контейнеров:

### Linux:
```bash
```
./docker-compose-build-up.sh
```

### Windows:
```powershell
```
./docker-compose-build-up.ps1
```
3 changes: 0 additions & 3 deletions django-createsuperuser.ps1

This file was deleted.

3 changes: 0 additions & 3 deletions django-makemigrations.ps1

This file was deleted.

2 changes: 2 additions & 0 deletions django-manage-py.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./env-inject.ps1
python ./django/tamprog/manage.py $args
53 changes: 35 additions & 18 deletions django/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,53 @@
# Use the official Python image from the Alpine version
FROM python:3.9-alpine
# Build stage
FROM python:3.9-alpine AS builder

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1

# Set the working directory inside the container
WORKDIR /usr/src/app

# Install dependencies
RUN apk update && \
apk add --no-cache gcc musl-dev libffi-dev openssl-dev make postgresql-dev curl
# Install build dependencies and compile requirements
RUN apk add --no-cache --virtual .build-deps \
gcc \
musl-dev \
libffi-dev \
openssl-dev \
make \
postgresql-dev \
&& pip install --upgrade pip

# Copy the requirements file to the working directory
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application code to the working directory
COPY . .
# Runtime stage
FROM python:3.9-alpine

ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1

WORKDIR /usr/src/app

# Install only runtime dependencies
RUN apk add --no-cache libpq curl

# Copy Python packages from builder
COPY --from=builder /usr/local/lib/python3.9/site-packages/ /usr/local/lib/python3.9/site-packages/
COPY --from=builder /usr/local/bin/ /usr/local/bin/

# Copy only necessary project files
COPY tamprog/ tamprog/
COPY entrypoint.sh .

# Collect static files
RUN python tamprog/manage.py collectstatic --noinput
# Collect static files and clean up in single layer
RUN python tamprog/manage.py collectstatic --noinput \
&& find . -type d -name __pycache__ -exec rm -r {} + \
&& rm -rf /root/.cache /tmp/*

# Expose the port the application will run on
EXPOSE 8000

# Add health check
HEALTHCHECK --interval=10s --timeout=5s --retries=5 CMD curl --fail http://localhost:8000/admin || exit 1

WORKDIR /usr/src/app/tamprog

# Run migrations and start the Django development server
ENTRYPOINT ["/bin/sh", "../entrypoint.sh"]
Loading

0 comments on commit ce98a5b

Please sign in to comment.