-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·86 lines (67 loc) · 2.49 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·86 lines (67 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
# Currency Analysis App Deployment Script
# This script builds and pushes the Docker image to ECR, then updates the ECS service
set -e
# Configuration
AWS_REGION=${AWS_REGION:-us-east-1}
STACK_NAME=${STACK_NAME:-currency-analysis}
ECR_REPOSITORY_NAME="currency-analysis"
IMAGE_TAG=${IMAGE_TAG:-latest}
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
echo_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
echo_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if AWS CLI is installed
if ! command -v aws &> /dev/null; then
echo_error "AWS CLI is not installed. Please install it first."
exit 1
fi
# Check if Docker is running
if ! docker info &> /dev/null; then
echo_error "Docker is not running. Please start Docker first."
exit 1
fi
# Get AWS account ID
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
if [ $? -ne 0 ]; then
echo_error "Failed to get AWS account ID. Please check your AWS credentials."
exit 1
fi
ECR_URI="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPOSITORY_NAME}"
echo_info "Starting deployment process..."
echo_info "AWS Account ID: ${AWS_ACCOUNT_ID}"
echo_info "AWS Region: ${AWS_REGION}"
echo_info "ECR Repository: ${ECR_URI}"
# Login to ECR
echo_info "Logging into ECR..."
aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${ECR_URI}
# Build Docker image
echo_info "Building Docker image..."
docker build -t ${ECR_REPOSITORY_NAME}:${IMAGE_TAG} .
# Tag image for ECR
echo_info "Tagging image for ECR..."
docker tag ${ECR_REPOSITORY_NAME}:${IMAGE_TAG} ${ECR_URI}:${IMAGE_TAG}
# Push image to ECR
echo_info "Pushing image to ECR..."
docker push ${ECR_URI}:${IMAGE_TAG}
# Update ECS service to use new image
echo_info "Updating ECS service..."
CLUSTER_NAME=$(aws cloudformation describe-stacks --stack-name ${STACK_NAME} --query 'Stacks[0].Outputs[?OutputKey==`ECSClusterName`].OutputValue' --output text)
if [ -n "$CLUSTER_NAME" ]; then
aws ecs update-service --cluster ${CLUSTER_NAME} --service currency-analysis-service --force-new-deployment
echo_info "ECS service update initiated. New deployment in progress..."
else
echo_warn "Could not find ECS cluster name. Please manually update the ECS service."
fi
echo_info "Deployment completed successfully!"
echo_info "Your application should be available at the load balancer URL from the CloudFormation outputs."