-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (96 loc) · 4.24 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
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: hero-alignlab-api CI/CD
# release 브랜치에 push 또는 pull request가 되면 스크립트 실행
on:
push:
branches: [ "main" ]
pull_request:
branches: [ main ]
# 해당 스크립트에서 사용될 환경 변수
env:
AWS_REGION: ap-northeast-2
PROJECT_NAME: hero-alignlab-api
S3_BUCKET_NAME: alignlab
CODE_DEPLOY_APP_NAME: hero-alignlab-api
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: hero-align-lab-deploy
permissions:
contents: read
jobs:
build:
# Github의 워크플로에서 실행될 OS 선택
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
# JDK 17, Corretto 17
- name: Set up Corretto JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# Secret Setup - application.yml
- name: Inject env-values to application.yml
uses: microsoft/variable-substitution@v1
with:
files: ./src/main/resources/config/application.yml
env:
# Aws Credentials 환경 변수 주입
cloud.aws.credentials.access-key: ${{ secrets.AWS_ACCESS_KEY_ID }}
cloud.aws.credentials.secret-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# Jwt Secret Key 환경 변수 주입
auth.jwt.secret: ${{ secrets.AUTH_JWT_SECRET }}
# Encrypt 환경 변수 주입
encrypt.key: ${{ secrets.ENCRYPT_KEY }}
encrypt.algorithm: ${{ secrets.ENCRYPT_ALGORITHM }}
# dev resource 환경 변수 주입
hero-alignlab.dev.resource.key: ${{ secrets.HERO_ALIGNLAB_DEV_RESOURCE_KEY }}
# OAuth-Kakao 환경 변수 주입
oauth.kakao.rest-api-key: ${{ secrets.OAUTH_KAKAO_REST_API_KEY }}
oauth.kakao.client-secret-code: ${{ secrets.OAUTH_KAKAO_CLIENT_SECRET_CODE }}
oauth.kakao.admin-key: ${{ secrets.OAUTH_KAKAO_ADMIN_KEY }}
# Secret Setup - application-prod.yml
- name: Inject env-values to application-prod.yml
uses: microsoft/variable-substitution@v1
with:
files: ./src/main/resources/config/application-prod.yml
env:
# Database 환경 변수 주입
hero.master.datasource.url: ${{ secrets.HERO_MASTER_DATASOURCE_URL }}
hero.master.datasource.username: ${{ secrets.HERO_MASTER_DATASOURCE_USERNAME }}
hero.master.datasource.password: ${{ secrets.HERO_MASTER_DATASOURCE_PASSWORD }}
# gradlew 파일 실행권한 설정
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash
# Gradle build (Test 제외)
- name: Build with Gradle
run: ./gradlew clean --stacktrace --info build
shell: bash
# AWS 인증 (IAM 사용자 Access Key, Secret Key 활용)
- 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 AWS S3
run: |
aws deploy push \
--application-name ${{ env.CODE_DEPLOY_APP_NAME }} \
--ignore-hidden-files \
--s3-location s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip \
--source .
# S3 버킷에 있는 파일을 대상으로 CodeDeploy 실행
- name: Deploy to AWS EC2 from S3
run: |
aws deploy create-deployment \
--application-name ${{ env.CODE_DEPLOY_APP_NAME }} \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \
--s3-location bucket=$S3_BUCKET_NAME,key=$GITHUB_SHA.zip,bundleType=zip