-
Notifications
You must be signed in to change notification settings - Fork 5
80 lines (70 loc) · 3.12 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
71
72
73
74
75
76
77
78
79
80
name: Build and Deploy to EC2
# 워크플로우가 언제 실행될 것인지 조건 명시
on:
push:
branches: [ "weekly/11"]
pull_request:
# branches: [ "Master" ]
types: [closed]
# AWS 관련 값 변수로 설정
env:
AWS_REGION: ap-northeast-2
AWS_S3_BUCKET: devcard-deploy-bucket
AWS_CODE_DEPLOY_APPLICATION: Devcard-Application-CD
AWS_CODE_DEPLOY_GROUP: Devcard-Deployment-Group
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
# JDK 17 설치
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
# 개별 환경 변수를 사용하여 application-secret.properties 파일 생성
- name: make application-secret.properties
run: |
mkdir -p ./src/main/resources
cd ./src/main/resources
touch ./application-secret.properties
echo "kakao.javascript.key=${{ secrets.KAKAO_JAVASCRIPT_KEY }}" >> ./application-secret.properties
echo "GITHUB_CLIENT_ID=${{ secrets.GH_CLIENT_ID }}" >> ./application-secret.properties
echo "GITHUB_CLIENT_SECRET=${{ secrets.GH_CLIENT_SECRET }}" >> ./application-secret.properties
echo "GITHUB_REDIRECT_URI=${{ secrets.GH_REDIRECT_URI }}" >> ./application-secret.properties
echo "DB_USERNAME=${{ secrets.DB_USERNAME }}" >> ./application-secret.properties
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> ./application-secret.properties
- name: Check environment variables
run: |
echo "AWS_REGION: ${{ env.AWS_REGION }}"
echo "AWS_S3_BUCKET: ${{ env.AWS_S3_BUCKET }}"
echo "AWS_CODE_DEPLOY_APPLICATION: ${{ env.AWS_CODE_DEPLOY_APPLICATION }}"
echo "AWS_CODE_DEPLOY_GROUP: ${{ env.AWS_CODE_DEPLOY_GROUP }}"
echo "DATABASE_URL: ${{ secrets.DATABASE_URL }}"
# 권한 부여
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash
- name: Build and Test
run: ./gradlew build test --info
# 빌드 파일을 zip 형식으로 압축
- name: Make zip file
run: zip -r ./$GITHUB_SHA.zip .
shell: bash
# AWS 권한
- name: AWS credential 설정
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: ${{ env.AWS_REGION }}
aws-access-key-id: ${{ secrets.CICD_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.CICD_SECRET_KEY }}
# S3 버킷에 빌드파일(zip 파일)을 업로드
- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$AWS_S3_BUCKET/$GITHUB_SHA.zip
# EC2 인스턴스에 S3에 저장되어 있던 zip 파일을 받아와 배포 시작
- name: EC2에 배포
run: aws deploy create-deployment --application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name ${{ env.AWS_CODE_DEPLOY_GROUP }} --s3-location bucket=$AWS_S3_BUCKET,key=$GITHUB_SHA.zip,bundleType=zip