From e0c431cbae7aeaed260ab99ce0109304096bd12a Mon Sep 17 00:00:00 2001 From: sysadmin Date: Fri, 3 Oct 2025 16:00:05 +0100 Subject: [PATCH] "CI-CD-Add-TeleBot-build-and-deployment" --- .gitlab-ci.yml | 56 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5fd738a..4dc15f2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,7 @@ stages: variables: DOCKER_HOST: unix:///var/run/docker.sock -build: +build:littleshop: stage: build image: docker:24 script: @@ -16,7 +16,25 @@ build: echo "Tagging as version $CI_COMMIT_TAG" docker tag localhost:5000/littleshop:latest localhost:5000/littleshop:$CI_COMMIT_TAG fi - - echo "Build complete" + - echo "LittleShop build complete" + rules: + - if: '$CI_COMMIT_BRANCH == "main"' + - if: '$CI_COMMIT_TAG' + tags: + - docker + +build:telebot: + stage: build + image: docker:24 + script: + - echo "Building TeleBot Docker image" + - docker build -t localhost:5000/telebot:latest -f Dockerfile.telebot . + - | + if [ -n "$CI_COMMIT_TAG" ]; then + echo "Tagging as version $CI_COMMIT_TAG" + docker tag localhost:5000/telebot:latest localhost:5000/telebot:$CI_COMMIT_TAG + fi + - echo "TeleBot build complete" rules: - if: '$CI_COMMIT_BRANCH == "main"' - if: '$CI_COMMIT_TAG' @@ -36,11 +54,13 @@ deploy:vps: script: - export VERSION="${CI_COMMIT_TAG:-$CI_COMMIT_SHORT_SHA}" - echo "Deploying version $VERSION to VPS" - - echo "Building image from source..." + - echo "Building images from source..." - docker build -t littleshop:$VERSION . + - docker build -t telebot:$VERSION -f Dockerfile.telebot . - - echo "Copying image to VPS via SSH..." + - echo "Copying images to VPS via SSH..." - docker save littleshop:$VERSION | ssh -i /tmp/deploy_key -p "$VPS_PORT" "$VPS_USER@$VPS_HOST" "docker load" + - docker save telebot:$VERSION | ssh -i /tmp/deploy_key -p "$VPS_PORT" "$VPS_USER@$VPS_HOST" "docker load" - echo "Deploying on VPS..." - | @@ -48,14 +68,18 @@ deploy:vps: set -e export VERSION="$VERSION" - # Tag the image + # Tag the images docker tag littleshop:\$VERSION localhost:5000/littleshop:\$VERSION docker tag littleshop:\$VERSION localhost:5000/littleshop:latest + docker tag telebot:\$VERSION localhost:5000/telebot:\$VERSION + docker tag telebot:\$VERSION localhost:5000/telebot:latest # Push to local registry - echo "Pushing to local Docker registry..." + echo "Pushing images to local Docker registry..." docker push localhost:5000/littleshop:\$VERSION docker push localhost:5000/littleshop:latest + docker push localhost:5000/telebot:\$VERSION + docker push localhost:5000/telebot:latest # Navigate to deployment directory cd /opt/littleshop @@ -65,6 +89,11 @@ deploy:vps: docker stop \$(docker ps -q --filter "name=littleshop") 2>/dev/null || true docker rm \$(docker ps -aq --filter "name=littleshop") 2>/dev/null || true + # Stop TeleBot container + echo "Stopping TeleBot container..." + docker stop telebot-service 2>/dev/null || true + docker rm telebot-service 2>/dev/null || true + # Stop services with compose (removes networks) echo "Stopping compose services..." docker-compose down --remove-orphans || true @@ -73,10 +102,20 @@ deploy:vps: echo "Cleaning up Docker networks..." docker network prune -f || true - # Start services with new image - echo "Starting services with new image..." + # Start services with new images + echo "Starting services with new images..." docker-compose up -d + # Start TeleBot with new image + echo "Starting TeleBot with new image..." + docker run -d \ + --name telebot-service \ + --restart unless-stopped \ + --network silverpay_silverpay-network \ + --network littleshop-network \ + -e ASPNETCORE_URLS=http://+:5010 \ + localhost:5000/telebot:latest + # Wait for startup echo "Waiting for services to start..." sleep 30 @@ -94,6 +133,7 @@ deploy:vps: echo "❌ Health check failed after deployment" docker logs littleshop-admin --tail 50 + docker logs telebot-service --tail 30 exit 1 EOF environment: