File size: 1,597 Bytes
38818c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
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"