feat: 데모데이용 알림 설정 (#18) #28
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ShowPot-Dev-CD | |
on: | |
push: | |
branches: | |
- develop | |
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/domain/common-domain/src/main/resources/application-domain-dev.yml, | |
./app/infrastructure/fcm/src/main/resources/application-fcm-dev.yml | |
env: | |
spring.datasource.url: ${{ secrets.APPLICATION_DATASOURCE_URL_DEV }} | |
spring.datasource.username: ${{ secrets.APPLICATION_DATASOURCE_USERNAME }} | |
spring.datasource.password: ${{ secrets.APPLICATION_DATASOURCE_PASSWORD }} | |
fcm.project_id: ${{ secrets.FCM_PROJECT_ID }} | |
fcm.private_key_id: ${{ secrets.FCM_PRIVATE_KEY_ID }} | |
fcm.private_key: ${{ secrets.FCM_PRIVATE_KEY }} | |
fcm.client_email: ${{ secrets.FCM_CLIENT_EMAIL }} | |
fcm.client_id: ${{ secrets.FCM_CLIENT_ID }} | |
- name: Build with Gradle Wrapper | |
run: ./gradlew clean build -Dspring.profiles.active=dev | |
- name: Prepare File for Deployment | |
run: | | |
mkdir -p deployment-alarm/app/build/libs | |
cp dockerfile-alarm-dev docker-compose-alarm-dev.yml deployment-alarm/ | |
cp -r ./app/build/libs deployment-alarm/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-alarm/*" | |
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-alarm/ | |
docker-compose -f docker-compose-alarm-dev.yml down | |
docker system prune -f | |
docker-compose -f docker-compose-alarm-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 }} |