-
Notifications
You must be signed in to change notification settings - Fork 4
70 lines (57 loc) · 2.03 KB
/
main.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
name: Build and Deploy to EC2
on:
push:
branches: [ "dev" ]
workflow_dispatch:
env:
AWS_REGION: ap-northeast-2
S3_BUCKET_NAME: itpick-cicd-bucket
PROJECT_NAME: IT-Pick-Backend
CODE_DEPLOY_APPLICATION_NAME: itpick_cicd
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: itpick_instance
RESOURCE_PATH: ${{ secrets.RESOURCE_PATH }}
jobs:
build-project:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
# 체크아웃
- name: checkout release
uses: actions/checkout@v4
# JDK 17 세팅
- name: set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
# gradlew 권한 설정
- name: Make gradlew executable
run: chmod +x ./gradlew
# Build Gradle
- name: Build with Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5
with:
arguments: clean build -x test
# zip 파일 생성
- name: Make zip file
run: zip -qq -r ./$GITHUB_SHA.zip .
# AWS 인증
- name: AWS configure 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 s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip
- name: deploy with AWS codeDeploy
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=${{ env.S3_BUCKET_NAME }},key=${{ env.PROJECT_NAME }}/$GITHUB_SHA.zip,bundleType=zip
- name: Test AWS credentials
run: aws s3 ls