-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (120 loc) · 4.2 KB
/
jib-build-depoly.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
name: NumberOne-Backend-JIB-BUILD-DEPLOY
# event trigger
on:
push:
branches: [ "dev", "dev-check", "feat/multi-module" ]
permissions: write-all
jobs:
build:
runs-on: ubuntu-latest
steps:
## jdk setting
- uses: actions/checkout@v3
- name: 🧱 Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin' # https://github.com/actions/setup-java
## gradle caching
- 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: get Current Time
run: echo "CURRENT_TIME=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV
- name: 🔔 Send Slack Message when deploy started
uses: 8398a7/action-slack@v3
with:
status: custom
custom_payload: |
{
"attachments": [
{
"title": "대피로 백엔드 배포를 시작합니다. 👻",
"pretext": "Daepiro backend is deploying...",
"fields": [
{
"title": "Author 💻",
"value": "${{ github.actor }}",
"short": true
},
{
"title": "Deploy time 🕚",
"value": "${{ env.CURRENT_TIME }}",
"short": true
}
]
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()
- name: 🔑 Login to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: 🐧 create application.yml
run: |
mkdir -p ./daepiro-app/src/main/resources
cd ./daepiro-app/src/main/resources
touch ./application.yml
echo "${{ secrets.PROPERTIES_PROD }}" | base64 --decode > ./application.yml
ls -la
shell: bash
- name: 🐧 create service-account.json
run: |
cd ./daepiro-api/src/main/resources
touch ./service-account.json
echo "${{ secrets.FCM }}" | base64 --decode > ./service-account.json
ls -la
shell: bash
- name: Build with jib
run: |
./gradlew :daepiro-app:jib -x test \
-Djib.to.auth.username=${{ secrets.DOCKER_USERNAME }} \
-Djib.to.auth.password=${{ secrets.DOCKER_PASSWORD }} \
-Djib.to.image="${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }}:latest"
env:
EC2_PUBLIC_IP: ${{ secrets.EC2_PUBLIC_IP }}
JMX_PORT: ${{ secrets.JMX_PORT }}
- name: Get current time
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00"
- name: Show Current Time
run: echo "CurrentTime=${{steps.current-time.outputs.formattedTime}}"
shell: bash
## deploy to production
- name: 🌿 Deploy
uses: appleboy/ssh-action@master
id: deploy-prod
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
sudo docker rm -f $(docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }}:latest
docker-compose up -d
docker image prune -f
## notify at Slack
- name: 🔔 Send Slack Message
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo, message, commit, author, workflow
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()