forked from function-implementation-only/Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (137 loc) · 5.59 KB
/
gradle.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
# This workflow will build a Java project with Gradle
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
# Repo Action 페이지에 나타날 이름
name: Spring Boot & Gradle CI/CD
# Event Trigger
# master branch에 push 또는 pull request가 발생할 경우 동작
# branch 단위 외에도, tag나 cron 식 등을 사용할 수 있음
on:
push:
branches:
- prod/main-service
- prod/chat-service
jobs:
build:
# 실행 환경 지정
runs-on: ubuntu-latest
# Task의 sequence를 명시한다.
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
# main-service
- name: Grant execute permission for gradlew
if: contains(github.ref, 'prod/main-service')
run: |
cd ./main-service
chmod +x gradlew
# properties
- name: make application-cicd.properties
if: contains(github.ref, 'prod/main-service')
run: |
echo "ls -a . & pwd"
pwd
ls -a .
echo "mkdir & touch"
mkdir -p ./main-service/src/main/resources
cd ./main-service/src/main/resources
touch ./application-cicd.properties
pwd
ls -a .
echo "copy properties"
echo $jasypt_encryptor_password >> ./application-cicd.properties
echo $slack_webhook_uri >> ./application-cicd.properties
cat application-cicd.properties
env:
jasypt_encryptor_password: ${{ secrets.JASYPT_ENCRYPTOR_PASSWORD }}
slack_webhook_uri: ${{ secrets.SLACK_WEBHOOK_URI }}
# build
- name: Build with Gradle
if: contains(github.ref, 'prod/main-service')
run: |
cd ./main-service
./gradlew clean build
# docker build & push to production
- name: Docker build & push to prod
if: contains(github.ref, 'prod/main-service')
run: |
cd ./main-service
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build --tag ${{ secrets.DOCKER_USERNAME }}/main-service .
docker push ${{ secrets.DOCKER_USERNAME }}/main-service
# deploy to production
- name: Deploy to prod
uses: appleboy/ssh-action@master
id: deploy-prod-main-service
if: contains(github.ref, 'prod/main-service')
with:
host: ${{ secrets.EC2_IP }}
username: ubuntu
password: ${{ secrets.EC2_PASSWORD }}
port: 22
script: |
sudo docker rm -f $(docker container rm -f main-service)
docker image prune -f -a
docker run -d --network joinus-network --name main-service -e "spring.cloud.config.uri=http://config-service:8888" -e "spring.rabbitmq.host=rabbitmq" -e "eureka.client.serviceUrl.defaultZone=http://discovery-service:8761/eureka/" -e "logging.file=/api-logs/users-ws.log" -e "spring.zipkin.base-url=http://zipkin:9411" refinedstone/main-service
# main-service
- name: Grant execute permission for gradlew
if: contains(github.ref, 'prod/main-service')
run: |
cd ./main-service
chmod +x gradlew
## chat-service
## auth
- name: Grant execute permission for gradlew
if: contains(github.ref, 'prod/chat-service')
run: |
cd ./chat-service
chmod +x gradlew
# properties
- name: make application-cicd.properties
if: contains(github.ref, 'prod/chat-service')
run: |
echo "ls -a . & pwd"
pwd
ls -a .
echo "mkdir & touch"
mkdir -p ./chat-service/src/main/resources
cd ./chat-service/src/main/resources
touch ./application-cicd.properties
pwd
ls -a .
echo "copy properties"
echo $jasypt_encryptor_password >> ./application-cicd.properties
echo $slack_webhook_uri >> ./application-cicd.properties
cat application-cicd.properties
env:
jasypt_encryptor_password: ${{ secrets.JASYPT_ENCRYPTOR_PASSWORD }}
slack_webhook_uri: ${{ secrets.SLACK_WEBHOOK_URI }}
- name: Build with Gradle
if: contains(github.ref, 'prod/chat-service')
run: |
cd ./chat-service
./gradlew clean build
## docker build & push to production
- name: Docker build & push to prod
if: contains(github.ref, 'prod/chat-service')
run: |
cd ./chat-service
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build --tag ${{ secrets.DOCKER_USERNAME }}/chat-service .
docker push ${{ secrets.DOCKER_USERNAME }}/chat-service
## deploy to production
- name: Deploy to prod
uses: appleboy/ssh-action@master
id: deploy-prod-chat-service
if: contains(github.ref, 'prod/chat-service')
with:
host: ${{ secrets.EC2_IP }}
username: ubuntu
password: ${{ secrets.EC2_PASSWORD }}
port: 22
script: |
sudo docker rm -f $(docker container rm -f chat-service)
docker image prune -f -a
docker run -d --network joinus-network --name chat-service -e "spring.cloud.config.uri=http://config-service:8888" -e "spring.zipkin.base-url=http://zipkin:9411" -e "spring.rabbitmq.host=rabbitmq" -e "eureka.client.serviceUrl.defaultZone=http://discovery-service:8761/eureka/" -e "logging.file=/api-logs/users-ws.log" refinedstone/chat-service