mirror of https://github.com/elunez/eladmin
push master
parent
e68c1baaf5
commit
807985ec36
|
@ -34,22 +34,56 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install sshpass
|
- name: Install expect
|
||||||
run: sudo apt-get install -y sshpass
|
run: sudo apt-get install -y expect
|
||||||
|
|
||||||
- name: Add server to known hosts
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
ssh-keyscan -H 172.235.32.135 >> ~/.ssh/known_hosts
|
|
||||||
|
|
||||||
- name: Deploy to server
|
- name: Deploy using expect script
|
||||||
env:
|
env:
|
||||||
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}
|
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}
|
||||||
run: |
|
run: |
|
||||||
# Using -o options to handle first-time connection and avoid strict host checking
|
# Create an expect script to handle interactive password prompts
|
||||||
export SSHPASS="$SSH_PASSWORD"
|
cat > deploy.exp << 'EOF'
|
||||||
sshpass -e ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@172.235.32.135 "cd backend && \
|
#!/usr/bin/expect -f
|
||||||
pkill -f 'java -jar' || true && \
|
|
||||||
git pull && \
|
# Get password from environment
|
||||||
./mvnw clean package && \
|
set password $env(SSH_PASSWORD)
|
||||||
nohup java -jar eladmin-system/target/eladmin-system-2.7.jar > app.log 2>&1 &"
|
set timeout 300
|
||||||
|
|
||||||
|
# Start SSH session
|
||||||
|
spawn ssh root@172.235.32.135
|
||||||
|
|
||||||
|
# Handle the password prompt
|
||||||
|
expect {
|
||||||
|
"Password:" {
|
||||||
|
send "$password\r"
|
||||||
|
exp_continue
|
||||||
|
}
|
||||||
|
"password:" {
|
||||||
|
send "$password\r"
|
||||||
|
exp_continue
|
||||||
|
}
|
||||||
|
"*#" {
|
||||||
|
# We have a root prompt, continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run deployment commands
|
||||||
|
send "cd backend\r"
|
||||||
|
expect "*#"
|
||||||
|
send "pkill -f 'java -jar' || true\r"
|
||||||
|
expect "*#"
|
||||||
|
send "git pull\r"
|
||||||
|
expect "*#"
|
||||||
|
send "./mvnw clean package\r"
|
||||||
|
expect "*#"
|
||||||
|
send "nohup java -jar eladmin-system/target/eladmin-system-2.7.jar > app.log 2>&1 &\r"
|
||||||
|
expect "*#"
|
||||||
|
send "exit\r"
|
||||||
|
expect eof
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Make script executable
|
||||||
|
chmod +x deploy.exp
|
||||||
|
|
||||||
|
# Run the expect script
|
||||||
|
./deploy.exp
|
||||||
|
|
Loading…
Reference in New Issue