-
Notifications
You must be signed in to change notification settings - Fork 27
/
entrypoint.sh
88 lines (73 loc) · 2.72 KB
/
entrypoint.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
set -e
PREVIOUS_PROJECT_ID=$(gcloud config list --format 'value(core.project)' 2>/dev/null)
set_up_a_credentials() {
if [ -n "${CLOUDSDK_AUTH_ACCESS_TOKEN}" ]; then
echo "CLOUDSDK_AUTH_ACCESS_TOKEN is set; using it for auth"
export CLOUDSDK_AUTH_ACCESS_TOKEN
return
else
if [ "$(echo "$APPLICATION_CREDENTIALS" | tr -d \\n)" = "$(echo "$APPLICATION_CREDENTIALS" | base64 -d | base64 | tr -d \\n)" ]; then
echo "APPLICATION_CREDENTIALS is Base64 Encoded"
echo "$APPLICATION_CREDENTIALS" | base64 -d > /tmp/account.json
else
echo "APPLICATION_CREDENTIALS is not Base64 Encoded"
echo "$APPLICATION_CREDENTIALS" > /tmp/account.json
fi
fi
gcloud auth activate-service-account --key-file=/tmp/account.json
}
if [ ! -d "$HOME/.config/gcloud" ]; then
echo "Previous configuration not detected"
if [ -z "${APPLICATION_CREDENTIALS-}" -a -z "${CLOUDSDK_AUTH_ACCESS_TOKEN}" ]; then
echo "APPLICATION_CREDENTIALS not found and CLOUDSDK_AUTH_ACCESS_TOKEN unset. Exiting...."
exit 1
else
set_up_a_credentials
fi
else
echo "Detect credentials from previous session..."
if [ -n "${CLOUDSDK_AUTH_ACCESS_TOKEN}" ]; then
echo "CLOUDSDK_AUTH_ACCESS_TOKEN is set; using it for auth"
export CLOUDSDK_AUTH_ACCESS_TOKEN
elif [ -n "${APPLICATION_CREDENTIALS-}" ]; then
echo "APPLICATION_CREDENTIALS found. Setting up a credentials...."
set_up_a_credentials
else
echo "Using credentials from previous session..."
fi
fi
if [ -z "${PREVIOUS_PROJECT_ID-}" ]; then
echo "Previous project id not detected"
if [ -z "${PROJECT_ID-}" ]; then
echo "PROJECT_ID not found. Exiting...."
exit 1
else
gcloud config set project "$PROJECT_ID"
fi
else
echo "Previous project id detected"
if [ -n "${PROJECT_ID-}" ] && [ "$PREVIOUS_PROJECT_ID" != "$PROJECT_ID" ]; then
echo "Project id from the previous session is not the same as in actual. Setting up new project id..."
gcloud config set project "$PROJECT_ID"
else
echo "Using project id from previous session...."
fi
fi
echo "/google-cloud-sdk/bin/gcloud" >> $GITHUB_PATH
echo "/google-cloud-sdk/bin/gsutil" >> $GITHUB_PATH
command="gcloud"
if [ "$CLI" = "gsutil" ] || [ "$INPUT_CLI" = "gsutil" ]; then
command="gsutil"
fi
if [ "$CLI" = "kubectl" ] || [ "$INPUT_CLI" = "kubectl" ]; then
gcloud components install kubectl
echo "/google-cloud-sdk/bin/kubectl" >> $GITHUB_PATH
command="kubectl"
fi
if [ "$command" = "gcloud" ] && [ "$1" = "beta" ]; then
gcloud components install beta
fi
if [ ! $# -eq 0 ]; then
eval "$command $*"
fi