-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (72 loc) · 2.59 KB
/
Copy pathdeploy.yml
File metadata and controls
82 lines (72 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Manual Deployment
on:
workflow_dispatch: # Allows manual triggering from GitHub UI
jobs:
# Job 1: Tooling System & Testing
validate-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Set up JDK 17
uses: actions/setup-java@v6
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Validate & Test (Format, Lint, Test)
run: mvn spotless:check checkstyle:check test
# Job 2: Build the Deployment Artifact
build-artifact:
needs: validate-and-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Set up JDK 17
uses: actions/setup-java@v6
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build Fat JAR
run: mvn clean package -DskipTests
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: deployment-jar
path: target/basic-web-server-1.0-SNAPSHOT.jar
# Job 3: Actual Deployment to Target Server
deploy:
needs: build-artifact
runs-on: ubuntu-latest
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: deployment-jar
- name: Copy Artifact to VM via SCP
uses: appleboy/scp-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_PORT || '22' }}
source: "basic-web-server-1.0-SNAPSHOT.jar"
target: "/opt/basic-web-server/"
- name: Restart Service via SSH
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_PORT || '22' }}
script: |
echo "Deployment starting on remote VM..."
cd /opt/basic-web-server
# If you are using a systemd service (recommended professional approach):
# sudo systemctl restart basic-web-server
# Or if you are using a raw shell script to restart:
echo "Stopping old server instance..."
pkill -f 'basic-web-server-1.0-SNAPSHOT.jar' || true
echo "Starting new server instance in background..."
nohup java -jar basic-web-server-1.0-SNAPSHOT.jar > server.log 2>&1 &
echo "Deployment completed successfully!"