-
Notifications
You must be signed in to change notification settings - Fork 1
92 lines (76 loc) · 2.79 KB
/
CICD.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
# workflow의 이름
name: CICD
# 해당 workflow가 언제 실행될 것인지에 대한 트리거를 지정
on:
push:
branches: [ "main", "dev" ] # master branch로 push 될 때 실행
pull_request:
branches: [ "main", "dev" ] # master branch로 pull request될 때 실행
env:
PROJECT_NAME: nabi
BUCKET_NAME: team-01-bucket
CODE_DEPLOY_APP_NAME: team01-codedeploy
DEPLOYMENT_GROUP_NAME: team01-instance-group
permissions:
contents: read
# workflow는 한개 이상의 job을 가지며, 각 job은 여러 step에 따라 단계를 나눌 수 있음
jobs:
build:
name: CI
# 해당 jobs에서 아래의 steps들이 어떠한 환경에서 실행될 것인지를 지정
runs-on: ubuntu-20.04
steps:
# 작업에서 액세스할 수 있도록 $GITHUB_WORKSPACE에서 저장소를 체크아웃
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# application.properties를 프로젝트에 포함
- name: Make application.properties
run: |
cd ./src/main/resources
touch ./application.properties
echo "${{ secrets.DATABASE_PROPERTIES }}" >> ./application.properties
shell: bash
- name: Setup MySQL
uses: samin/[email protected]
with:
host port: 3306
container port: 3306
mysql database: 'nabi'
mysql user: 'test'
mysql password: ${{ secrets.MYSQL_PASSWORD }}
# gradle 권한 설정
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash
- name: Test with Gradle
run: ./gradlew test
# 빌드
- name: Build with Gradle
run: ./gradlew build
shell: bash
- name: Make zip file
run: zip -r ./$GITHUB_SHA.zip .
shell: bash
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.SECRET_KEY }}
aws-region: ap-northeast-2
# script files 복사
- name: Copy script
run: cp ./scripts/*.sh ./deploy
# S3에 빌드 결과 업로드
- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip
# Deploy 실행
- name: Code Deploy To EC2 instance
run: aws deploy create-deployment
--application-name $CODE_DEPLOY_APP_NAME
--deployment-config-name CodeDeployDefault.AllAtOnce
--deployment-group-name $DEPLOYMENT_GROUP_NAME
--s3-location bucket=$BUCKET_NAME,bundleType=zip,key=$PROJECT_NAME/$GITHUB_SHA.zip