-
Notifications
You must be signed in to change notification settings - Fork 0
49 lines (42 loc) · 1.45 KB
/
cd.yml
File metadata and controls
49 lines (42 loc) · 1.45 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
name: Build and Deploy to EC2
on:
push:
branches:
- main
- dev
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Build JAR file
run: ./gradlew clean build -x test
- name: Upload JAR to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.DEVSYNC_EC2_HOST }}
username: ${{ secrets.DEVSYNC_EC2_USERNAME }}
key: ${{ secrets.DEVSYNC_EC2_PRIVATE_KEY }}
source: "./build/libs/devsync.jar"
target: "/home/ubuntu/"
- name: Run JAR on EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEVSYNC_EC2_HOST }}
username: ${{ secrets.DEVSYNC_EC2_USERNAME }}
key: ${{ secrets.DEVSYNC_EC2_PRIVATE_KEY }}
script: |
set -x
echo "Setting up environment variables..."
echo "RDS_ENDPOINT=${{ secrets.RDS_ENDPOINT }}" >> ~/.bashrc
echo "RDS_USERNAME=${{ secrets.RDS_USERNAME }}" >> ~/.bashrc
echo "RDS_PASSWORD=${{ secrets.RDS_PASSWORD }}" >> ~/.bashrc
source ~/.bashrc
echo "Starting application..."
nohup java -jar -Dspring.profiles.active=prod /home/ubuntu/devsync.jar > /home/ubuntu/app.log 2>&1 &