Переделан алгоритм инициализации

This commit is contained in:
2025-08-25 14:02:15 +07:00
parent e835b0c02d
commit 9a4d28d934
2 changed files with 9 additions and 47 deletions

View File

@@ -1,19 +1,3 @@
# FROM debian:stable-slim
# # Установим утилиты для скачивания и распаковки
# RUN apt-get update && apt-get install -y wget tar ca-certificates \
# && rm -rf /var/lib/apt/lists/*
# WORKDIR /opt/x-ui
# # Скачиваем и распаковываем конкретный релиз
# RUN wget https://github.com/MHSanaei/3x-ui/releases/download/v2.6.6/x-ui-linux-amd64.tar.gz \
# && tar -xvf x-ui-linux-amd64.tar.gz --strip-components=1 \
# && rm x-ui-linux-amd64.tar.gz \
# && chmod +x x-ui
# CMD ["./x-ui"]
FROM alpine:3.18 FROM alpine:3.18
RUN apk add --no-cache bash curl tar ca-certificates RUN apk add --no-cache bash curl tar ca-certificates

40
init.py
View File

@@ -1,46 +1,24 @@
# файл для инициализации docker-compose.yml
import os import os
import random import random
import sys import sys
with open("docker-compose.yml", "w+") as file: with open("docker-compose.yml", "w+") as file:
name = os.getlogin() name = os.getlogin()
if "--ui_p" in sys.argv:
ui_port = sys.argv[sys.argv.index("--ui_p") + 1]
else:
ui_port = input("Укажите порт для ui: ")
if "--client_p" in sys.argv:
inp_ports = sys.argv[sys.argv.index("--client_p") + 1]
else:
inp_ports = input("Укажите порты для проксирования через пробел в формате 'host_port:docker_port' или просто 'host_port'\n: ")
f_list_ports = []
list_ports: set[int] = {int(ui_port)}
for port in inp_ports.split(" "):
if ":" in port:
if list_ports & {int(port.split(":")[1])}:
raise ValueError(f"Некоторые порты в докере повторяются ({int(port.split(":")[1])})")
f_list_ports.append(f" - {port}")
list_ports.add(int(port.split(":")[1]))
else:
new_port = int(ui_port)
while new_port in list_ports:
new_port = random.randint(10_000, 65_536)
f_list_ports.append(f" - {port}:{new_port}")
list_ports.add(new_port)
print("Готово! Теперь вы сможете использовать клиентов на следующих портах:", ", ".join(str(i) for i in list_ports ^ {int(ui_port)}))
file.write(''' file.write('''
services: services:
{name}-3x-ui: {name}-3x-ui:
build: . build: .
container_name: {name}-3x-ui container_name: {name}-3x-ui
ports:
- "{ui_port}:2053" # port for ui
# client ports
{clients_ports}
volumes: volumes:
- ./data:/opt/x-ui/db - ./data:/opt/x-ui/db
networks:
- nginx_network_external
restart: always restart: always
'''.format(name=name, ui_port=ui_port, clients_ports='\n'.join(f_list_ports)))
networks:
nginx_network_external:
external: true
'''.format(name=name))