-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpublish-release
More file actions
executable file
·57 lines (46 loc) · 2.37 KB
/
publish-release
File metadata and controls
executable file
·57 lines (46 loc) · 2.37 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
#!/usr/bin/env bash
set -euo pipefail
app_name="$1"
image_name="$2"
image_tag="$3"
image_choice=${4:-app}
echo "---------------"
echo "Publish release"
echo "---------------"
echo "Input parameters:"
echo " app_name=${app_name}"
echo " image_name=${image_name}"
echo " image_tag=${image_tag}"
# Need to init module when running in CD since GitHub actions does a fresh checkout of repo
terraform -chdir="infra/${app_name}/app-config" init > /dev/null
terraform -chdir="infra/${app_name}/app-config" apply -auto-approve > /dev/null
if [ "${image_choice}" = "app" ]; then
image_repository_name="$(terraform -chdir="infra/${app_name}/app-config" output -json build_repository_config | jq -r ".name")"
elif [ "${image_choice}" = "db-role-manager" ]; then
image_repository_name="$(terraform -chdir="infra/${app_name}/app-config" output -json build_repository_config | jq -r ".db_role_manager_name")"
else
echo "Unknown image choice: ${image_choice}"
exit 1
fi
image_registry_name="$(terraform -chdir="infra/${app_name}/app-config" output -json build_repository_config | jq -r ".registry_name")"
image_registry_subscription_id="$(terraform -chdir="infra/${app_name}/app-config" output -json build_repository_config | jq -r ".account_id")"
image_registry_url="$(terraform -chdir="infra/${app_name}/app-config" output -json build_repository_config | jq -r ".registry_url")"
image_repository_url="${image_registry_url}/${image_repository_name}"
echo "Build repository info:"
echo " image_registry_name=${image_registry_name}"
echo " image_registry_url=${image_registry_url}"
echo " image_repository_name=${image_repository_name}"
echo " image_repository_url=${image_repository_url}"
echo
echo "Authenticating Docker with AZ"
DOCKER_COMMAND=$CONTAINER_CMD az acr login --subscription "${image_registry_subscription_id}" --name "${image_registry_name}"
echo "Check if tag has already been published..."
result=""
result=$(az acr repository show-tags --subscription "${image_registry_subscription_id}" --name "${image_registry_name}" --repository "${image_repository_name}" --query "[?contains(@, '${image_tag}')]" -o tsv 2> /dev/null ) || true
if [ -n "${result}" ];then
echo "Image with tag ${image_tag} already published"
exit 0
fi
echo "New tag. Publishing image"
$CONTAINER_CMD tag "${image_name}:${image_tag}" "${image_repository_url}:${image_tag}"
$CONTAINER_CMD push "${image_repository_url}:${image_tag}"