Skip to content

Workflow file for this run

name: CI/CD Pipeline for DigitalOcean Droplet
on:
push:
branches:
- cicd
jobs:
redeploy:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the code
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Set up SSH for DigitalOcean access
- name: Set up SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_KEY }}
# Step 3: Deploy to DigitalOcean
- name: Deploy to DigitalOcean
run: |
ssh -o StrictHostKeyChecking=no ubuntu@${{ secrets.SSH_HOST }} << EOF
# Define sudo password
SUDO_PASS='${{ secrets.SUDO_PASSWORD }}'
# Ensure directories exist
if [ ! -d "aibotprototype/main_server" ]; then
echo "Directory aibotprototype/main_server does not exist"
exit 1
fi
if [ ! -d "aibotprototype/processing_server" ]; then
echo "Directory aibotprototype/processing_server does not exist"
exit 1
fi
# Rebuild and run container chatbotmain
CONTAINER_ID=\$(echo \$SUDO_PASS | sudo -S docker ps -q --filter "name=chatbotmain")
if [ "\$CONTAINER_ID" ]; then
echo "Stopping and removing container chatbotmain..."
echo \$SUDO_PASS | sudo -S docker stop \$CONTAINER_ID
echo \$SUDO_PASS | sudo -S docker rm \$CONTAINER_ID
IMAGE_ID=\$(echo \$SUDO_PASS | sudo -S docker images -q chatbotmain)
if [ "\$IMAGE_ID" ]; then
echo "Removing image chatbotmain..."
echo \$SUDO_PASS | sudo -S docker rmi -f \$IMAGE_ID
fi
fi
echo "Rebuilding and running container chatbotmain..."
cd aibotprototype/main_server/
if [ ! -f "Dockerfile" ]; then
echo "Dockerfile not found in aibotprototype/main_server/"
exit 1
fi
echo \$SUDO_PASS | sudo -S docker build -t chatbotmain .
echo \$SUDO_PASS | sudo -S docker run -d -p 8000:8000 chatbotmain || echo "Port 8000 is already in use"
# Rebuild and run container chatbotprocess
CONTAINER_ID=\$(echo \$SUDO_PASS | sudo -S docker ps -q --filter "name=chatbotprocess")
if [ "\$CONTAINER_ID" ]; then
echo "Stopping and removing container chatbotprocess..."
echo \$SUDO_PASS | sudo -S docker stop \$CONTAINER_ID
echo \$SUDO_PASS | sudo -S docker rm \$CONTAINER_ID
IMAGE_ID=\$(echo \$SUDO_PASS | sudo -S docker images -q chatbotprocess)
if [ "\$IMAGE_ID" ]; then
echo "Removing image chatbotprocess..."
echo \$SUDO_PASS | sudo -S docker rmi -f \$IMAGE_ID
fi
fi
echo "Rebuilding and running container chatbotprocess..."
cd aibotprototype/processing_server/
if [ ! -f "Dockerfile" ]; then
echo "Dockerfile not found in aibotprototype/processing_server/"
exit 1
fi
echo \$SUDO_PASS | sudo -S docker build -t chatbotprocess .
echo \$SUDO_PASS | sudo -S docker run -d -p 9000:9000 chatbotprocess || echo "Port 9000 is already in use"
EOF
env:
SUDO_PASSWORD: ${{ secrets.SUDO_PASSWORD }}