Spaces:
Runtime error
Runtime error
set -e | |
# Run tests before deployment | |
# echo "Running tests before deployment..." | |
# ./run_tests.sh | |
# If tests pass, continue with deployment | |
if [ $? -ne 0 ]; then | |
echo "Tests failed. Aborting deployment." | |
exit 1 | |
fi | |
case "$1" in | |
"api") | |
dockerfile_target="api" | |
aws_app="api" | |
;; | |
*) | |
echo "Unsupported app" | |
exit 1 | |
;; | |
esac | |
case "$2" in | |
"dev") | |
aws_account="790537050551" | |
aws_env="dev" | |
aws_region="us-east-2" | |
git_tag="dev_mms_api" | |
;; | |
*) | |
echo "Unsupported environment" | |
exit 1 | |
;; | |
esac | |
# Build the Docker image (production-ready with code baked in) | |
local_tag="mms-${dockerfile_target}" | |
DOCKER_BUILDKIT=1 docker build -t "$local_tag" --platform linux/amd64 . | |
# login to ECR Repo | |
aws ecr get-login-password --region ${aws_region} | docker login --username AWS --password-stdin ${aws_account}.dkr.ecr.${aws_region}.amazonaws.com | |
# Tag the Docker image | |
ecs_tag="${aws_account}.dkr.ecr.${aws_region}.amazonaws.com/${aws_env}_mms_${aws_app}_repo:latest" | |
docker tag "$local_tag":latest "$ecs_tag" | |
# Push the Docker image | |
docker push "$ecs_tag" | |
# Restart the service | |
aws ecs update-service --force-new-deployment --service "$aws_env"-mms-"$aws_app"-ecs-service --cluster "$aws_env"-mms-api-cluster --region "$aws_region" | |
# Tag the release in github (add this back in when stable in prod) | |
# git tag -d "$git_tag" || true # ignore fail | |
# git tag "$git_tag" | |
# git push origin --delete "$git_tag" || true # ignore fail | |
# git push origin "$git_tag" | |