mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 14:55:50 +00:00
Remove unessasary source command + typo fix + SSH commands for pulling and running docker image
This commit is contained in:
parent
bba363e933
commit
fc01f1aa31
1 changed files with 26 additions and 7 deletions
|
@ -3,12 +3,11 @@
|
|||
# This script sets authenthicates and pulls docker image. Then runs it on host
|
||||
|
||||
# Global data
|
||||
source ./send_image_to_aws.sh
|
||||
|
||||
IMAGE_NAME="$ECR_NAME:latest"
|
||||
FULL_KEY_PATH=""
|
||||
|
||||
read -p "Enter your AWS Key absoluet path: " FULL_KEY_PATH
|
||||
read -p "Enter your AWS Key absolute path: " FULL_KEY_PATH
|
||||
|
||||
# Get the public IP of EC2 instance from previus script
|
||||
echo "Getting public IP address of EC2 instance..."
|
||||
|
@ -34,11 +33,31 @@ fi
|
|||
# SSH to EC2 and run instance
|
||||
echo "SSH-ing to EC2 instance and running Docker image from ECR..."
|
||||
ssh -i "$FULL_KEY_PATH" ec2-user@"$PUBLIC_IP" <<EOF
|
||||
docker pull "$IMAGE_NAME"
|
||||
docker run -d -p 80:8080 "$IMAGE_NAME"
|
||||
# Ensure Docker is installed and running
|
||||
sudo yum update -y
|
||||
sudo yum install -y docker
|
||||
sudo service docker start
|
||||
|
||||
# Authorize ECR in Docker using IAM role
|
||||
aws ecr get-login-password --region "$REGION" | docker login --username AWS --password-stdin "$AWS_ACCOUNT_ID".dkr.ecr."$REGION".amazonaws.com
|
||||
|
||||
# Pull the Docker image
|
||||
docker pull "$AWS_ACCOUNT_ID".dkr.ecr."$REGION".amazonaws.com/"$IMAGE_NAME"
|
||||
|
||||
# Run the Docker image
|
||||
docker run -d -p 80:8080 "$AWS_ACCOUNT_ID".dkr.ecr."$REGION".amazonaws.com/"$IMAGE_NAME"
|
||||
|
||||
# Check if the docker run command was successful
|
||||
if [ \$? -eq 0 ]; then
|
||||
echo "Docker container started successfully."
|
||||
else
|
||||
echo "Error: Failed to start Docker container."
|
||||
exit 1
|
||||
fi
|
||||
EOF
|
||||
|
||||
if [ $? -eq 1 ]; then
|
||||
echo "Could not ssh and run docker image from ECR"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Docker image has been successfully deployed on EC2 instance."
|
||||
else
|
||||
echo "Failed to deploy Docker image on EC2 instance."
|
||||
fi
|
||||
echo "Docker image has been successfully deployed on EC2 instance."
|
||||
|
|
Loading…
Reference in a new issue