-
Notifications
You must be signed in to change notification settings - Fork 3
168 lines (147 loc) · 6.24 KB
/
deployment-and-code-coverage-workflow.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: Continuous Delivery & Jacoco CodeCoverage
on:
push:
branches: [main]
paths:
- "java/src/main/**/*"
- "java/src/test/**/*"
- "java/**/build.gradle*"
- "java/**/settings.gradle*"
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
docker_build_and_deploy_to_ec2:
runs-on: ubuntu-latest
outputs:
codecov: ${{ steps.test_changes.outputs.codecov }}
defaults:
run:
working-directory: java
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: "17"
distribution: "corretto"
- name: Configure Application Secrets
run: |
echo "${{ secrets.APPLICATION_YML }}" | base64 --decode > src/main/resources/application-secret.yml
echo "${{ secrets.APPLICATION_TEST_YML }}" | base64 --decode > src/main/resources/application-secret-github.yml
echo "${{ secrets.LOGBACK_TEST }}" | base64 --decode > src/test/resources/logback-test.xml
echo "${{ secrets.LOGSTASH_CONF }}" | base64 --decode > logstash/pipeline/spring-boot-logs.conf
echo "${{ secrets.REDIS_CONF }}" | base64 --decode > redis/redis.conf
echo "${{ secrets.DOCKER_PYTHON }}" | base64 --decode > python.env
echo "${{ secrets.DOCKER_SPRING }}" | base64 --decode > spring.env
echo "${{ secrets.DOCKER_REDIS }}" | base64 --decode > redis.env
echo "${{ secrets.DOCKER_GOOGLE }}" | base64 --decode > google-beautyminder.json
- name: Make Gradle Wrapper Executable
run: chmod +x gradlew
- name: Gradle Build and Package
run: ./gradlew clean bootJar build -x test
- name: Docker Image Build and Local Deployment
run: |
cp Dockerfile.spring build/libs/
cp google-beautyminder.json build/libs/
cp Dockerfile.python python/
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker compose -f ELK.yml up --build -d
- name: Push Docker Images to Registry
run: |
docker ps
docker tag java-spring-boot ${{ secrets.DOCKER_USERNAME }}/beautyminder-spring:latest
docker tag java-python-fastapi ${{ secrets.DOCKER_USERNAME }}/beautyminder-fastapi:latest
docker push ${{ secrets.DOCKER_USERNAME }}/beautyminder-spring:latest
docker push ${{ secrets.DOCKER_USERNAME }}/beautyminder-fastapi:latest
- name: Deploy Docker Containers to EC2
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC_HOST }}
username: ${{ secrets.EC_USERNAME }}
password: ${{ secrets.EC_PASSWORD }}
passphrase: ${{ secrets.EC_PASSPHRASE }}
key: ${{ secrets.EC_PRIVATE_KEY }}
script: |
whoami
cd beautyminder
docker compose -f ELK-hub.yml pull
docker compose -f ELK-hub.yml build --no-cache
docker compose -f ELK-hub.yml up --build --force-recreate -d
- name: Send KakaoTalk notification of Docker success
uses: Alfex4936/kakaotalk-ci-action@main
if: success()
continue-on-error: true
with:
kakao_access_token: ${{ secrets.KAKAO_ACCESS_TOKEN }}
function_name: send_to_me_custom
template_id: "101722"
template_args: '{"title": "EC2 도커 빌드 완료", "description": "Github Action에서 EC2 빌드를 완료하였습니다."}'
- name: Check for Test Changes
id: test_changes
uses: dorny/paths-filter@v2
with:
list-files: shell
filters: |
codecov:
- 'java/src/test/**/*'
jacoco_codecov:
runs-on: ubuntu-latest
needs: docker_build_and_deploy_to_ec2
if: ${{ needs.docker_build_and_deploy_to_ec2.outputs.codecov == 'true' }}
defaults:
run:
working-directory: java
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: "17"
distribution: "corretto"
- name: Setup secrets
run: |
echo "${{ secrets.APPLICATION_YML }}" | base64 --decode > src/main/resources/application-secret.yml
echo "${{ secrets.APPLICATION_TEST_YML }}" | base64 --decode > src/main/resources/application-secret-github.yml
echo "${{ secrets.LOGBACK_TEST }}" | base64 --decode > src/test/resources/logback-test.xml
echo "${{ secrets.DOCKER_PYTHON }}" | base64 --decode > python.env
echo "${{ secrets.DOCKER_SPRING }}" | base64 --decode > spring.env
echo "${{ secrets.DOCKER_REDIS }}" | base64 --decode > redis.env
echo "${{ secrets.DOCKER_GOOGLE }}" | base64 --decode > google-beautyminder.json
echo "GOOGLE_APPLICATION_CREDENTIALS=${GITHUB_WORKSPACE}/java/google-beautyminder.json" >> "$GITHUB_ENV"
echo "LOGSTASH_HOST=${{ secrets.EC_HOST }}" >> "$GITHUB_ENV"
- name: Correct permission
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build -x test
- name: Run JacocoTest
uses: nick-fields/retry@v2
with:
timeout_minutes: 10
max_attempts: 2
command: |
cd ${GITHUB_WORKSPACE}/java
./gradlew clean test jacocoTestReport
# - name: Run JacocoTest
# run: ./gradlew clean test jacocoTestReport
# continue-on-error: true
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: build/reports/jacoco/test/jacocoTestReport.xml
fail_ci_if_error: true
- name: Send KakaoTalk notification of CodeCov success
uses: Alfex4936/kakaotalk-ci-action@main
if: success()
continue-on-error: true
with:
kakao_access_token: ${{ secrets.KAKAO_ACCESS_TOKEN }}
function_name: send_to_me_custom
template_id: "101722"
template_args: '{"title": "Jacoco 테스트 완료", "description": "Github Action에서 코드 커버리지를 완료했습니다."}'