Compare commits
No commits in common. "main" and "test" have entirely different histories.
|
|
@ -1,117 +1,23 @@
|
||||||
pipeline {
|
pipeline {
|
||||||
environment {
|
agent { label 'agent_smith' }
|
||||||
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'}
|
|
||||||
|
|
||||||
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 {
|
||||||
script {
|
|
||||||
docker.withRegistry("${REGISTRY_URL}", 'jenkins_harbor') {
|
|
||||||
def BotImage = docker.build(
|
|
||||||
"${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 ('clear after build and push') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
sh "docker image prune --filter label=stage=builder"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage("Deploy") {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
sh '''
|
sh '''
|
||||||
export BOT_IMAGE_TAG=${IMAGE_TAG}
|
docker stop open_sesam || true
|
||||||
export TUNNEL_IMAGE_TAG=${IMAGE_TAG}
|
docker rm open_sesam || true
|
||||||
|
docker-compose down || true
|
||||||
# Pull new images explicitly
|
'''
|
||||||
docker-compose pull bot_open_sesam tunnel_open_sesam
|
}
|
||||||
|
}
|
||||||
# Deploy with specific project name
|
|
||||||
docker-compose up -d --remove-orphans
|
|
||||||
|
|
||||||
|
stage('Build and Run Container') {
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
docker-compose up --build -d
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
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,52 +1,15 @@
|
||||||
version: '3'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
bot_open_sesam:
|
open_sesam:
|
||||||
container_name: bot_open_sesam
|
container_name: open_sesam
|
||||||
image: proxy.docker.dataekb.ru/local_cache/bot_open_sesam:${BOT_IMAGE_TAG:-latest}
|
build: .
|
||||||
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:
|
||||||
# SSH ключ
|
- ./.env:/bot/open_sesam/.env
|
||||||
- .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,32 +1,22 @@
|
||||||
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(
|
bot = Bot(token=BOT_TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML))
|
||||||
token=BOT_TOKEN
|
|
||||||
, session=session
|
|
||||||
, default=DefaultBotProperties(parse_mode=ParseMode.HTML)
|
|
||||||
)
|
|
||||||
await dp.start_polling(bot)
|
await dp.start_polling(bot)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,4 +18,3 @@ 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
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
# 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"]
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
#!/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