refactor: project architecture refactor, container splitting

This commit is contained in:
3252a8
2026-05-17 00:01:28 +03:00
parent e0b5218037
commit 30fb774d93
367 changed files with 2609 additions and 864 deletions
+157
View File
@@ -0,0 +1,157 @@
services:
postgres:
image: postgres:17
container_name: remnawave-minishop-postgres
env_file:
- ${APP_ENV_FILE:-../../.env}
volumes:
- remnawave-minishop-db-data:/var/lib/postgresql/data
networks:
- remnawave-network
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
interval: 5s
timeout: 5s
retries: 20
redis:
image: redis:7-alpine
container_name: remnawave-minishop-redis
command: ["redis-server", "--appendonly", "yes"]
volumes:
- remnawave-minishop-redis-data:/data
networks:
- remnawave-network
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 20
migrate:
container_name: remnawave-minishop-migrate
image: ghcr.io/3252a8/remnawave-minishop-backend:${IMAGE_TAG:-latest}
command: ["python", "backend/main_migrate.py"]
env_file:
- ${APP_ENV_FILE:-../../.env}
environment:
IMAGE_TAG: ${IMAGE_TAG:-latest}
POSTGRES_HOST: postgres
REDIS_URL: redis://redis:6379/0
volumes:
- shop-data:/app/data
networks:
- remnawave-network
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
backend:
container_name: remnawave-minishop-backend
image: ghcr.io/3252a8/remnawave-minishop-backend:${IMAGE_TAG:-latest}
env_file:
- ${APP_ENV_FILE:-../../.env}
environment:
IMAGE_TAG: ${IMAGE_TAG:-latest}
POSTGRES_HOST: postgres
REDIS_URL: redis://redis:6379/0
WEBAPP_ENABLED: "true"
volumes:
- shop-data:/app/data
networks:
- remnawave-network
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
migrate:
condition: service_completed_successfully
healthcheck:
test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/healthz', timeout=3).read()\""]
interval: 30s
timeout: 5s
retries: 5
start_period: 30s
worker:
container_name: remnawave-minishop-worker
image: ghcr.io/3252a8/remnawave-minishop-worker:${IMAGE_TAG:-latest}
env_file:
- ${APP_ENV_FILE:-../../.env}
environment:
IMAGE_TAG: ${IMAGE_TAG:-latest}
POSTGRES_HOST: postgres
REDIS_URL: redis://redis:6379/0
volumes:
- shop-data:/app/data
networks:
- remnawave-network
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
migrate:
condition: service_completed_successfully
frontend:
container_name: remnawave-minishop-frontend
image: ghcr.io/3252a8/remnawave-minishop-frontend:${IMAGE_TAG:-latest}
environment:
IMAGE_TAG: ${IMAGE_TAG:-latest}
FRONTEND_PORT: ${FRONTEND_PORT:-8082}
FRONTEND_PUBLIC: via caddy
networks:
- remnawave-network
restart: unless-stopped
depends_on:
backend:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1/health | grep -q ok"]
interval: 30s
timeout: 5s
retries: 5
caddy:
image: caddy:2-alpine
container_name: remnawave-minishop-caddy
environment:
PUBLIC_HOST: ${PUBLIC_HOST:-localhost}
depends_on:
frontend:
condition: service_healthy
backend:
condition: service_healthy
ports:
- "${HTTP_BIND:-0.0.0.0:80}:80"
- "${HTTPS_BIND:-0.0.0.0:443}:443"
volumes:
- ../docker/caddy/Caddyfile:/etc/caddy/Caddyfile:ro
- caddy-data:/data
- caddy-config:/config
networks:
- remnawave-network
restart: unless-stopped
networks:
remnawave-network:
volumes:
remnawave-minishop-db-data:
name: remnawave-minishop-db-data
remnawave-minishop-redis-data:
name: remnawave-minishop-redis-data
shop-data:
name: remnawave-minishop-shop-data
caddy-data:
name: remnawave-minishop-caddy-data
caddy-config:
name: remnawave-minishop-caddy-config
@@ -0,0 +1,136 @@
services:
postgres:
image: postgres:17
container_name: remnawave-minishop-postgres
env_file:
- ${APP_ENV_FILE:-../../.env}
volumes:
- remnawave-minishop-db-data:/var/lib/postgresql/data
networks:
- remnawave-network
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
interval: 5s
timeout: 5s
retries: 20
redis:
image: redis:7-alpine
container_name: remnawave-minishop-redis
command: ["redis-server", "--appendonly", "yes"]
volumes:
- remnawave-minishop-redis-data:/data
networks:
- remnawave-network
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 20
migrate:
container_name: remnawave-minishop-migrate
image: ghcr.io/3252a8/remnawave-minishop-backend:${IMAGE_TAG:-latest}
command: ["python", "backend/main_migrate.py"]
env_file:
- ${APP_ENV_FILE:-../../.env}
environment:
IMAGE_TAG: ${IMAGE_TAG:-latest}
POSTGRES_HOST: postgres
REDIS_URL: redis://redis:6379/0
volumes:
- shop-data:/app/data
networks:
- remnawave-network
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
backend:
container_name: remnawave-minishop-backend
image: ghcr.io/3252a8/remnawave-minishop-backend:${IMAGE_TAG:-latest}
env_file:
- ${APP_ENV_FILE:-../../.env}
environment:
IMAGE_TAG: ${IMAGE_TAG:-latest}
POSTGRES_HOST: postgres
REDIS_URL: redis://redis:6379/0
WEBAPP_ENABLED: "true"
volumes:
- shop-data:/app/data
networks:
- remnawave-network
ports:
- "127.0.0.1:${WEB_SERVER_PORT:-8080}:8080"
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
migrate:
condition: service_completed_successfully
healthcheck:
test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/healthz', timeout=3).read()\""]
interval: 30s
timeout: 5s
retries: 5
start_period: 30s
worker:
container_name: remnawave-minishop-worker
image: ghcr.io/3252a8/remnawave-minishop-worker:${IMAGE_TAG:-latest}
env_file:
- ${APP_ENV_FILE:-../../.env}
environment:
IMAGE_TAG: ${IMAGE_TAG:-latest}
POSTGRES_HOST: postgres
REDIS_URL: redis://redis:6379/0
volumes:
- shop-data:/app/data
networks:
- remnawave-network
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
migrate:
condition: service_completed_successfully
frontend:
container_name: remnawave-minishop-frontend
image: ghcr.io/3252a8/remnawave-minishop-frontend:${IMAGE_TAG:-latest}
environment:
IMAGE_TAG: ${IMAGE_TAG:-latest}
FRONTEND_PORT: ${FRONTEND_PORT:-8082}
FRONTEND_PUBLIC: 127.0.0.1:${FRONTEND_PORT:-8082}->80
networks:
- remnawave-network
ports:
- "127.0.0.1:${FRONTEND_PORT:-8082}:80"
restart: unless-stopped
depends_on:
backend:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1/health | grep -q ok"]
interval: 30s
timeout: 5s
retries: 5
networks:
remnawave-network:
volumes:
remnawave-minishop-db-data:
name: remnawave-minishop-db-data
remnawave-minishop-redis-data:
name: remnawave-minishop-redis-data
shop-data:
name: remnawave-minishop-shop-data
+82
View File
@@ -0,0 +1,82 @@
FROM python:3.12-slim AS python-base
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app/backend
WORKDIR /app
RUN useradd -u 10001 -m appuser
COPY backend/requirements.txt backend/requirements.txt
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --no-cache-dir -r backend/requirements.txt
COPY backend ./backend
COPY locales ./locales
COPY data ./data
RUN mkdir -p /app/logs /app/data && chown -R appuser:appuser /app/logs /app/data
USER appuser
FROM python-base AS backend
LABEL org.opencontainers.image.source="https://github.com/3252a8/remnawave-minishop" \
org.opencontainers.image.title="remnawave-minishop-backend" \
org.opencontainers.image.description="Remnawave Minishop backend (Telegram bot API, web app, webhooks)." \
org.opencontainers.image.licenses="MIT"
EXPOSE 8080 8081
CMD ["python", "backend/main_backend.py"]
FROM python-base AS worker
LABEL org.opencontainers.image.source="https://github.com/3252a8/remnawave-minishop" \
org.opencontainers.image.title="remnawave-minishop-worker" \
org.opencontainers.image.description="Remnawave Minishop background worker (scheduled jobs, async tasks)." \
org.opencontainers.image.licenses="MIT"
CMD ["python", "backend/main_worker.py"]
FROM node:22-slim AS frontend-builder
WORKDIR /app/frontend
COPY frontend/package.json frontend/package-lock.json* ./
RUN --mount=type=cache,target=/root/.npm \
if [ -f package-lock.json ]; then npm ci; else npm install; fi
COPY frontend ./
COPY backend/bot/app/web/templates ../backend/bot/app/web/templates
RUN npm run build:webapp
FROM nginx:1.27-alpine AS frontend
LABEL org.opencontainers.image.source="https://github.com/3252a8/remnawave-minishop" \
org.opencontainers.image.title="remnawave-minishop-frontend" \
org.opencontainers.image.description="Remnawave Minishop frontend (nginx serving the subscription Mini App)." \
org.opencontainers.image.licenses="MIT"
COPY deploy/docker/frontend/nginx.conf /etc/nginx/conf.d/default.conf
COPY deploy/docker/frontend/00-startup-banner.sh /docker-entrypoint.d/00-startup-banner.sh
COPY backend/bot/app/web/templates/subscription_webapp.html /usr/share/nginx/html/index.html
COPY --from=frontend-builder /app/backend/bot/app/web/templates/subscription_webapp.css /usr/share/nginx/html/subscription_webapp.css
COPY --from=frontend-builder /app/backend/bot/app/web/templates/subscription_webapp.js /usr/share/nginx/html/subscription_webapp.js
COPY --from=frontend-builder /app/backend/bot/app/web/templates/subscription_webapp.min.*.js /usr/share/nginx/html/
RUN sed -i \
-e '/WEBAPP_I18N_SCRIPT/d' \
-e '/WEBAPP_CONFIG_SCRIPT/d' \
-e '/WEBAPP_JS_SCRIPT/c\ <script src="/subscription_webapp.js" type="module"></script>' \
-e '/WEBAPP_DEV_MOCK_START/d' \
-e '/WEBAPP_DEV_MOCK_END/d' \
-e '/subscription_webapp.js" defer/d' \
/usr/share/nginx/html/index.html \
&& chmod +x /docker-entrypoint.d/00-startup-banner.sh
EXPOSE 80
+11
View File
@@ -0,0 +1,11 @@
{$PUBLIC_HOST:localhost} {
encode zstd gzip
@webhooks path /tg/webhook /webhook/*
reverse_proxy @webhooks backend:8080
@backend_health path /health /healthz
reverse_proxy @backend_health backend:8080
reverse_proxy frontend:80
}
@@ -0,0 +1,23 @@
#!/bin/sh
PUBLISHED="${FRONTEND_PUBLIC:-127.0.0.1:${FRONTEND_PORT:-8082}->80}"
cat <<EOF
~ ~ ~ r e m n a w a v e ~ ~ ~
███╗ ███╗██╗███╗ ██╗██╗███████╗██╗ ██╗ ██████╗ ██████╗
████╗ ████║██║████╗ ██║██║██╔════╝██║ ██║██╔═══██╗██╔══██╗
██╔████╔██║██║██╔██╗ ██║██║███████╗███████║██║ ██║██████╔╝
██║╚██╔╝██║██║██║╚██╗██║██║╚════██║██╔══██║██║ ██║██╔═══╝
██║ ╚═╝ ██║██║██║ ╚████║██║███████║██║ ██║╚██████╔╝██║
╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚═╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝
container :: FRONTEND
image tag :: ${IMAGE_TAG:-local}
listen :: :80
published :: ${PUBLISHED}
upstream :: backend:8081
healthcheck :: /health
https://github.com/3252a8/remnawave-minishop
EOF
+57
View File
@@ -0,0 +1,57 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
location = /health {
access_log off;
return 200 "ok\n";
}
location /api/ {
proxy_pass http://backend:8081;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /auth/ {
proxy_pass http://backend:8081;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location = /webapp-logo {
proxy_pass http://backend:8081;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location ~ ^/(webapp-logo|webapp-uploaded-logo|webapp-favicon|webapp-emoji|webapp-theme-css|webapp-theme-assets)/ {
proxy_pass http://backend:8081;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg|webp)$ {
expires 30d;
add_header Cache-Control "public";
try_files $uri =404;
}
location / {
try_files $uri /index.html;
}
}