Merge pull request #4 from Akatsuki-USW/develop #2
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: 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: Add EC2 to SSH known hosts | |
run: | | |
echo '3.34.147.253 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBGlJ0+sDok0Up66RDn3+5WsBmupvBL14zUBx7CJwULOd2qU65kFE2MEj5u93SriS5LjwZ5DqHGBdkNKl/VGEX3g=' >> ~/.ssh/known_hosts | |
echo '3.34.147.253 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCywcdLiX3GJ6ZpAKchKuEsNTeiWnFe9FJqrZCbOE4g6/M2VdwlusMGQDIA1l+V500qQbiSms6vKnRaSKiDLnVM8fz9H93pNHQ+XTbfy9DPALyOlRBDXKvoR4APqiRjXh6/3HmBPptV6VR/fREuv1+fwnA84uIxWlCZgcLYWe8NUVqjfldlVwUOqOe+c0jcl4OHE8Les2M0i8x6qr9gjnpEXOuYcg4GxGup8UEimRBaTikjUM6MPCNEYGqMiGHzhiDhAHzicQTmgs2lpotHfcScohBXDI8VI/5utumTiHdxr4cC71CVKiVJE9ZO5+mQU0DM1w/3H34OGyftrvV4HexgjcWE0j0+i1NGWxQDWrEXpyK7i6eITTY12tDstgaGiq5tVBnMC6jye8dech8UH8U60Pdg8GSCwO7fXHvJwHS2q+/ARenTyAQVgY3XU2XDxsxDsdNZcOKihWkXv5sO/TY7SaMN6iIdB16+quI+/gU4S9b+GXcItnuxsDh36J1hdBc=' >> ~/.ssh/known_hosts | |
echo '3.34.147.253 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOeYq1i/ezJq/+q3B4iebrc/q4gr2qxINUtQx33Ve7ym' >> ~/.ssh/known_hosts | |
- 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() |