#!/bin/bash # Deploy VIMS to AWS ECS # Uses Fargate for serverless container deployment set -e REGION="eu-north-1" PROJECT="vims" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' echo -e "${GREEN}🚀 VIMS AWS Deployment${NC}" echo "=======================" # Load AWS config if [ -f .env.aws ]; then source .env.aws else echo -e "${RED}AWS config not found. Run setup-aws.sh first.${NC}" exit 1 fi # Build Docker image echo -e "${YELLOW}Building Docker image...${NC}" docker build -t ${PROJECT}:latest . # Login to ECR echo -e "${YELLOW}Logging in to ECR...${NC}" aws ecr get-login-password --region ${REGION} | \ docker login --username AWS --password-stdin ${ECR_URI} # Tag and push echo -e "${YELLOW}Pushing to ECR...${NC}" docker tag ${PROJECT}:latest ${ECR_URI}:latest docker push ${ECR_URI}:latest echo -e "${GREEN}✓ Image pushed to ${ECR_URI}:latest${NC}" # Create ECS cluster (if not exists) echo -e "${YELLOW}Creating ECS cluster...${NC}" aws ecs create-cluster \ --cluster-name ${PROJECT} \ --region ${REGION} 2>/dev/null || true # Create task definition echo -e "${YELLOW}Creating task definition...${NC}" cat > /tmp/vims-task.json </dev/null || \ aws ecs update-service \ --cluster ${PROJECT} \ --service ${PROJECT}-api \ --task-definition ${PROJECT} \ --desired-count 2 \ --region ${REGION} echo -e "${GREEN}✓ ECS service updated${NC}" # Wait for deployment echo -e "${YELLOW}Waiting for deployment...${NC}" aws ecs wait services-stable \ --cluster ${PROJECT} \ --services ${PROJECT}-api \ --region ${REGION} echo -e "${GREEN}✓ Deployment complete!${NC}" # Get service URL echo "" echo -e "${GREEN}🎉 VIMS deployed to AWS!${NC}" echo "" echo "Check service status:" echo " aws ecs describe-services --cluster ${PROJECT} --services ${PROJECT}-api"