-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·54 lines (44 loc) · 1.49 KB
/
init.sh
File metadata and controls
executable file
·54 lines (44 loc) · 1.49 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
#!/bin/sh
#
# ENTRYPOINT script to initialize gcloud and kubectl
# Exit on any error
set -e
# Update the $PATH
export PATH="/google-cloud-sdk/bin:$PATH"
# Needed by kubectl to find default credentials
export GOOGLE_APPLICATION_CREDENTIALS="/cloudsdk_service_account.json"
# Activate GCP service account
if [ -n "${CLOUDSDK_SERVICE_ACCOUNT}" ]; then
echo ${CLOUDSDK_SERVICE_ACCOUNT} | base64 -d > ${GOOGLE_APPLICATION_CREDENTIALS}
gcloud auth activate-service-account --key-file ${GOOGLE_APPLICATION_CREDENTIALS}
elif [ -s "${CLOUDSDK_SERVICE_ACCOUNT_FILE}" ]; then
cat ${CLOUDSDK_SERVICE_ACCOUNT_FILE} > ${GOOGLE_APPLICATION_CREDENTIALS}
gcloud auth activate-service-account --key-file ${GOOGLE_APPLICATION_CREDENTIALS}
fi
# Set project
if [ -n "${CLOUDSDK_PROJECT_NAME}" ]; then
gcloud config set project ${CLOUDSDK_PROJECT_NAME}
fi
# Set project zone
if [ -n "${CLOUDSDK_COMPUTE_ZONE}" ]; then
gcloud config set compute/zone ${CLOUDSDK_COMPUTE_ZONE}
fi
# Set the default kubernetes cluster
if [ -n "${CLOUDSDK_CLUSTER_NAME}" ]; then
gcloud config set container/cluster ${CLOUDSDK_CLUSTER_NAME}
# get cluster credentials only when project and zone are set
if [ -n "${CLOUDSDK_PROJECT_NAME}" ] && [ -n "${CLOUDSDK_COMPUTE_ZONE}" ]; then
gcloud container clusters get-credentials ${CLOUDSDK_CLUSTER_NAME}
fi
fi
# Run the ci.sh script
if [ -f "/code/ci.sh" ]; then
sh /code/ci.sh
exit $?
fi
# Run the parameters if any, or run gcloud info
if [ -n "$1" ]; then
exec "$@"
else
gcloud info
fi