Deploy ELK Stack #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy ELK Stack | |
| on: | |
| push: | |
| branches: [main] | |
| paths: ["nodejs-elk-ec2/**"] | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Deploy ELK Stack to EC2 | |
| uses: appleboy/ssh-action@v0.1.5 | |
| with: | |
| host: ${{ secrets.ELK_EC2_HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.ELK_EC2_SSH_KEY }} | |
| script: | | |
| echo "🚀 Deploying ELK Stack..." | |
| cd /opt/nodejs-elk-app | |
| # Clone or pull repository | |
| if [ -d "DevOps" ]; then | |
| echo "�� Pulling latest changes..." | |
| cd DevOps | |
| git pull origin main | |
| cd .. | |
| else | |
| echo "📥 Cloning repository..." | |
| git clone https://github.com/ratishjain12/DevOps.git | |
| fi | |
| # Navigate to server directory | |
| cd DevOps/nodejs-elk-ec2/server | |
| # Create logs directory | |
| mkdir -p logs | |
| # Stop existing containers | |
| echo "🛑 Stopping existing containers..." | |
| docker compose down | |
| # Start the ELK stack | |
| echo "🚀 Starting ELK stack..." | |
| sudo docker compose up -d | |
| # Wait for services to start | |
| echo "⏳ Waiting for services to start..." | |
| sleep 60 | |
| # Check service status | |
| echo "📊 Checking service status..." | |
| sudo docker compose ps |