Skip to content

Commit

Permalink
fix : 실패시 디스코드 알림 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
SolfE committed Sep 26, 2024
1 parent 56973eb commit 3bf9c0d
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/main-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,100 @@ jobs:
name: Send notification
needs: [build, deploy]
runs-on: ubuntu-latest
steps:
- name: Send Discord notificaname: Deploy to AWS ECS

on:
push:
branches: [ "main", "feat/CICD" ]

jobs:
build:
name: Build and push Docker image
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'

- name: Set yml file
uses: microsoft/variable-substitution@v1
with:
files: ./src/main/resources/application-prod.yml
env:
spring.datasource.url: ${{ secrets.MYSQL_URL }}
spring.datasource.username: ${{ secrets.MYSQL_USERNAME }}
spring.datasource.password: ${{ secrets.MYSQL_PASSWORD }}

- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew clean build -x test
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build Docker image
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/server:latest .

- name: Push Docker image to Docker Hub
run: docker push ${{ secrets.DOCKER_USERNAME }}/server:latest

deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
steps:
- name: executing remote ssh commands using ssh key
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/server:latest
if [ "$(docker ps -aq -f name=server)" ]
then
echo "[ spring is running ]"
docker stop server
docker rm server
else
echo "[ spring is not running ]"
fi
docker run -d --name server -p 80:8080 ${{ secrets.DOCKER_USERNAME }}/server
result:
name: Send notification
needs: [build, deploy]
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Send Discord notification on success
if: ${{ needs.build.result == 'success' && needs.deploy.result == 'success' }}
run: |
curl -X POST -H "Content-Type: application/json" -d '{"content": "✅ : Deployment to AWS ECS was successful!"}' ${{ secrets.DISCORD_WEBHOOK_URL }}
- name: Send Discord notification on failure
if: ${{ needs.build.result != 'success' || needs.deploy.result != 'success' }}
run: |
curl -X POST -H "Content-Type: application/json" -d '{"content": "❌ : Deployment to AWS ECS failed!"}' ${{ secrets.DISCORD_WEBHOOK_URL }}tion on success
if: ${{ needs.build.result == 'success' && needs.deploy.result == 'success' }}
run: |
curl -X POST -H "Content-Type: application/json" -d '{"content": "✅ : Deployment to AWS ECS was successful!"}' ${{ secrets.DISCORD_WEBHOOK_URL }}
- name: Send Discord notification on failure
if: ${{ needs.build.result != 'success' || needs.deploy.result != 'success' }}
run: |
Expand Down

0 comments on commit 3bf9c0d

Please sign in to comment.