-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (108 loc) · 4.63 KB
/
githubaction.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# 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://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
name: Java CI with Gradle
on:
push:
branches: [ "main","develop" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: Cache Gradle packages
uses: actions/cache@v2
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
- name: Cleanup Gradle Cache
if: ${{ always() }}
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties
- name: Docker build & push to prod
if: contains(github.ref, 'main')
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile-prod -t wiki .
docker tag wiki ${{ secrets.DOCKER_HUB_PROD_REPO }}:1.0
docker push ${{ secrets.DOCKER_HUB_PROD_REPO }}:1.0
- name: Docker build & push to dev
if: contains(github.ref, 'develop')
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile-dev -t wiki .
docker tag wiki ${{ secrets.DOCKER_HUB_DEV_REPO }}:1.0
docker push ${{ secrets.DOCKER_HUB_DEV_REPO }}:1.0
- name: Discord notification
if: contains(github.ref, 'main')
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: '운영 서버 배포가 진행중입니다!!! 서버가 5-6분 뒤에 다시 서버가 시작 됩니다.'
- name: Discord notification
if: contains(github.ref, 'develop')
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: '개발 서버 배포가 진행중입니다!!! 서버가 5-6분 뒤에 다시 서버가 시작 됩니다.'
- name: prod SSH Remote Commands
uses: appleboy/[email protected]
id: deploy-prod
if: contains(github.ref, 'main')
with:
host: ${{ secrets.NCP_SERVER_HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
timeout: 40s # 30초 기본
script: |
echo "테스트 출력"
docker stop wiki
docker rm wiki
docker rmi ${{ secrets.DOCKER_HUB_PROD_REPO }}:1.0
docker pull ${{ secrets.DOCKER_HUB_PROD_REPO }}:1.0
docker run --name=wiki -p 8080:8080 -e JAVA_OPTS=-Djasypt.encryptor.password=${{ secrets.ENCRYTOR_PASSWORD }} --restart unless-stopped -e TZ=Asia/Seoul -d ${{ secrets.DOCKER_HUB_PROD_REPO }}:1.0
- name: dev SSH Remote Commands
uses: appleboy/[email protected]
id: deploy-dev
if: contains(github.ref, 'develop')
with:
host: ${{ secrets.EC2_SERVER_HOST }}
username: ${{ secrets.EC2_USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
timeout: 40s # 30초 기본
script: |
echo "테스트 출력"
docker stop wiki
docker rm wiki
docker rmi ${{ secrets.DOCKER_HUB_DEV_REPO }}:1.0
docker pull ${{ secrets.DOCKER_HUB_DEV_REPO }}:1.0
docker run --name=wiki -p 8080:8080 -e "SPRING_PROFILES_ACTIVE=dev" -e JAVA_OPTS=-Djasypt.encryptor.password=${{ secrets.ENCRYTOR_PASSWORD }} --restart unless-stopped -e TZ=Asia/Seoul -d ${{ secrets.DOCKER_HUB_DEV_REPO }}:1.0
- name: Send status to Discord
uses: nebularg/actions-discord-webhook@v1
with:
webhook_url: ${{ secrets.DISCORD_WEBHOOK }} # required
status: ${{ job.status }} # optional, this is the default
if: always() # or failure() or success()