-
Notifications
You must be signed in to change notification settings - Fork 1
73 lines (62 loc) · 2.36 KB
/
cd.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
name: cd with Gradle
on:
push:
branches:
- main # main 브랜치에 push될 때
permissions: write-all # 테스트 결과 작성을 위해 쓰기권한 추가
jobs:
build:
if: github.event.pull_request.merged == true || github.event_name == 'push' # PR merge 또는 push일 때 실행
runs-on: ubuntu-latest # 환경
steps:
- name: Checkout repository
uses: actions/checkout@v3 # 코드 체크아웃 = 가상환경 복사
- name: Set up JDK 21
uses: actions/setup-java@v3 #jdk 컴파일러
with:
java-version: '21'
distribution: 'temurin' # 자바 개발 키트 배포판
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Grant execute permission for Gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build -x test #빌드
- name: Ensure target directory exists
uses: appleboy/ssh-action@master # SSH를 통해 대상 디렉토리 생성
with:
username: ubuntu
host: ${{ secrets.SSH_HOST }}
key: ${{ secrets.SSH_KEY }}
script: |
mkdir -p /home/ubuntu/gather_back_end
- name: List build directory
run: ls -la build/libs
- name: Transfer Build File using SCP
uses: appleboy/scp-action@master # .jar 파일 원격 서버로 복사
with:
username: ubuntu
host: ${{ secrets.SSH_HOST }}
key: ${{ secrets.SSH_KEY }}
source: |
build/libs/gather_back_end-0.0.1-SNAPSHOT.jar
target: "/home/ubuntu/gather_back_end"
- name: Deploy using Docker Compose via SSH(Prod)
if: github.ref == 'refs/heads/main'
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ubuntu
key: ${{ secrets.SSH_KEY }}
script_stop: true
script: |
cd /home/ubuntu/gather_back_end || exit 1 # 경로 변경 실패 시 종료
sudo docker compose --env-file .env down
sudo docker compose --env-file .env up --build -d