-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (134 loc) · 5.13 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Project CI/CD
# < CI/CD 이전에 먼저 호출해야만 하는 목록 - postdeploy chmod 권한 부여 & submodule 최신화 >
# chmod +x .platform/hooks/postdeploy/connect_spring_to_network.sh
# git submodule update --remote
# git add .
# git commit -m "[#이슈번호] Setting: Git Submodule 최신화"
# git push
on:
pull_request:
types: [ closed ] # Pull Request가 닫힐 때만 트리거됨
workflow_dispatch: # Github UI 수동 실행도 가능
jobs:
deploy:
runs-on: ubuntu-latest
# 닫힌 Pull Request가 실제로 merge 되었을때 && Pull Request가 develop 브랜치로 merge 되는 방향일때
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop'
steps:
### Set Up ###
- name: Checkout
uses: actions/checkout@v2
with:
token: ${{ secrets.SUBMODULE_GITHUB_TOKEN }}
submodules: true
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'adopt'
### Gradle ###
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
### Docker ###
- name: Docker build
run: |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
docker build -t devrace-image .
docker tag devrace-image sahyunjin/devrace-image:latest
docker push sahyunjin/devrace-image:latest
### Time ###
- name: Get Current Time
uses: 1466587594/get-current-time@v2
id: current-ksttime
with:
format: YYYY-MM-DDTHH:mm:ss
utcOffset: "+09:00" # KST time = UTC time + 9hour
### ZIP file ###
- name: Generate deployment package
run: |
mkdir -p deploy
mkdir -p deploy/.platform/hooks/postdeploy
cp -r .ebextensions deploy/.ebextensions
cp Dockerrun.aws.json deploy/Dockerrun.aws.json
cp .platform/hooks/postdeploy/connect_spring_to_network.sh deploy/.platform/hooks/postdeploy/connect_spring_to_network.sh
cd deploy && zip -r deploy.zip .
### AWS Elastic Beanstalk ###
- name: Beanstalk Deploy
uses: einaregilsson/beanstalk-deploy@v20
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: devrace-app
environment_name: Devrace-env
version_label: "github-action--${{ steps.current-ksttime.outputs.formattedTime }}"
region: ap-northeast-2
deployment_package: deploy/deploy.zip
wait_for_deployment: false
### Slack Alarm for success deploy ###
- name: Notify Slack on Success
if: success()
id: slack-success
uses: slackapi/[email protected]
with:
payload: |
{
"channel": "C06FGQEQ1CP",
"attachments": [
{
"color": "#36a64f",
"title": ":white_check_mark: Success CI/CD",
"title_link": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"text": "'${{ github.event.pull_request.user.login }}'의 배포가 성공했습니다.",
"fields": [
{
"title": "Repository",
"value": "${{ github.repository }}",
"short": true
},
{
"title": "Branch",
"value": "${{ github.event.pull_request.head.ref }}",
"short": true
}
]
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
### Slack Alarm for fail deploy ###
- name: Notify Slack on Failure
if: failure()
id: slack-failure
uses: slackapi/[email protected]
with:
payload: |
{
"channel": "C06FGQEQ1CP",
"attachments": [
{
"color": "#ff0000",
"title": ":x: Fail CI/CD",
"title_link": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"text": "'${{ github.event.pull_request.user.login }}'의 배포가 실패했습니다.",
"fields": [
{
"title": "Repository",
"value": "${{ github.repository }}",
"short": true
},
{
"title": "Branch",
"value": "${{ github.event.pull_request.head.ref }}",
"short": true
}
]
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK