CI/CD Pipeline #5
This file contains 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: CI/CD Pipeline | |
on: | |
workflow_dispatch | |
jobs: | |
ssh-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Install SSHpass | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y sshpass | |
- name: SSH into server and deploy app | |
env: | |
SSH_USERNAME: ${{ secrets.SSH_USERNAME }} | |
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }} | |
SSH_IP: ${{ secrets.SSH_IP }} | |
REPO_URL: ${{ secrets.REPO_URL }} | |
run: | | |
sshpass -p "$SSH_PASSWORD" ssh -o StrictHostKeyChecking=no "$SSH_USERNAME@$SSH_IP" " | |
sudo apt update && sudo apt install -y nginx && | |
sudo systemctl enable nginx && | |
sudo systemctl start nginx && | |
if [ -d '/var/www/shopdesk-fe' ]; then | |
cd /var/www/shopdesk-fe && git pull origin main | |
else | |
git clone $REPO_URL && | |
cd $(basename $REPO_URL .git) | |
fi && | |
# Install and configure Nginx | |
sudo apt-get update -qq | |
sudo apt-get install -y -qq nginx | |
sudo rm -f /etc/nginx/sites-enabled/default | |
# Create Nginx configuration | |
sudo bash -c 'cat > /etc/nginx/sites-available/shopdesk-fe <<EOF | |
server { | |
listen 80; | |
server_name 157.180.27.189; | |
location / { | |
proxy_pass http://localhost:7777; | |
proxy_set_header Host \$host; | |
proxy_set_header X-Real-IP \$remote_addr; | |
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto \$scheme; | |
} | |
} | |
EOF' | |
# Enable configuration and reload Nginx | |
sudo ln -sf /etc/nginx/sites-available/shopdesk-fe /etc/nginx/sites-enabled/ | |
sudo nginx -t && sudo systemctl reload nginx | |
echo 'Running command...' && | |
npm run dev | |
" | |