-
Notifications
You must be signed in to change notification settings - Fork 1
90 lines (85 loc) · 3.15 KB
/
ci.cd.production.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
name: ci-cd
on:
push:
branches: [ main ]
pull_request:
types: [ labeled, opened, synchronize ]
permissions:
contents: read
env:
S3_BUCKET_NAME: fineants2024
AWS_REGION: ap-northeast-2
CODEDEPLOY_NAME: fineAnts
CODEDEPLOY_GROUP: production
jobs:
build-image:
runs-on: ubuntu-latest
environment: aws2024
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v3
with:
submodules: true
token: ${{ secrets.GIT_TOKEN }}
## JDK 설정
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# 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-
# gradlew 실행을 위해서 실행 권한을 부여
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
# Timezone 설정
- name: Set timezone to Asia/Seoul
run: |
sudo timedatectl set-timezone Asia/Seoul
# 'no test' label 존재하는지 확인
- name: Determine if "no test" label is present
id: check-label
run: |
if [[ "$(jq -r '.pull_request.labels[]?.name' $GITHUB_EVENT_PATH | grep -c 'no test')" -gt 0 ]]; then
echo "::set-output name=no_test::true"
else
echo "::set-output name=no_test::false"
fi
# Gradle을 이용하여 빌드 수행
- name: Build without tests if "no test" label is present
run: |
if [ "${{ steps.check-label.outputs.no_test }}" == "true" ]; then
./gradlew bootJar -x test
else
./gradlew bootJar
fi
# zip 파일 생성
- name: Make zip file
run: zip -r ./$GITHUB_SHA.zip .
# AWS 인증정보 설정
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
# S3에 업로드
- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME/deploy/production/$GITHUB_SHA.zip
# 코드 배포
- name: Code Deploy
run: aws deploy create-deployment --application-name $CODEDEPLOY_NAME --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name $CODEDEPLOY_GROUP --s3-location bucket=$S3_BUCKET_NAME,bundleType=zip,key=deploy/production/$GITHUB_SHA.zip