mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 07:15:49 +00:00
Added separations to script parts
This commit is contained in:
parent
fe9149f9a5
commit
106b490008
3 changed files with 19 additions and 0 deletions
|
@ -14,6 +14,8 @@ ECR_REPO_URI=""
|
||||||
INSTANCE_ID=""
|
INSTANCE_ID=""
|
||||||
|
|
||||||
# Get data from user - set it as env to be used in later scripts
|
# Get data from user - set it as env to be used in later scripts
|
||||||
|
echo "---------------------------------------"
|
||||||
|
echo ""
|
||||||
read -p "Enter VPC name: " VPC_NAME && export VPC_NAME
|
read -p "Enter VPC name: " VPC_NAME && export VPC_NAME
|
||||||
read -p "Enter owner name: " OWNER && export OWNER
|
read -p "Enter owner name: " OWNER && export OWNER
|
||||||
read -p "Enter project name: " PROJECT && export PROJECT
|
read -p "Enter project name: " PROJECT && export PROJECT
|
||||||
|
@ -23,6 +25,8 @@ read -p "Enter security group name: " SECURITY_GROUP_NAME && export SECURITY_GRO
|
||||||
read -p "Enter key pair name: " KEY_PAIR_NAME && export KEY_PAIR_NAME
|
read -p "Enter key pair name: " KEY_PAIR_NAME && export KEY_PAIR_NAME
|
||||||
|
|
||||||
# Create VPC
|
# Create VPC
|
||||||
|
echo "---------------------------------------"
|
||||||
|
|
||||||
echo "Creating VPC..."
|
echo "Creating VPC..."
|
||||||
VPC_ID=$(aws ec2 create-vpc --cidr-block 10.0.0.0/16 --region "$REGION" --query 'Vpc.VpcId' --output text)
|
VPC_ID=$(aws ec2 create-vpc --cidr-block 10.0.0.0/16 --region "$REGION" --query 'Vpc.VpcId' --output text)
|
||||||
|
|
||||||
|
@ -37,6 +41,7 @@ aws ec2 create-tags --resources "$VPC_ID" --tags Key=Name,Value="$VPC_NAME" Key=
|
||||||
echo "VPC is now correctly configured."
|
echo "VPC is now correctly configured."
|
||||||
|
|
||||||
# Create Subnet
|
# Create Subnet
|
||||||
|
echo "---------------------------------------"
|
||||||
echo "Creating Subnet..."
|
echo "Creating Subnet..."
|
||||||
SUBNET_ID=$(aws ec2 create-subnet --vpc-id "$VPC_ID" --cidr-block 10.0.0.0/24 --availability-zone "$REGION"a --query 'Subnet.SubnetId' --output text)
|
SUBNET_ID=$(aws ec2 create-subnet --vpc-id "$VPC_ID" --cidr-block 10.0.0.0/24 --availability-zone "$REGION"a --query 'Subnet.SubnetId' --output text)
|
||||||
|
|
||||||
|
@ -51,6 +56,7 @@ aws ec2 create-tags --resources "$SUBNET_ID" --tags Key=Name,Value="$VPC_NAME-Su
|
||||||
echo "Subnet is now correctly configured."
|
echo "Subnet is now correctly configured."
|
||||||
|
|
||||||
# Create Elastic Container Registry (ECR)
|
# Create Elastic Container Registry (ECR)
|
||||||
|
echo "---------------------------------------"
|
||||||
echo "Creating Elastic Container Registry (ECR)..."
|
echo "Creating Elastic Container Registry (ECR)..."
|
||||||
ECR_REPO_URI=$(aws ecr create-repository --repository-name "$ECR_NAME" -tags Key=Name,Value="$ECR_NAME" Key=Owner,Value="$OWNER" Key=Project,Value="$PROJECT" --region "$REGION" --query 'repository.repositoryUri' --output text)
|
ECR_REPO_URI=$(aws ecr create-repository --repository-name "$ECR_NAME" -tags Key=Name,Value="$ECR_NAME" Key=Owner,Value="$OWNER" Key=Project,Value="$PROJECT" --region "$REGION" --query 'repository.repositoryUri' --output text)
|
||||||
|
|
||||||
|
@ -63,6 +69,7 @@ fi
|
||||||
echo "ECR repository created: $ECR_REPO_URI"
|
echo "ECR repository created: $ECR_REPO_URI"
|
||||||
|
|
||||||
# Create Security Group
|
# Create Security Group
|
||||||
|
echo "---------------------------------------"
|
||||||
echo "Creating Security Group..."
|
echo "Creating Security Group..."
|
||||||
SECURITY_GROUP_ID=$(aws ec2 create-security-group --group-name "$SECURITY_GROUP_NAME" --description "Security group for devOps internship assesment" --vpc-id "$VPC_ID" --region "$REGION" --output text)
|
SECURITY_GROUP_ID=$(aws ec2 create-security-group --group-name "$SECURITY_GROUP_NAME" --description "Security group for devOps internship assesment" --vpc-id "$VPC_ID" --region "$REGION" --output text)
|
||||||
|
|
||||||
|
@ -81,6 +88,7 @@ aws ec2 authorize-security-group-ingress --group-id "$SECURITY_GROUP_ID" --proto
|
||||||
echo "Inbound SSH access has been allowed for Security Group."
|
echo "Inbound SSH access has been allowed for Security Group."
|
||||||
|
|
||||||
# Create EC2 instance
|
# Create EC2 instance
|
||||||
|
echo "---------------------------------------"
|
||||||
echo "Creating EC2 instance..."
|
echo "Creating EC2 instance..."
|
||||||
|
|
||||||
# UserData script to install Docker and run it
|
# UserData script to install Docker and run it
|
||||||
|
@ -109,6 +117,7 @@ aws ec2 create-tags --resources "$INSTANCE_ID" --tags Key=Name,Value="$INSTANCE_
|
||||||
echo "EC2 instance is now correctly configured."
|
echo "EC2 instance is now correctly configured."
|
||||||
|
|
||||||
# Allocate and associate public IP address with EC2 instance
|
# Allocate and associate public IP address with EC2 instance
|
||||||
|
echo "---------------------------------------"
|
||||||
echo "Allocating and associating public IP address with EC2 instance..."
|
echo "Allocating and associating public IP address with EC2 instance..."
|
||||||
|
|
||||||
PUBLIC_IP=$(aws ec2 allocate-address --domain vpc --region "$REGION" --output text)
|
PUBLIC_IP=$(aws ec2 allocate-address --domain vpc --region "$REGION" --output text)
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
IMAGE_NAME="$ECR_NAME:latest"
|
IMAGE_NAME="$ECR_NAME:latest"
|
||||||
FULL_KEY_PATH=""
|
FULL_KEY_PATH=""
|
||||||
|
|
||||||
|
echo "---------------------------------------"
|
||||||
|
echo ""
|
||||||
|
|
||||||
read -p "Enter your AWS Key absolute 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
|
# Get the public IP of EC2 instance from previus script
|
||||||
|
@ -76,6 +79,7 @@ echo "---------------------------------------"
|
||||||
echo "Running spring-petclinic container..."
|
echo "Running spring-petclinic container..."
|
||||||
# Run the Docker image
|
# Run the Docker image
|
||||||
docker run -d --name spring-pertlinic \
|
docker run -d --name spring-pertlinic \
|
||||||
|
--link spring-pertlinic-db:db \
|
||||||
--network spring-petclinic-network \
|
--network spring-petclinic-network \
|
||||||
-p 80:8080 "$AWS_ACCOUNT_ID".dkr.ecr."$REGION".amazonaws.com/"$IMAGE_NAME"
|
-p 80:8080 "$AWS_ACCOUNT_ID".dkr.ecr."$REGION".amazonaws.com/"$IMAGE_NAME"
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,12 @@
|
||||||
AWS_ACCOUNT_ID=""
|
AWS_ACCOUNT_ID=""
|
||||||
|
|
||||||
# Get data from user
|
# Get data from user
|
||||||
|
echo "---------------------------------------"
|
||||||
|
echo ""
|
||||||
read -p "Enter your AWS account ID: " AWS_ACCOUNT_ID
|
read -p "Enter your AWS account ID: " AWS_ACCOUNT_ID
|
||||||
|
|
||||||
# Build docker image locally
|
# Build docker image locally
|
||||||
|
echo "---------------------------------------"
|
||||||
echo "Building Docker image..."
|
echo "Building Docker image..."
|
||||||
if docker build -t spring-petclinic .; then
|
if docker build -t spring-petclinic .; then
|
||||||
echo "Docker image built successfully."
|
echo "Docker image built successfully."
|
||||||
|
@ -21,6 +24,7 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Log in to ECR
|
# Log in to ECR
|
||||||
|
echo "---------------------------------------"
|
||||||
echo "Logging in to Amazon ECR..."
|
echo "Logging in to Amazon ECR..."
|
||||||
DOCKER_LOGIN_CMD=$(aws ecr get-login-password --region "$REGION")
|
DOCKER_LOGIN_CMD=$(aws ecr get-login-password --region "$REGION")
|
||||||
|
|
||||||
|
@ -39,6 +43,7 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Tag the image
|
# Tag the image
|
||||||
|
echo "---------------------------------------"
|
||||||
echo "Tagging Docker image..."
|
echo "Tagging Docker image..."
|
||||||
if docker tag spring-petclinic:latest "$AWS_ACCOUNT_ID".dkr.ecr."$REGION".amazonaws.com/"$ECR_NAME":latest; then
|
if docker tag spring-petclinic:latest "$AWS_ACCOUNT_ID".dkr.ecr."$REGION".amazonaws.com/"$ECR_NAME":latest; then
|
||||||
echo "Docker image tagged successfully."
|
echo "Docker image tagged successfully."
|
||||||
|
@ -48,6 +53,7 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Push image to ECR
|
# Push image to ECR
|
||||||
|
echo "---------------------------------------"
|
||||||
echo "Pushing Docker image to ECR..."
|
echo "Pushing Docker image to ECR..."
|
||||||
if docker push "$AWS_ACCOUNT_ID".dkr.ecr."$REGION".amazonaws.com/"$ECR_NAME":latest; then
|
if docker push "$AWS_ACCOUNT_ID".dkr.ecr."$REGION".amazonaws.com/"$ECR_NAME":latest; then
|
||||||
echo "Docker image pushed to ECR successfully."
|
echo "Docker image pushed to ECR successfully."
|
||||||
|
|
Loading…
Reference in a new issue