-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathdeploy-release
More file actions
executable file
·60 lines (48 loc) · 2.08 KB
/
deploy-release
File metadata and controls
executable file
·60 lines (48 loc) · 2.08 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
#!/bin/bash
set -euo pipefail
app_name="$1"
image_tag="$2"
environment="$3"
echo "--------------"
echo "Deploy release"
echo "--------------"
echo "Input parameters:"
echo " app_name=${app_name}"
echo " image_tag=${image_tag}"
echo " environment=${environment}"
echo
# Update task definition and update service to use new task definition
echo "::group::Starting ${app_name} deploy of ${image_tag} to ${environment}"
TF_CLI_ARGS_apply="-input=false -auto-approve -var=image_tag=${image_tag}" make infra-update-app-service APP_NAME="${app_name}" ENVIRONMENT="${environment}"
echo "::endgroup::"
# Wait for the service to become stable
cluster_name=$(terraform -chdir="infra/${app_name}/service" output -raw service_cluster_name)
service_name=$(terraform -chdir="infra/${app_name}/service" output -raw service_name)
echo "Wait for service ${service_name} to become stable"
wait_for_service_stability() {
aws ecs wait services-stable --cluster "${cluster_name}" --services "${service_name}"
}
if ! wait_for_service_stability; then
echo "Retrying"
wait_for_service_stability
fi
echo "Completed ${app_name} deploy of ${image_tag} to ${environment}"
# Invalidate CloudFront cache for frontend deployments only
if [ "$app_name" = "frontend" ]; then
echo "::group::Invalidating CloudFront cache"
cloudfront_distribution_id=$(terraform -chdir="infra/${app_name}/service" output -raw cloudfront_distribution_id 2>/dev/null || echo "")
if [ -n "$cloudfront_distribution_id" ] && [ "$cloudfront_distribution_id" != "null" ]; then
echo "CloudFront distribution ID: ${cloudfront_distribution_id}"
echo "Creating invalidation for all paths (/*)"
invalidation_id=$(aws cloudfront create-invalidation \
--distribution-id "${cloudfront_distribution_id}" \
--paths "/*" \
--query 'Invalidation.Id' \
--output text)
echo "Invalidation created with ID: ${invalidation_id}"
echo "CloudFront cache invalidation initiated successfully"
else
echo "No CloudFront distribution found for ${app_name} in ${environment}, skipping cache invalidation"
fi
echo "::endgroup::"
fi