-
Notifications
You must be signed in to change notification settings - Fork 1
110 lines (95 loc) · 4.11 KB
/
showpot-dev-cd.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
name: ShowPot-Dev-CD
on:
push:
branches:
- develop
- hotfix/**
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'liberica'
cache: gradle
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: Copy Secrets
uses: microsoft/variable-substitution@v1
with:
files: './app/src/main/resources/application-dev.yml, ./app/src/main/resources/application-cloud-dev.yml, ./app/domain/common-domain/src/main/resources/application-domain-dev.yml'
env:
token.secret-key: ${{ secrets.TOKEN_SECRET_KEY }}
cloud.aws.credentials.accessKey: ${{ secrets.AWS_ACCESS_KEY }}
cloud.aws.credentials.secretKey: ${{ secrets.AWS_SECRET_KEY }}
cloud.aws.region: ${{ secrets.AWS_REGION }}
cloud.aws.s3.bucket: ${{ secrets.AWS_BUCKET }}
spring.datasource.url: ${{ secrets.APPLICATION_DATASOURCE_URL_DEV }}
spring.datasource.username: ${{ secrets.APPLICATION_DATASOURCE_USERNAME }}
spring.datasource.password: ${{ secrets.APPLICATION_DATASOURCE_PASSWORD }}
- name: Build with Gradle Wrapper
run: ./gradlew clean build -Dspring.profiles.active=dev
- name: Prepare File for Deployment
run: |
mkdir -p deployment/app/build/libs
cp dockerfile-dev docker-compose-dev.yml deployment/
cp -r ./app/build/libs deployment/app/build
- name: Get Github Actions IP
id: ip
uses: candidob/[email protected]
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ap-northeast-2
- name: Add Github Actions IP on Security Group
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_DEV_SECURITY_GROUP_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
- name: Upload files to EC2
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_DEV_HOST }}
username: ec2-user
key: ${{ secrets.EC2_DEV_SSH_PRIVATE_KEY }}
source: "deployment/*"
target: "/home/ec2-user/"
- name: Deploy using Docker Compose
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_DEV_HOST }}
username: ec2-user
key: ${{ secrets.EC2_DEV_SSH_PRIVATE_KEY }}
script: |
cd /home/ec2-user/deployment/
docker-compose -f docker-compose-dev.yml down
docker system prune -f
docker-compose -f docker-compose-dev.yml up -d --build
- name: Remove Github Actions IP from Security Group
if: always()
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_DEV_SECURITY_GROUP_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
- name: Backend CD for Dev Server Discord Notification
uses: sarisia/actions-status-discord@v1
if: success()
with:
title: ✅ 개발 서버 배포 프로세스가 완료되었습니다! ✅
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }}
content: "<@1084774841460215839> <@281597829636423682> 배포가 정상적으로 이뤄졌는지 확인해주세요!"
color: 00FF00
username: showPot-Bot
avatar_url: ${{ secrets.DISCORD_NOTIFICATION_SUCCESS_AVATAR_URL }}
- name: Backend CD for Dev Server Discord Notification
uses: sarisia/actions-status-discord@v1
if: failure()
with:
title: ❗️개발 서버 배포 프로세스가 실패했습니다! ❗️
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }}
color: FF0000
username: showPot-Bot
avatar_url: ${{ secrets.DISCORD_NOTIFICATION_FAILED_AVATAR_URL }}