Skip to content

Commit

Permalink
new idea part #3
Browse files Browse the repository at this point in the history
  • Loading branch information
parhamrahmani committed May 27, 2024
1 parent c878a0b commit 47c0717
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/deploy-to-ec2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ jobs:
aws autoscaling describe-auto-scaling-instances --query "AutoScalingInstances[*].InstanceId" --output text > autoscaling_instance_ids.txt
aws ec2 describe-instances --instance-ids $(cat autoscaling_instance_ids.txt) --query "Reservations[*].Instances[*].PublicIpAddress" --output text > autoscaling_instance_ips.txt
cat autoscaling_instance_ips.txt
<< EOF
ips_file="autoscaling_instance_ips.txt"
IFS=$'\n' read -d '' -r -a ips < "$ips_file"
for i in "${!ips[@]}"; do
Expand All @@ -114,14 +113,22 @@ jobs:
chmod +x update_instance_$((i+1)).sh
# show the content of the new file
cat update_instance_$((i+1)).sh
done
- name: Update Autoscaling EC2 with new Docker image
run: |
cat autoscaling_instance_ips.txt
ips_file="autoscaling_instance_ips.txt"
IFS=$'\n' read -d '' -r -a ips < "$ips_file"
for i in "${!ips[@]}"; do
ssh -o StrictHostKeyChecking=no -i /home/runner/.ssh/id_rsa ubuntu@${ips[i]} << 'EOF'
docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/flask-app-image-repository:latest
docker stop my-container || true
docker rm my-container || true
docker run -d --name my-container -p 80:5000 ${{ secrets.DOCKER_HUB_USERNAME }}/flask-app-image-repository:latest
EOF
done
env:
Expand Down

0 comments on commit 47c0717

Please sign in to comment.