-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathec2-deploy.sh
More file actions
70 lines (60 loc) · 2.39 KB
/
Copy pathec2-deploy.sh
File metadata and controls
70 lines (60 loc) · 2.39 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
#!/bin/bash
# EC2 deployment script for AushadhiAI Backend
# This script pulls the latest Docker image from ECR and runs it
# Set variables
AWS_REGION="us-east-1" # Change to your AWS region
ECR_URI="905418100386.dkr.ecr.us-east-1.amazonaws.com" # Change to your ECR URI
IMAGE_NAME="aushadhi-backend"
IMAGE_TAG="latest" # Can be changed to a specific tag if needed
CONTAINER_NAME="aushadhi-backend"
APP_PORT=8007
# Install dependencies if not already installed
if ! command -v docker &> /dev/null; then
echo "Docker not found. Installing Docker..."
sudo apt-get update
sudo apt-get install -y docker.io
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker $USER
echo "Please log out and log back in to apply docker group changes, then run this script again."
exit 1
fi
if ! command -v aws &> /dev/null; then
echo "AWS CLI not found. Installing AWS CLI..."
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
rm -rf aws awscliv2.zip
fi
# Configure AWS credentials if needed
# aws configure
# Login to ECR
echo "Logging in to Amazon ECR..."
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_URI
# Check if the container is already running
if [ "$(docker ps -q -f name=$CONTAINER_NAME)" ]; then
echo "Stopping existing $CONTAINER_NAME container..."
docker stop $CONTAINER_NAME
docker rm $CONTAINER_NAME
fi
# Pull the latest image
echo "Pulling the latest Docker image from ECR..."
docker pull $ECR_URI/$IMAGE_NAME:$IMAGE_TAG
# Run the container
echo "Starting the container..."
docker run -d \
--name $CONTAINER_NAME \
-p $APP_PORT:$APP_PORT \
-e AZURE_VISION_ENDPOINT="https://aushadhiai-computervision.cognitiveservices.azure.com/" \
-e AZURE_VISION_KEY="1BUzJ4Dr444av4ikJ3X3qfb9bpFeKodrjCNrBtUEALstuNIqecUJJQQJ99BCACYeBjFXJ3w3AAAFACOGxnpP" \
-e ALLOWED_ORIGINS="https://harryhome1.github.io/INTRO-AushadhiAI,http://localhost:8006" \
$ECR_URI/$IMAGE_NAME:$IMAGE_TAG
# Check if container started successfully
if [ "$(docker ps -q -f name=$CONTAINER_NAME)" ]; then
echo "Container started successfully!"
echo "The application is now running on port $APP_PORT"
echo "You can check the logs with: docker logs $CONTAINER_NAME"
else
echo "Failed to start the container. Check the logs for more information."
docker logs $CONTAINER_NAME
fi