-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (63 loc) · 2.43 KB
/
deploy.yml
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
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: deploy
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Setup MySQL
run: |
sudo docker run -d -p 20000:3306 -e MYSQL_DATABASE=busan -e MYSQL_ROOT_PASSWORD=password mysql:8.0.23
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build with Gradle
uses: gradle/[email protected]
with:
arguments: clean openapi3 build
- name: SCP to prod server
uses: appleboy/scp-action@master
with:
username: ubuntu
host: ${{ secrets.HOST }}
key: ${{ secrets.PRIVATE_KEY }}
source: "build/libs/*-SNAPSHOT.jar"
target: "/home/ubuntu/server"
strip_components: 2
- name: Deploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: 'ubuntu'
key: ${{ secrets.PRIVATE_KEY }}
script: |
cd /home/ubuntu/server
if sudo lsof -i :8080;
then
echo "Port 8080 is already in use. Killing the process..."
sudo lsof -i :8080 | awk 'NR!=1 {print $2}' | sudo xargs kill -9
fi
while lsof -i :8080
do
echo "Wait for killing prior process..."
sleep 1
done
echo "Start Spring..."
sudo nohup java -jar -Dspring.profiles.active=prod -Duser.timezone=Asia/Seoul busan-0.0.1-SNAPSHOT.jar > nohup.out 2> nohup.err < /dev/null &
echo "Finished!"
- name: Docker build and push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} .
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}