diff --git a/Jenkinsfile b/Jenkinsfile index 7a89656..7222992 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,24 +1,42 @@ pipeline { environment { REGISTRY_URL = "https://proxy.docker.dataekb.ru/local_cache" - IMAGE_NAME = "bot_open_sesam" - IMAGE_TAG = "latest" + BOT_IMAGE_NAME = "bot_open_sesam" + TUNNEL_IMAGE_NAME = "tunnel_open_sesam" + BOT_IMAGE_TAG = "latest" + TUNNEL_IMAGE_TAG = "latest" } agent { label 'agent_smith'} stages { - stage ('push main') { + stage ('build bot image and push') { steps { script { docker.withRegistry("${REGISTRY_URL}", 'jenkins_harbor') { - def customImage = docker.build("proxy.docker.dataekb.ru/local_cache/${IMAGE_NAME}:latest") - customImage.push() + def BotImage = docker.build( + "${REGISTRY_URL}/${BOT_IMAGE_NAME}:${BOT_IMAGE_TAG}" + "-f ./tunnel/Dockerfile.tunnel ." + ) + BotImage.push() } } } } + stage ('build tunnel image and push') { + steps { + script { + docker.withRegistry("${REGISTRY_URL}", 'jenkins_harbor') { + def TunnelImage = docker.build( + "${REGISTRY}/${TUNNEL_IMAGE_NAME}:${TUNNEL_IMAGE_TAG}", + "-f ./tunnel/Dockerfile.tunnel ." + ) + TunnelImage.push() + } + } + } + } stage ('clear after build and push') { steps { @@ -38,8 +56,13 @@ pipeline { } } } - - + post { + success { + echo "Оба образа собраны и задеплоены успешно" + } + failure { + echo "Ошибка сборки!" + } } } diff --git a/docker-compose.yml b/docker-compose.yml index 6132ac7..d24ce27 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,11 +10,39 @@ services: restart: always networks: - bot_open_sesam_network + depends_on: + tunnel_open_sesam: + condition: service_healthy logging: driver: "json-file" options: max-size: "10m" max-file: "3" + tunnel_open_sesam: + image: proxy.docker.dataekb.ru/local_cache/tunnel_open_sesam:latest + container_name: tunnel_open_sesam + env_file: + - ./.env +# environment: +# - SSH_HOST=91.194.84.91 +# - SSH_PORT=22 +# - SSH_USER=root + volumes: + # SSH ключ + - ~/.ssh/id_rsa:/root/.ssh/id_rsa:ro + networks: + - bot_open_sesam_network + restart: always + logging: + driver: "json-file" + options: + max-size: "10m" + max-file: "3" + healthcheck: + test: ["CMD", "nc", "-z", "localhost", "1080"] + interval: 10s + timeout: 5s + retries: 5 networks: bot_open_sesam_network: driver: bridge diff --git a/main.py b/main.py index 6f196e0..11b1f40 100755 --- a/main.py +++ b/main.py @@ -14,12 +14,11 @@ from config import config # BOT_TOKEN = config["BOT_TOKEN"] BOT_TOKEN=os.environ.get('BOT_TOKEN') +PROXY_URL = os.environ.get('PROXY_URL') dp = Dispatcher() register_all_handlers(dp) -PROXY_URL = os.environ.get('PROXY_URL') - session = AiohttpSession(proxy=PROXY_URL) async def main() -> None: diff --git a/tunnel/Dockerfile.tunnel b/tunnel/Dockerfile.tunnel new file mode 100644 index 0000000..4744029 --- /dev/null +++ b/tunnel/Dockerfile.tunnel @@ -0,0 +1,15 @@ +# tunnel/Dockerfile +FROM alpine:3.19 + +RUN apk add --no-cache \ + autossh \ + openssh-client + +# Директория для SSH ключей +RUN mkdir -p /root/.ssh && \ + chmod 700 /root/.ssh + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/tunnel/entrypoint.sh b/tunnel/entrypoint.sh new file mode 100644 index 0000000..ed80a67 --- /dev/null +++ b/tunnel/entrypoint.sh @@ -0,0 +1,23 @@ +# tunnel/entrypoint.sh +#!/bin/sh + +# Права на ключ +chmod 600 /root/.ssh/id_rsa + +# Добавляем сервер в known_hosts +ssh-keyscan -p ${SSH_PORT:-22} ${SSH_HOST} >> /root/.ssh/known_hosts 2>/dev/null + +echo "Запуск AutoSSH туннеля → ${SSH_USER}@${SSH_HOST}:${SSH_PORT:-22}" + +exec autossh \ + -M 0 \ + -N \ + -D 0.0.0.0:1080 \ + -o "ServerAliveInterval=30" \ + -o "ServerAliveCountMax=3" \ + -o "ExitOnForwardFailure=yes" \ + -o "StrictHostKeyChecking=no" \ + -o "ConnectTimeout=10" \ + -p ${SSH_PORT:-22} \ + -i /root/.ssh/id_rsa \ + ${SSH_USER}@${SSH_HOST} \ No newline at end of file