Update main.yml #25
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: Vulnerability | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| jobs: | ||
| deployment: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout Repository | ||
| uses: actions/checkout@v3 | ||
| - name: Install sshpass | ||
| run: sudo apt-get install -y sshpass | ||
| - name: Add Azure VM to known_hosts | ||
| run: | | ||
| mkdir -p ~/.ssh | ||
| ssh-keyscan -H ${{ secrets.VM_HOST }} >> ~/.ssh/known_hosts | ||
| - name: Verify known_hosts Entry | ||
| run: | | ||
| cat ~/.ssh/known_hosts # Optional step to confirm the host is added | ||
| - name: Synchronize Code with Azure VM Using rsync and sshpass | ||
| env: | ||
| PASSWORD: ${{ secrets.PASSWORD }} | ||
| run: | | ||
| sshpass -p "$PASSWORD" rsync -avz --exclude='.git' --exclude='.env' \ | ||
| --no-perms --omit-dir-times --no-group \ | ||
| -e "ssh -o StrictHostKeyChecking=no" ./ ${{ secrets.VM_USER }}@${{ secrets.VM_HOST }}:/home/dev/CAPEC-Rag/ | ||
| - name: Restart Docker Compose Services | ||
| uses: appleboy/[email protected] | ||
| with: | ||
| host: ${{ secrets.VM_HOST }} | ||
| username: ${{ secrets.VM_USER }} | ||
| password: ${{ secrets.PASSWORD }} | ||
| script: | | ||
| echo "Stopping existing Docker Compose services..." | ||
| cd /home/dev/CAPEC-Rag/ | ||
| echo "$PASSWORD" | sudo -S docker-compose down | ||
| echo "Starting Docker Compose services..." | ||
| echo "$PASSWORD" | sudo -S docker-compose build --no-cache | ||
| echo "$PASSWORD" | sudo -S docker-compose up -d | ||
| echo "Successfully deployed the application!" | ||
| env: | ||
| PASSWORD: ${{ secrets.PASSWORD }} | ||