-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (93 loc) · 3.67 KB
/
gradle-publish.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
on:
push: # feature/*와 develop 브랜치에서 push가 일어났을 때 github action 동작
branches:
#- 'main'
- 'develop'
- 'feature/*'
pull_request: # feature/*와 develop 브랜치에서 PR이 일어났을 때 github action 동작
branches:
#- 'main'
- 'develop'
- 'feature/*'
# 참고사항
# push가 일어난 브랜치에 PR이 존재하면, push에 대한 이벤트와 PR에 대한 이벤트 모두 발생합니다.
jobs:
build:
runs-on: ubuntu-latest # 실행 환경 지정
steps:
- uses: actions/checkout@v2 # github action 버전 지정(major version)
- name: Set up JDK 11 # JAVA 버전 지정
uses: actions/setup-java@v1
with:
java-version: 11
- name: Setup MySQL
uses: samin/mysql-action@v1
with:
character set server: 'utf8'
mysql database: 'catch_bug_db'
mysql user: 'user01'
mysql password: 'user01'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
## create application-database.yaml
- name: make application-database.yaml
run: |
# create application-database.yaml
cd ./src/main/resources
# application-database.yaml 파일 생성
touch ./application-database.yaml
# GitHub-Actions 에서 설정한 값을 application-database.yaml 파일에 쓰기
echo "${{ secrets.DATABASE }}" >> ./application-database.yaml
shell: bash
- name: Build with Gradle # 실제 application build(-x 옵션을 통해 test는 제외)
run: ./gradlew build -x test
- name: Test with Gradle # test application build
run: ./gradlew test
- name: Publish Unit Test Results # test 후 result를 보기 위해 추가
uses: EnricoMi/publish-unit-test-result-action@v1
if: ${{ always() }} # test가 실패해도 report를 남기기 위해 설정
with:
files: build/test-results/**/*.xml
deploy:
if: github.base_ref == 'main'
runs-on: ubuntu-latest # 실행 환경 지정
needs: build
steps:
# 배포 Job
# 도커허브 push
- name: Docker build
run: |
docker login -u ${{ secrets.DOCKER_ID }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t app .
docker tag app ${{ secrets.DOCKER_ID }}/${{ secrets.DOCKER_REPO }}
docker push ${{ secrets.DOCKER_ID }}/&{{ secrets.DOCKER_REPO }}
# ec2 접속 및 도커 pull
# 도커 실행
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_HOST }} # EC2 인스턴스 퍼블릭 DNS
username: ubuntu
key: ${{ secrets.AWS_SSH_KEY }} # pem 키--
# 도커 작업
script: |
docker pull ${{ secrets.DOCKER_ID }}/${{ secrets.DOCKER_REPO }}:latest
docker tag app ${{ secrets.DOCKER_ID }}/${{ secrets.DOCKER_REPO }}:latest
docker stop app
docker rm app
docker rmi ${{ secrets.DOCKER_ID }}/${{ secrets.DOCKER_REPO }}:latest
docker run -d --rm --name app --network catch_bug_net -p 8080:8080 ${{ secrets.DOCKER_ID }}/${{ secrets.DOCKER_REPO }}:latest
slack:
runs-on: ubuntu-latest # 실행 환경 지정
steps:
- name: Slack
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
author_name: youngho Cha
fields: repo,commit,message,author
mention: here
if_mention: failure,cancelled
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()