-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_acr.sh
executable file
·72 lines (63 loc) · 2.29 KB
/
build_acr.sh
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
68
69
70
71
72
#!/bin/bash
function GetBuildCommand() {
local prefix="BUILD_SECRET_"
local buildArgs=''
if [[ ${PUSH} == "--push" ]]; then
local ACR_TASK_NAME='radix-image-builder-${RADIX_ZONE}'
else
local ACR_TASK_NAME='radix-image-builder-build-only-${RADIX_ZONE}'
fi
local buildCommand="az acr task run \
--name ${ACR_TASK_NAME} \
--registry ${DOCKER_REGISTRY} \
--context ${CONTEXT} \
--file ${CONTEXT}${DOCKER_FILE_NAME} \
--set IMAGE=${IMAGE} \
--set CLUSTERTYPE_IMAGE=${CLUSTERTYPE_IMAGE} \
--set CLUSTERNAME_IMAGE=${CLUSTERNAME_IMAGE} \
--set DOCKER_FILE_NAME=${DOCKER_FILE_NAME}"
if [[ -n "${SUBSCRIPTION_ID}" ]]; then
buildCommand+=" --subscription ${SUBSCRIPTION_ID} "
fi
local line
local keyValue
local envBuildSecret
local secretName
local secretValue
while read -r line; do
if [[ "$line" ]]; then
keyValue=(${line//=/ })
envBuildSecret=${keyValue[0]}
secretName=${envBuildSecret#"$prefix"}
secretValue="$(printenv $envBuildSecret | base64 | tr -d \\n)"
buildArgs+="--build-arg $secretName=\"$secretValue\" "
fi
done <<< "$(env | grep 'BUILD_SECRET_')"
if [[ -n "${RADIX_GIT_COMMIT_HASH}" ]]; then
buildArgs+="--build-arg RADIX_GIT_COMMIT_HASH=${RADIX_GIT_COMMIT_HASH} "
fi
if [[ -n "${RADIX_GIT_TAGS}" ]]; then
buildArgs+="--build-arg RADIX_GIT_TAGS=\\\"${RADIX_GIT_TAGS}\\\" "
fi
if [[ -n "${BRANCH}" ]]; then
buildArgs+="--build-arg BRANCH=${BRANCH} "
fi
if [[ -n "${TARGET_ENVIRONMENTS}" ]]; then
buildArgs+="--build-arg TARGET_ENVIRONMENTS=\\\"${TARGET_ENVIRONMENTS}\\\" "
fi
buildCommand+=" --set BUILD_ARGS=\"${buildArgs}\""
echo "$buildCommand"
}
if [[ -z "${SP_USER}" ]]; then
SP_USER=$(cat ${AZURE_CREDENTIALS} | jq -r '.id')
fi
if [[ -z "${SP_SECRET}" ]]; then
SP_SECRET=$(cat ${AZURE_CREDENTIALS} | jq -r '.password')
fi
#if [[ -n "${RADIX_GIT_COMMIT_HASH}" ]]; then
# git --git-dir=/workspace/.git --work-tree=/workspace/ reset --hard $RADIX_GIT_COMMIT_HASH || exit 1
#fi
TEMPFILE="$(mktemp -u).sh" # We need a random filename since emptyDir /tmp is mounted to multiple build containers
GetBuildCommand > "$TEMPFILE"
az login --service-principal -u ${SP_USER} -p ${SP_SECRET} --tenant ${TENANT}
bash "$TEMPFILE"