-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (113 loc) · 4.3 KB
/
cd-dev.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
name: CD - Deploy to Production Server
on:
push:
branches: [ "dev" ] # main 브랜치 푸시 시 실행
# flow에서 사용할 변수
env:
AWS_REGION: ap-northeast-2
S3_BUCKET_NAME: meerket-bucket
CODE_DEPLOY_APPLICATION_NAME: meerket-dev
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: meerket-deployment-group
permissions: write-all
#여기서부터 build job
jobs:
build:
runs-on: ubuntu-latest
environment: production
steps:
# 1) 기본 체크아웃
- name: Checkout
uses: actions/checkout@v4
# 2) JDK 17 셋팅
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
# 2.5) secret설정한 env 등록
- name: Create .env file from Secret
run: |
echo "${{ secrets.ENV_PROD}}" | base64 --decode > .env
# # 4) gradle 테스트 빌드
# - name: Build Test with Gradle
# run: ./gradlew test -i
# # run: ./gradlew clean build -i
# # working-directory: ${{ env.working-directory }}
# 3) gradlew 권한 설정
- name: Grant execute permission for gradlew
run: chmod +x ./meerket/gradlew # gradlew에 실행 권한 부여
- name: Build with Gradle
working-directory: ./meerket
run: |
echo "Setting execute permission for gradlew"
chmod +x ./gradlew
echo "Cleaning and building the project"
./gradlew clean build -x test --no-daemon --info
echo "Verifying JAR file generation..."
if [ -f ./meerket-application/build/libs/meerket-application-0.0.1.jar ]; then
echo "JAR file generated successfully!"
else
echo "JAR file not found! Please check the build configuration."
exit 1
fi
# 여기서부터 배포 job
deploy:
name: deploy
runs-on: ubuntu-latest
environment: production
needs: [ build ] # test와 build 작업이 성공적으로 완료된 경우에만 실행
steps:
# 1) 기본 체크아웃
- name: Checkout
uses: actions/checkout@v3
# 2) JDK 17 셋팅
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# 2.5) secret설정한 env 등록
- name: Create .env file from Secret
run: |
echo "${{ secrets.ENV_PROD }}" | base64 --decode > .env
# 2.5) secret 설정한 firesbase json key 등록
- name: create-json
uses: jsdaniell/[email protected]
with:
name: "meerket-83e38-firebase-adminsdk-gyt9i-d2df62fdf4.json"
json: ${{secrets.FIREBASE_SERVICE_KEY }}
dir: './meerket/meerket-application/src/main/resources'
# 3) gradlew 권한 설정
- name: Grant execute permission for gradlew
run: chmod +x ./meerket/gradlew # gradlew에 실행 권한 부여
# 4) gradle 테스트 빌드
- name: Build with Gradle
run: ./meerket/gradlew clean build -x test -i
# run: ./gradlew clean build -i
# working-directory: ${{ env.working-directory }}
# AWS 인증
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_DEV }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }}
aws-region: ${{ env.AWS_REGION }}
# AWS S3에 업로드
- name: Upload to AWS S3
run: |
cd meerket
aws deploy push \
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \
--ignore-hidden-files \
--s3-location s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip \
--source .
echo "S3 Upload completed. Verifying contents in S3..."
aws s3 ls s3://meerket-bucket/
# AWS EC2에 Deploy
- name: Deploy to AWS EC2 from S3
run: |
aws deploy create-deployment \
--application-name ${{ env.CODE_DEPLOY_APPLICATION_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