Compare commits
31 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
78c23227e4 | |
|
|
7b6d298d68 | |
|
|
1b9649fbc0 | |
|
|
193390ecb8 | |
|
|
55ebed483f | |
|
|
00846331f3 | |
|
|
0adc48209d | |
|
|
d7403bb266 | |
|
|
2b43532a8f | |
|
|
54afe573c1 | |
|
|
b240bc1bad | |
|
|
be996f942b | |
|
|
dda0e8ebb7 | |
|
|
dd78a4a55b | |
|
|
f61e8e1588 | |
|
|
0168036fab | |
|
|
24fdc1014c | |
|
|
5f59c4df92 | |
|
|
63ab836f1a | |
|
|
d57a88321e | |
|
|
5b0eafe695 | |
|
|
35dca573c9 | |
|
|
dc021f6802 | |
|
|
8f8b5d18d1 | |
|
|
7ad9b91a0a | |
|
|
469ab42324 | |
|
|
3547f307b1 | |
|
|
8edd79be72 | |
|
|
e4f596dd82 | |
|
|
b2363215b8 | |
|
|
0c060c79cb |
|
|
@ -1,23 +1,117 @@
|
||||||
pipeline {
|
pipeline {
|
||||||
|
environment {
|
||||||
|
REGISTRY_URL = "https://proxy.docker.dataekb.ru/local_cache"
|
||||||
|
REGISTRY = "proxy.docker.dataekb.ru/local_cache"
|
||||||
|
BOT_IMAGE_NAME = "bot_open_sesam"
|
||||||
|
TUNNEL_IMAGE_NAME = "tunnel_open_sesam"
|
||||||
|
BOT_IMAGE_TAG = "latest"
|
||||||
|
TUNNEL_IMAGE_TAG = "latest"
|
||||||
|
IMAGE_TAG = "${env.BUILD_NUMBER}"
|
||||||
|
}
|
||||||
|
|
||||||
agent { label 'agent_smith'}
|
agent { label 'agent_smith'}
|
||||||
|
|
||||||
|
options {
|
||||||
|
buildDiscarder(logRotator(numToKeepStr: '10'))
|
||||||
|
disableConcurrentBuilds() // Prevent cleanup conflicts
|
||||||
|
timeout(time: 30, unit: 'MINUTES')
|
||||||
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Stop and Remove Existing Container') {
|
|
||||||
|
stage ('build bot image and push') {
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
script {
|
||||||
docker stop open_sesam || true
|
docker.withRegistry("${REGISTRY_URL}", 'jenkins_harbor') {
|
||||||
docker rm open_sesam || true
|
def BotImage = docker.build(
|
||||||
docker-compose down || true
|
"${REGISTRY}/${BOT_IMAGE_NAME}:${env.BUILD_NUMBER}",
|
||||||
'''
|
"--label build_number=${IMAGE_TAG} " +
|
||||||
|
"--label git_commit=${env.GIT_COMMIT} " +
|
||||||
|
"."
|
||||||
|
)
|
||||||
|
BotImage.push()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage ('build tunnel image and push') {
|
||||||
|
steps {
|
||||||
|
dir('tunnel'){
|
||||||
|
script {
|
||||||
|
docker.withRegistry("${REGISTRY_URL}", 'jenkins_harbor') {
|
||||||
|
def TunnelImage = docker.build(
|
||||||
|
"${REGISTRY}/${TUNNEL_IMAGE_NAME}:${env.BUILD_NUMBER}",
|
||||||
|
"--label build_number=${IMAGE_TAG} " +
|
||||||
|
"--label git_commit=${env.GIT_COMMIT} " +
|
||||||
|
"."
|
||||||
|
)
|
||||||
|
TunnelImage.push()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build and Run Container') {
|
stage ('clear after build and push') {
|
||||||
steps {
|
steps {
|
||||||
|
script {
|
||||||
|
sh "docker image prune --filter label=stage=builder"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage("Deploy") {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
sh '''
|
sh '''
|
||||||
docker-compose up --build -d
|
export BOT_IMAGE_TAG=${IMAGE_TAG}
|
||||||
|
export TUNNEL_IMAGE_TAG=${IMAGE_TAG}
|
||||||
|
|
||||||
|
# Pull new images explicitly
|
||||||
|
docker-compose pull bot_open_sesam tunnel_open_sesam
|
||||||
|
|
||||||
|
# Deploy with specific project name
|
||||||
|
docker-compose up -d --remove-orphans
|
||||||
|
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
post {
|
||||||
|
success {
|
||||||
|
echo "Оба образа собраны и задеплоены успешно"
|
||||||
|
}
|
||||||
|
failure {
|
||||||
|
echo "Ошибка сборки!"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Old_version
|
||||||
|
// pipeline {
|
||||||
|
// agent { label 'agent_smith' }
|
||||||
|
//
|
||||||
|
// stages {
|
||||||
|
// stage('Stop and Remove Existing Container') {
|
||||||
|
// steps {
|
||||||
|
// sh '''
|
||||||
|
// docker stop open_sesam || true
|
||||||
|
// docker rm open_sesam || true
|
||||||
|
// docker-compose down || true
|
||||||
|
// '''
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// stage('Build and Run Container') {
|
||||||
|
// steps {
|
||||||
|
// sh '''
|
||||||
|
// docker-compose up --build -d
|
||||||
|
// '''
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,52 @@
|
||||||
version: '3'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
open_sesam:
|
bot_open_sesam:
|
||||||
container_name: open_sesam
|
container_name: bot_open_sesam
|
||||||
build: .
|
image: proxy.docker.dataekb.ru/local_cache/bot_open_sesam:${BOT_IMAGE_TAG:-latest}
|
||||||
stdin_open: true
|
stdin_open: true
|
||||||
tty: true
|
tty: true
|
||||||
|
env_file:
|
||||||
|
- ./.env
|
||||||
|
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:${BOT_IMAGE_TAG:-latest}
|
||||||
|
container_name: tunnel_open_sesam
|
||||||
|
env_file:
|
||||||
|
- ./.env
|
||||||
|
# environment:
|
||||||
|
# - SSH_HOST=91.194.84.91
|
||||||
|
# - SSH_PORT=22
|
||||||
|
# - SSH_USER=root
|
||||||
volumes:
|
volumes:
|
||||||
- ./.env:/bot/open_sesam/.env
|
# SSH ключ
|
||||||
|
- .ssh/id_rsa:/root/.ssh/id_rsa:ro
|
||||||
|
networks:
|
||||||
|
- bot_open_sesam_network
|
||||||
restart: always
|
restart: always
|
||||||
logging:
|
logging:
|
||||||
driver: "json-file"
|
driver: "json-file"
|
||||||
options:
|
options:
|
||||||
max-size: "10m"
|
max-size: "10m"
|
||||||
max-file: "3"
|
max-file: "3"
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "nc", "-z", "localhost", "1080"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
networks:
|
||||||
|
bot_open_sesam_network:
|
||||||
|
driver: bridge
|
||||||
|
ipam:
|
||||||
|
config:
|
||||||
|
- subnet: 172.30.10.0/29
|
||||||
|
gateway: 172.30.10.1
|
||||||
14
main.py
14
main.py
|
|
@ -1,22 +1,32 @@
|
||||||
|
import os
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
from aiogram import Bot, Dispatcher
|
from aiogram import Bot, Dispatcher
|
||||||
from aiogram.enums import ParseMode
|
from aiogram.enums import ParseMode
|
||||||
from aiogram.client.default import DefaultBotProperties
|
from aiogram.client.default import DefaultBotProperties
|
||||||
|
from aiogram.client.session.aiohttp import AiohttpSession
|
||||||
|
|
||||||
from handlers import register_all_handlers
|
from handlers import register_all_handlers
|
||||||
from config import config
|
from config import config
|
||||||
|
|
||||||
BOT_TOKEN = config["BOT_TOKEN"]
|
# BOT_TOKEN = config["BOT_TOKEN"]
|
||||||
|
BOT_TOKEN=os.environ.get('BOT_TOKEN')
|
||||||
|
PROXY_URL = os.environ.get('PROXY_URL')
|
||||||
|
|
||||||
dp = Dispatcher()
|
dp = Dispatcher()
|
||||||
register_all_handlers(dp)
|
register_all_handlers(dp)
|
||||||
|
|
||||||
|
session = AiohttpSession(proxy=PROXY_URL)
|
||||||
|
|
||||||
async def main() -> None:
|
async def main() -> None:
|
||||||
bot = Bot(token=BOT_TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML))
|
bot = Bot(
|
||||||
|
token=BOT_TOKEN
|
||||||
|
, session=session
|
||||||
|
, default=DefaultBotProperties(parse_mode=ParseMode.HTML)
|
||||||
|
)
|
||||||
await dp.start_polling(bot)
|
await dp.start_polling(bot)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,3 +18,4 @@ typing-inspection==0.4.0
|
||||||
typing_extensions==4.13.2
|
typing_extensions==4.13.2
|
||||||
urllib3==2.4.0
|
urllib3==2.4.0
|
||||||
yarl==1.20.0
|
yarl==1.20.0
|
||||||
|
aiohttp-socks
|
||||||
|
|
|
||||||
|
|
@ -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"]
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
ssh-keyscan -p ${SSH_PORT:-22} ${SSH_HOST} >> /root/.ssh/known_hosts 2>/dev/null
|
||||||
|
|
||||||
|
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}
|
||||||
Loading…
Reference in New Issue