fix: Fix deploy-alexhost.sh verify function and add GitLab CI/CD
- Fix ssh_exec → ssh_sudo in verify_deployment function - Add .gitlab-ci.yml for GitLab CI/CD deployment support - Manual deployment jobs: deploy-alexhost, deploy-teleshop-only, deploy-telebot-only 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
86f19ba044
commit
26e9004242
193
.gitlab-ci.yml
Normal file
193
.gitlab-ci.yml
Normal file
@ -0,0 +1,193 @@
|
||||
# GitLab CI/CD Pipeline for AlexHost Deployment
|
||||
# Server: 193.233.245.41 (teleshop.silentmary.mywire.org)
|
||||
|
||||
stages:
|
||||
- build
|
||||
- deploy
|
||||
- verify
|
||||
|
||||
variables:
|
||||
ALEXHOST_IP: "193.233.245.41"
|
||||
ALEXHOST_USER: "sysadmin"
|
||||
REGISTRY: "localhost:5000"
|
||||
TELESHOP_IMAGE: "littleshop"
|
||||
TELEBOT_IMAGE: "telebot"
|
||||
|
||||
# Manual deployment to AlexHost Production
|
||||
deploy-alexhost:
|
||||
stage: deploy
|
||||
image: docker:24.0
|
||||
services:
|
||||
- docker:24.0-dind
|
||||
rules:
|
||||
- when: manual
|
||||
variables:
|
||||
DOCKER_TLS_CERTDIR: "/certs"
|
||||
before_script:
|
||||
- apk add --no-cache openssh-client curl tar gzip
|
||||
- mkdir -p ~/.ssh
|
||||
- echo "$ALEXHOST_SSH_KEY" > ~/.ssh/id_rsa
|
||||
- chmod 600 ~/.ssh/id_rsa
|
||||
- ssh-keyscan -H $ALEXHOST_IP >> ~/.ssh/known_hosts 2>/dev/null || true
|
||||
script:
|
||||
- echo "=== Building and Deploying to AlexHost ==="
|
||||
|
||||
# Build TeleShop image
|
||||
- echo "Building TeleShop image..."
|
||||
- docker build -t ${TELESHOP_IMAGE}:${CI_COMMIT_SHA} -t ${TELESHOP_IMAGE}:latest -f Dockerfile .
|
||||
- docker save ${TELESHOP_IMAGE}:latest | gzip > teleshop-image.tar.gz
|
||||
|
||||
# Build TeleBot image
|
||||
- echo "Building TeleBot image..."
|
||||
- docker build -t ${TELEBOT_IMAGE}:${CI_COMMIT_SHA} -t ${TELEBOT_IMAGE}:latest -f Dockerfile.telebot .
|
||||
- docker save ${TELEBOT_IMAGE}:latest | gzip > telebot-image.tar.gz
|
||||
|
||||
# Transfer images to AlexHost
|
||||
- echo "Transferring images to AlexHost..."
|
||||
- scp -o StrictHostKeyChecking=no teleshop-image.tar.gz ${ALEXHOST_USER}@${ALEXHOST_IP}:/tmp/
|
||||
- scp -o StrictHostKeyChecking=no telebot-image.tar.gz ${ALEXHOST_USER}@${ALEXHOST_IP}:/tmp/
|
||||
- scp -o StrictHostKeyChecking=no docker-compose.alexhost.yml ${ALEXHOST_USER}@${ALEXHOST_IP}:/tmp/
|
||||
|
||||
# Deploy on AlexHost
|
||||
- |
|
||||
ssh -o StrictHostKeyChecking=no ${ALEXHOST_USER}@${ALEXHOST_IP} << 'DEPLOY_EOF'
|
||||
set -e
|
||||
echo "=== Loading Docker images ==="
|
||||
gunzip -c /tmp/teleshop-image.tar.gz | sudo docker load
|
||||
gunzip -c /tmp/telebot-image.tar.gz | sudo docker load
|
||||
|
||||
echo "=== Pushing to local registry ==="
|
||||
sudo docker tag littleshop:latest localhost:5000/littleshop:latest
|
||||
sudo docker push localhost:5000/littleshop:latest
|
||||
sudo docker tag telebot:latest localhost:5000/telebot:latest
|
||||
sudo docker push localhost:5000/telebot:latest
|
||||
|
||||
echo "=== Stopping existing containers ==="
|
||||
sudo docker stop teleshop telebot 2>/dev/null || true
|
||||
sudo docker rm teleshop telebot 2>/dev/null || true
|
||||
|
||||
echo "=== Starting new containers ==="
|
||||
mkdir -p /home/sysadmin/teleshop-source
|
||||
cp /tmp/docker-compose.alexhost.yml /home/sysadmin/teleshop-source/docker-compose.yml
|
||||
cd /home/sysadmin/teleshop-source
|
||||
sudo docker compose up -d
|
||||
|
||||
echo "=== Waiting for health checks ==="
|
||||
sleep 30
|
||||
sudo docker ps --format "table {{.Names}}\t{{.Status}}"
|
||||
|
||||
echo "=== Cleanup ==="
|
||||
rm -f /tmp/teleshop-image.tar.gz /tmp/telebot-image.tar.gz
|
||||
echo "=== Deployment complete ==="
|
||||
DEPLOY_EOF
|
||||
after_script:
|
||||
- rm -f teleshop-image.tar.gz telebot-image.tar.gz
|
||||
environment:
|
||||
name: production
|
||||
url: https://teleshop.silentmary.mywire.org
|
||||
tags:
|
||||
- docker
|
||||
|
||||
# Deploy only TeleShop
|
||||
deploy-teleshop-only:
|
||||
stage: deploy
|
||||
image: docker:24.0
|
||||
services:
|
||||
- docker:24.0-dind
|
||||
rules:
|
||||
- when: manual
|
||||
variables:
|
||||
DOCKER_TLS_CERTDIR: "/certs"
|
||||
before_script:
|
||||
- apk add --no-cache openssh-client curl tar gzip
|
||||
- mkdir -p ~/.ssh
|
||||
- echo "$ALEXHOST_SSH_KEY" > ~/.ssh/id_rsa
|
||||
- chmod 600 ~/.ssh/id_rsa
|
||||
- ssh-keyscan -H $ALEXHOST_IP >> ~/.ssh/known_hosts 2>/dev/null || true
|
||||
script:
|
||||
- echo "Building TeleShop image..."
|
||||
- docker build -t ${TELESHOP_IMAGE}:latest -f Dockerfile .
|
||||
- docker save ${TELESHOP_IMAGE}:latest | gzip > teleshop-image.tar.gz
|
||||
- scp -o StrictHostKeyChecking=no teleshop-image.tar.gz ${ALEXHOST_USER}@${ALEXHOST_IP}:/tmp/
|
||||
- scp -o StrictHostKeyChecking=no docker-compose.alexhost.yml ${ALEXHOST_USER}@${ALEXHOST_IP}:/tmp/
|
||||
- |
|
||||
ssh -o StrictHostKeyChecking=no ${ALEXHOST_USER}@${ALEXHOST_IP} << 'EOF'
|
||||
gunzip -c /tmp/teleshop-image.tar.gz | sudo docker load
|
||||
sudo docker tag littleshop:latest localhost:5000/littleshop:latest
|
||||
sudo docker push localhost:5000/littleshop:latest
|
||||
sudo docker stop teleshop 2>/dev/null || true
|
||||
sudo docker rm teleshop 2>/dev/null || true
|
||||
mkdir -p /home/sysadmin/teleshop-source
|
||||
cp /tmp/docker-compose.alexhost.yml /home/sysadmin/teleshop-source/docker-compose.yml
|
||||
cd /home/sysadmin/teleshop-source && sudo docker compose up -d teleshop
|
||||
sleep 30 && sudo docker ps | grep teleshop
|
||||
rm -f /tmp/teleshop-image.tar.gz
|
||||
EOF
|
||||
after_script:
|
||||
- rm -f teleshop-image.tar.gz
|
||||
environment:
|
||||
name: production
|
||||
url: https://teleshop.silentmary.mywire.org
|
||||
tags:
|
||||
- docker
|
||||
|
||||
# Deploy only TeleBot
|
||||
deploy-telebot-only:
|
||||
stage: deploy
|
||||
image: docker:24.0
|
||||
services:
|
||||
- docker:24.0-dind
|
||||
rules:
|
||||
- when: manual
|
||||
before_script:
|
||||
- apk add --no-cache openssh-client curl tar gzip
|
||||
- mkdir -p ~/.ssh
|
||||
- echo "$ALEXHOST_SSH_KEY" > ~/.ssh/id_rsa
|
||||
- chmod 600 ~/.ssh/id_rsa
|
||||
- ssh-keyscan -H $ALEXHOST_IP >> ~/.ssh/known_hosts 2>/dev/null || true
|
||||
script:
|
||||
- echo "Building TeleBot image..."
|
||||
- docker build -t ${TELEBOT_IMAGE}:latest -f Dockerfile.telebot .
|
||||
- docker save ${TELEBOT_IMAGE}:latest | gzip > telebot-image.tar.gz
|
||||
- scp -o StrictHostKeyChecking=no telebot-image.tar.gz ${ALEXHOST_USER}@${ALEXHOST_IP}:/tmp/
|
||||
- |
|
||||
ssh -o StrictHostKeyChecking=no ${ALEXHOST_USER}@${ALEXHOST_IP} << 'EOF'
|
||||
gunzip -c /tmp/telebot-image.tar.gz | sudo docker load
|
||||
sudo docker tag telebot:latest localhost:5000/telebot:latest
|
||||
sudo docker push localhost:5000/telebot:latest
|
||||
sudo docker stop telebot 2>/dev/null || true
|
||||
sudo docker rm telebot 2>/dev/null || true
|
||||
cd /home/sysadmin/teleshop-source && sudo docker compose up -d telebot
|
||||
sleep 20 && sudo docker ps | grep telebot
|
||||
rm -f /tmp/telebot-image.tar.gz
|
||||
EOF
|
||||
after_script:
|
||||
- rm -f telebot-image.tar.gz
|
||||
environment:
|
||||
name: production
|
||||
tags:
|
||||
- docker
|
||||
|
||||
# Verify deployment status
|
||||
verify-deployment:
|
||||
stage: verify
|
||||
image: alpine:latest
|
||||
rules:
|
||||
- when: manual
|
||||
before_script:
|
||||
- apk add --no-cache openssh-client curl
|
||||
- mkdir -p ~/.ssh
|
||||
- echo "$ALEXHOST_SSH_KEY" > ~/.ssh/id_rsa
|
||||
- chmod 600 ~/.ssh/id_rsa
|
||||
- ssh-keyscan -H $ALEXHOST_IP >> ~/.ssh/known_hosts 2>/dev/null || true
|
||||
script:
|
||||
- |
|
||||
ssh -o StrictHostKeyChecking=no ${ALEXHOST_USER}@${ALEXHOST_IP} << 'EOF'
|
||||
echo "=== Container Status ==="
|
||||
sudo docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
|
||||
echo ""
|
||||
echo "=== Health Checks ==="
|
||||
curl -sf http://localhost:5100/health && echo " TeleShop: OK" || echo " TeleShop: FAIL"
|
||||
echo ""
|
||||
echo "=== Deployment verified ==="
|
||||
EOF
|
||||
@ -171,7 +171,7 @@ deploy_telebot() {
|
||||
verify_deployment() {
|
||||
echo -e "${YELLOW}=== Verifying Deployment ===${NC}"
|
||||
|
||||
ssh_exec "
|
||||
ssh_sudo "
|
||||
echo ''
|
||||
echo 'Container Status:'
|
||||
sudo docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' | grep -E 'NAMES|teleshop|telebot'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user