From 0d0761cb310c9cf65eaf185e2bf7a7d4b7dc0ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Thu, 5 Feb 2026 07:36:25 +0300 Subject: [PATCH] docker support --- APP_CORE/Dockerfile.api | 16 +++++++++ APP_CORE/Dockerfile.gatherer | 13 +++++++ APP_PROFILER/Dockerfile | 21 +++++++++++ APP_PROFILER/entrypoint.sh | 20 +++++++++++ APP_PROFILER/requirements.txt | 6 ++++ APP_UI/Dockerfile | 14 ++++++++ APP_UI/nginx.conf | 25 +++++++++++++ docker-compose.yml | 67 +++++++++++++++++++++++++++++++++++ 8 files changed, 182 insertions(+) create mode 100644 APP_CORE/Dockerfile.api create mode 100644 APP_CORE/Dockerfile.gatherer create mode 100644 APP_PROFILER/Dockerfile create mode 100644 APP_PROFILER/entrypoint.sh create mode 100644 APP_PROFILER/requirements.txt create mode 100644 APP_UI/Dockerfile create mode 100644 APP_UI/nginx.conf create mode 100644 docker-compose.yml diff --git a/APP_CORE/Dockerfile.api b/APP_CORE/Dockerfile.api new file mode 100644 index 0000000..e7bfe51 --- /dev/null +++ b/APP_CORE/Dockerfile.api @@ -0,0 +1,16 @@ +FROM python:3.12-alpine + +WORKDIR /app + +# Install dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy source code +COPY . . + +# Expose the port +EXPOSE 5001 + +# Run the API +CMD ["python", "openvpn_api_v3.py"] diff --git a/APP_CORE/Dockerfile.gatherer b/APP_CORE/Dockerfile.gatherer new file mode 100644 index 0000000..946b310 --- /dev/null +++ b/APP_CORE/Dockerfile.gatherer @@ -0,0 +1,13 @@ +FROM python:3.12-alpine + +WORKDIR /app + +# Install dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy source code +COPY . . + +# Run the gatherer +CMD ["python", "openvpn_gatherer_v3.py"] diff --git a/APP_PROFILER/Dockerfile b/APP_PROFILER/Dockerfile new file mode 100644 index 0000000..bcef513 --- /dev/null +++ b/APP_PROFILER/Dockerfile @@ -0,0 +1,21 @@ +FROM python:3.12-alpine + +# Install OpenVPN, OpenRC and other system deps +RUN apk add --no-cache openvpn openrc iproute2 bash + +WORKDIR /app + +# Install Python dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy source code and entrypoint +COPY . . +RUN chmod +x entrypoint.sh + +# Expose API port +EXPOSE 8000 +# Expose OpenVPN port (default 1194 UDP) +EXPOSE 1194/udp + +ENTRYPOINT ["./entrypoint.sh"] diff --git a/APP_PROFILER/entrypoint.sh b/APP_PROFILER/entrypoint.sh new file mode 100644 index 0000000..efaf70e --- /dev/null +++ b/APP_PROFILER/entrypoint.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# EnsureTUN device exists +if [ ! -c /dev/net/tun ]; then + mkdir -p /dev/net + mknod /dev/net/tun c 10 200 + chmod 600 /dev/net/tun +fi + +# Enable IP forwarding +sysctl -w net.ipv4.ip_forward=1 + +# Start OpenRC (needed for rc-service if we use it, but better to start openvpn directly or via rc) +# Since we are in Alpine, we can try to start the service if configured, +# but Container 4 main.py might expect rc-service to work. +openrc default + +# Start the APP_PROFILER API +# We use 0.0.0.0 to be reachable from other containers +python main.py diff --git a/APP_PROFILER/requirements.txt b/APP_PROFILER/requirements.txt new file mode 100644 index 0000000..bb00e47 --- /dev/null +++ b/APP_PROFILER/requirements.txt @@ -0,0 +1,6 @@ +fastapi +uvicorn +sqlalchemy +psutil +python-multipart +jinja2 diff --git a/APP_UI/Dockerfile b/APP_UI/Dockerfile new file mode 100644 index 0000000..91cf673 --- /dev/null +++ b/APP_UI/Dockerfile @@ -0,0 +1,14 @@ +# Stage 1: Build +FROM node:20-alpine AS build-stage +WORKDIR /app +COPY package*.json ./ +RUN npm install +COPY . . +RUN npm run build + +# Stage 2: Serve +FROM nginx:alpine +COPY --from=build-stage /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/APP_UI/nginx.conf b/APP_UI/nginx.conf new file mode 100644 index 0000000..2f17b99 --- /dev/null +++ b/APP_UI/nginx.conf @@ -0,0 +1,25 @@ +server { + listen 80; + server_name localhost; + + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } + + # Proxy API requests if needed or let the frontend handle URLs + # location /api/v1/ { + # proxy_pass http://app-api:5001; + # } + + # location /api/ { + # proxy_pass http://app-profiler:8000; + # } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5959aca --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,67 @@ +version: '3.8' + +services: + app-ui: + build: ./APP_UI + container_name: ovp-ui + ports: + - "80:80" + depends_on: + - app-api + - app-profiler + networks: + - ovp-net + + app-gatherer: + build: + context: ./APP_CORE + dockerfile: Dockerfile.gatherer + container_name: ovp-gatherer + volumes: + - ovp_logs:/var/log/openvpn + - db_data:/app/db # Assuming APP_CORE looks for DB in /app/db + depends_on: + - app-profiler + networks: + - ovp-net + + app-api: + build: + context: ./APP_CORE + dockerfile: Dockerfile.api + container_name: ovp-api + ports: + - "5001:5001" + volumes: + - db_data:/app/db + networks: + - ovp-net + environment: + - JWT_SECRET=${JWT_SECRET:-supersecret} + + app-profiler: + build: ./APP_PROFILER + container_name: ovp-profiler + cap_add: + - NET_ADMIN + devices: + - "/dev/net/tun:/dev/net/tun" + ports: + - "8000:8000" + - "1194:1194/udp" + volumes: + - ovp_logs:/var/log/openvpn + - ovp_config:/etc/openvpn + networks: + - ovp-net + environment: + - JWT_SECRET=${JWT_SECRET:-supersecret} + +networks: + ovp-net: + driver: bridge + +volumes: + ovp_logs: + ovp_config: + db_data: