Skip to content

Merge pull request #2 from Akatsuki-USW/develop #1

Merge pull request #2 from Akatsuki-USW/develop

Merge pull request #2 from Akatsuki-USW/develop #1

Workflow file for this run

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()