From 1c66411d5dfa2c0addd832a9de2a0a4194e06174 Mon Sep 17 00:00:00 2001 From: chanhengseang Date: Mon, 26 May 2025 16:16:10 -0700 Subject: [PATCH 1/6] push master --- .github/workflows/maven-build.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.github/workflows/maven-build.yml b/.github/workflows/maven-build.yml index 316a2185..b2086f0e 100644 --- a/.github/workflows/maven-build.yml +++ b/.github/workflows/maven-build.yml @@ -23,3 +23,28 @@ jobs: - name: Build with Maven run: ./mvnw clean package -DskipTests + + deploy: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/master' + + steps: + - uses: actions/checkout@v3 + + - name: Setup SSH + uses: webfactory/ssh-agent@v0.7.0 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Add server to known hosts + run: | + mkdir -p ~/.ssh + ssh-keyscan -H 172.235.32.135 >> ~/.ssh/known_hosts + + - name: Deploy to server + run: | + ssh ubuntu@172.235.32.135 "cd backend && \ + pkill -f 'java -jar' || true && \ + git pull && \ + ./mvnw clean package && \ + nohup java -jar target/*.jar > app.log 2>&1 &" From 3ef96bbd73e441b9561c3913d700916717bc78e9 Mon Sep 17 00:00:00 2001 From: chanhengseang Date: Mon, 26 May 2025 16:22:27 -0700 Subject: [PATCH 2/6] push master --- .github/workflows/maven-build.yml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/maven-build.yml b/.github/workflows/maven-build.yml index b2086f0e..70fac4f8 100644 --- a/.github/workflows/maven-build.yml +++ b/.github/workflows/maven-build.yml @@ -2,7 +2,9 @@ name: Maven Build on: push: - branches: [ '*' ] + branches: + - '*' # This runs on all branches for the build job + - 'master' # Explicitly include master jobs: build: @@ -30,21 +32,21 @@ jobs: steps: - uses: actions/checkout@v3 - - - name: Setup SSH - uses: webfactory/ssh-agent@v0.7.0 - with: - ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - + + - name: Install sshpass + run: sudo apt-get install -y sshpass + - name: Add server to known hosts run: | mkdir -p ~/.ssh ssh-keyscan -H 172.235.32.135 >> ~/.ssh/known_hosts - name: Deploy to server + env: + SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }} run: | - ssh ubuntu@172.235.32.135 "cd backend && \ + sshpass -p "$SSH_PASSWORD" ssh root@172.235.32.135 "cd backend && \ pkill -f 'java -jar' || true && \ git pull && \ ./mvnw clean package && \ - nohup java -jar target/*.jar > app.log 2>&1 &" + nohup java -jar eladmin-system/target/eladmin-system-2.7.jar > app.log 2>&1 &" From e68c1baaf5ba71186f9ffd6f31722da53c7c822b Mon Sep 17 00:00:00 2001 From: chanhengseang Date: Mon, 26 May 2025 16:24:57 -0700 Subject: [PATCH 3/6] push master --- .github/workflows/maven-build.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/maven-build.yml b/.github/workflows/maven-build.yml index 70fac4f8..d009161f 100644 --- a/.github/workflows/maven-build.yml +++ b/.github/workflows/maven-build.yml @@ -29,6 +29,7 @@ jobs: deploy: runs-on: ubuntu-latest if: github.ref == 'refs/heads/master' + needs: build steps: - uses: actions/checkout@v3 @@ -45,7 +46,9 @@ jobs: env: SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }} run: | - sshpass -p "$SSH_PASSWORD" ssh root@172.235.32.135 "cd backend && \ + # Using -o options to handle first-time connection and avoid strict host checking + export SSHPASS="$SSH_PASSWORD" + sshpass -e ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@172.235.32.135 "cd backend && \ pkill -f 'java -jar' || true && \ git pull && \ ./mvnw clean package && \ From 807985ec36b220644eefab449bbcfadcafc41adc Mon Sep 17 00:00:00 2001 From: chanhengseang Date: Mon, 26 May 2025 16:27:52 -0700 Subject: [PATCH 4/6] push master --- .github/workflows/maven-build.yml | 64 +++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/.github/workflows/maven-build.yml b/.github/workflows/maven-build.yml index d009161f..4a23a672 100644 --- a/.github/workflows/maven-build.yml +++ b/.github/workflows/maven-build.yml @@ -34,22 +34,56 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Install sshpass - run: sudo apt-get install -y sshpass - - - name: Add server to known hosts - run: | - mkdir -p ~/.ssh - ssh-keyscan -H 172.235.32.135 >> ~/.ssh/known_hosts + - name: Install expect + run: sudo apt-get install -y expect - - name: Deploy to server + - name: Deploy using expect script env: SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }} run: | - # Using -o options to handle first-time connection and avoid strict host checking - export SSHPASS="$SSH_PASSWORD" - sshpass -e ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@172.235.32.135 "cd backend && \ - pkill -f 'java -jar' || true && \ - git pull && \ - ./mvnw clean package && \ - nohup java -jar eladmin-system/target/eladmin-system-2.7.jar > app.log 2>&1 &" + # Create an expect script to handle interactive password prompts + cat > deploy.exp << 'EOF' + #!/usr/bin/expect -f + + # Get password from environment + set password $env(SSH_PASSWORD) + 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 From afd176ab96737a77d31aace4e6afa0a7581de8c0 Mon Sep 17 00:00:00 2001 From: chanhengseang Date: Mon, 26 May 2025 16:35:47 -0700 Subject: [PATCH 5/6] push master --- .github/workflows/maven-build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/maven-build.yml b/.github/workflows/maven-build.yml index 4a23a672..0c08aaa7 100644 --- a/.github/workflows/maven-build.yml +++ b/.github/workflows/maven-build.yml @@ -52,8 +52,12 @@ jobs: # Start SSH session spawn ssh root@172.235.32.135 - # Handle the password prompt + # Handle the host key verification prompt and password prompt expect { + "Are you sure you want to continue connecting (yes/no/[fingerprint])?" { + send "yes\r" + exp_continue + } "Password:" { send "$password\r" exp_continue From 28c235271ef5890c2b3c32563c2375ead47694b0 Mon Sep 17 00:00:00 2001 From: chanhengseang Date: Mon, 26 May 2025 16:38:57 -0700 Subject: [PATCH 6/6] push master --- .github/workflows/maven-build.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/maven-build.yml b/.github/workflows/maven-build.yml index 0c08aaa7..117bdf48 100644 --- a/.github/workflows/maven-build.yml +++ b/.github/workflows/maven-build.yml @@ -50,14 +50,10 @@ jobs: set timeout 300 # Start SSH session - spawn ssh root@172.235.32.135 + spawn ssh -o StrictHostKeyChecking=no root@172.235.32.135 - # Handle the host key verification prompt and password prompt + # Handle the password prompt expect { - "Are you sure you want to continue connecting (yes/no/[fingerprint])?" { - send "yes\r" - exp_continue - } "Password:" { send "$password\r" exp_continue