forked from codesquad-members-2023/second-hand-max
-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (72 loc) · 2.45 KB
/
workflow.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
76
77
78
79
80
81
82
83
84
name: CD
on:
pull_request:
branches:
- main
jobs:
build-jar:
runs-on: ubuntu-latest
steps:
# SOURCE 단계 - 저장소 checkout
- name: Checkout-source code
uses: actions/checkout@v3
with:
token: ${{ secrets.ACCESS_TOKEN_FOR_GITHUB_ACTIONS }}
submodules: true
# JDK 설치
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
# Gradle 실행권한 부여
- name: Grant execute permission to gradlew
run: chmod +x ./gradlew
# Spring boot application 빌드
- name: Build with gradle
run: ./gradlew -x test clean build
- name: Cache PhysicalTheraphy build directory
uses: actions/cache@v3
with:
path: ./
key: ${{ runner.os }}-physicaltheraphy-build-cache-${{ steps.short-sha.outputs.sha }}
backend-deploy:
runs-on: ubuntu-latest
needs: build-jar
steps:
# SOURCE 단계 - 저장소 checkout
- name: Checkout-source code
uses: actions/checkout@v3
with:
token: ${{ secrets.ACCESS_TOKEN_FOR_GITHUB_ACTIONS }}
submodules: true
- name: Restore Gradle cache directory
uses: actions/cache@v3
with:
path: ./
key: ${{ runner.os }}-physicaltheraphy-build-cache-${{ steps.short-sha.outputs.sha }}
# docker image 빌드
- name: Build docker image
run: docker build --no-cache -t ${{ secrets.DOCKER_HUB_USERNAME }}/app .
# docker hub 로그인
- name: Login docker hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
# docker hub 퍼블리시
- name: Publish to docker hub
run: docker push ${{ secrets.DOCKER_HUB_USERNAME }}/app
# WAS 인스턴스 접속 & 애플리케이션 실행
- name: Connect to WAS & Execute Application
uses: appleboy/[email protected]
with:
host: ${{ secrets.WAS_HOST }}
username: ${{ secrets.WAS_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: 22
script: |
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/app
docker run -d -p 8080:8080 --name app ${{ secrets.DOCKER_HUB_USERNAME }}/app