Skip to content

Commit

Permalink
add workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
ashee022 committed Sep 17, 2023
1 parent 1e8f768 commit 530e585
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Empty file removed .github/workflows
Empty file.
47 changes: 47 additions & 0 deletions .github/workflows/docker_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Docker Deploy to EC2

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

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

- name: Deploy Docker on EC2
env:
PRIVATE_KEY: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
run: |
echo "$PRIVATE_KEY" > private_key.pem
chmod 600 private_key.pem
scp -i private_key.pem -r * [email protected]:/home/ubuntu/DataFetcher/
ssh -i private_key.pem [email protected] 'cd /home/ubuntu/DataFetcher/ && sudo docker stop buzzing_admin_container && sudo docker rm buzzing_admin_container && sudo docker build -t awsbuzzing_image . && sudo docker run -d -p 8081:8081 --name buzzing_admin_container awsbuzzing_image'
rm -f private_key.pem
- name: Health Check
run: |
for i in {1..5}; do
response=$(curl -o /dev/null -s -w "%{http_code}" http://3.34.147.253:8081/auth/admin/main/)
if [ "$response" -eq 200 ]; then
echo "Server is healthy."
exit 0
fi
echo "Check failed. Attempt: $i. Waiting for 10 seconds..."
sleep 10
done
echo "Server health check failed after 5 attempts."
exit 1
- name: Send Slack notification
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()

0 comments on commit 530e585

Please sign in to comment.