-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·75 lines (61 loc) · 2.27 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·75 lines (61 loc) · 2.27 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
#! /bin/bash
echo "====================================="
echo " AWS ECR Deployment Script "
echo "====================================="
echo ""
echo "Please select deployment environment:"
echo "1) dev"
echo "2) prod"
echo "-------------------------------------"
read -p "Enter your choice (1 or 2): " deploy_stage
# Convert numeric choice to environment name
if [ "$deploy_stage" = "1" ]; then
deploy_stage="dev"
elif [ "$deploy_stage" = "2" ]; then
deploy_stage="prod"
else
echo "Invalid selection. Please choose 1 for dev or 2 for prod. Exiting..."
exit 1
fi
if [ ! -e .env ]; then
echo ".env file not found. Exiting..."
exit 1
fi
echo "Deploying to ${deploy_stage} environment..."
echo "====================================="
# Load Environment Variables
if [ -f .env ]; then
set -o allexport
source .env
set +o allexport
fi
# Export AWS credentials from .env
export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}
# Authenticate with AWS ECR and login to Docker
echo "Authenticating with AWS ECR..."
aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | docker login --username AWS --password-stdin ${ECR_PUBLIC_URL}
# Repository name based on stage
repository_name="dev-retech-frontend"
image_version=$IMAGE_VERSION
export IMAGE_NAME="${repository_name}"
export IMAGE_TAG="${image_version}"
echo "Building Docker image..."
echo "====================================="
docker build \
--platform="linux/amd64" \
--file=docker/dockerfiles/app.Dockerfile \
--tag="${repository_name}:${image_version}" .
echo "Tagging Docker image..."
echo "====================================="
docker tag "${repository_name}:${image_version}" "${ECR_PUBLIC_URL}/${repository_name}:${image_version}"
echo "Pushing Docker image to ECR..."
echo "====================================="
docker push "${ECR_PUBLIC_URL}/${repository_name}:${image_version}"
echo "Tagging Docker image as latest..."
echo "====================================="
docker tag "${ECR_PUBLIC_URL}/${repository_name}:${image_version}" "${ECR_PUBLIC_URL}/${repository_name}:latest"
echo "Pushing Docker image as latest..."
echo "====================================="
docker push "${ECR_PUBLIC_URL}/${repository_name}:latest"