-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnpaas
executable file
·106 lines (99 loc) · 3.87 KB
/
snpaas
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
#
# https://github.com/springernature/ee-snpaas-cli
#
# SNPaaS client. This docker image has some scripts inside
# to deal with EE deployments structure. But you can use
# this docker image just to execute bosh, credhub, terraform
# Env vars are loaded automatically and you can run those
# commands directly, e.g.:
#
# snpaas credhub find -p '/director-name/'
#
# All docker images are versioned. So you can point to local images
# or previous versions by defining DOCKER_IMAGE env var, like:
#
# DOCKER_IMAGE=snpaas-tools EPHEMERAL_HOME=1 snpaas create-env live-bosh-env
#
# EPHEMERAL_HOME env var forces non mounting of the user home, so
# all resources bosh-cli uses/downloads will be gone with the container.
#
# Docker image with all the binaries
DOCKER_IMAGE="${DOCKER_IMAGE:-eu.gcr.io/halfpipe-io/engineering-enablement/snpaas-tools:master}"
DOCKER_CMD_ARGS="--rm"
PREPARE_SCRIPT="prepare.sh"
# If these environment variables are defined in the environment, they will be exported automatically to the container
BOSH_ENVVARS="BOSH_CLIENT BOSH_CLIENT_SECRET BOSH_ENVIRONMENT BOSH_CA_CERT"
CREDHUB_ENVVARS="CREDHUB_SERVER CREDHUB_CLIENT CREDHUB_SECRET CREDHUB_CA_CERT"
CF_ENVVARS="CF_API CF_USER CF_PASSWORD CF_ORG CF_SPACE"
GCP_ENVVARS="GCP_PROJECT GCP_ZONE GCP_REGION"
SYSTEM_ENVVARS="USER GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_SSH_COMMAND"
# Force to not mound /home/user
EPHEMERAL_HOME="${EPHEMERAL_HOME:-0}"
TTY="${TTY--t}"
# You can define extra envvars to pass to the container just with this env var
EXTRA_ENVVARS="${EXTRA_ENVVARS:-}"
# export GIT_SSH_COMMAND=${GIT_SSH_COMMAND:-"ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"}
###
if BASE_FOLDER="$(git rev-parse --show-toplevel 2>/dev/null)"
then
# If the command is being executed in a git repo, the volume will be the entire
# git repo, and the workdir will be set to the current path
current_path="$(pwd)"
relative_path="${current_path#"$BASE_FOLDER"}"
DOCKER_CMD_ARGS="${DOCKER_CMD_ARGS} --workdir /data${relative_path}"
# If there is a prepare.sh script in the base folder of the repo, execute it
if [ -x "${BASE_FOLDER}/${PREPARE_SCRIPT}" ]
then
(
cd ${BASE_FOLDER}
# . .envrc
./${PREPARE_SCRIPT} 2>&1 | awk '{ print "# "$0}'
exit ${PIPESTATUS[0]}
) &
wait $!
rvalue=$?
[ "${rvalue}" == "0" ] || exit ${rvalue}
fi
else
# If this is not a git repo, just import the current path as volume
BASE_FOLDER="$(pwd)"
fi
if [ "x${EPHEMERAL_HOME}" == "x0" ]
then
case "$(uname -s)" in
Linux*)
DOCKER_CMD_ARGS="${DOCKER_CMD_ARGS} --user $(id -u):$(id -g)"
DOCKER_CMD_ARGS="${DOCKER_CMD_ARGS} -v ${HOME}:/home/${USER}"
;;
Darwin*)
DOCKER_CMD_ARGS="${DOCKER_CMD_ARGS} --user snpaas"
# Mac OSX, not mounting /Users because of bugs, no caching for create-env commands!
;;
*)
echo "# Unknown OS, not mounting home, no user mapping, no caching for create-env commands!"
;;
esac
fi
if [ -n "${SSH_AUTH_SOCK}" ] && [[ "$(uname -s)" == Linux* ]]
then
# SSH agent socket in order to get working with github
# THIS ONLY WORKS ON LINUX
DOCKER_CMD_ARGS="${DOCKER_CMD_ARGS} -v $(realpath ${SSH_AUTH_SOCK}):/ssh-agent --env SSH_AUTH_SOCK=/ssh-agent"
fi
if [ -x "$(command -v docker)" ]
then
docker pull "${DOCKER_IMAGE}" 2>&1 | awk '{ print "# "$0}' || true
echo "#"
for var in ${BOSH_ENVVARS} ${CREDHUB_ENVVARS} ${CREDHUB_ENVVARS} ${CF_ENVVARS} ${SYSTEM_ENVVARS} ${EXTRA_ENVVARS}
do
[ -z "${var}" ] || DOCKER_CMD_ARGS="--env ${var} ${DOCKER_CMD_ARGS}"
done
exec docker run ${DOCKER_CMD_ARGS} -v ${BASE_FOLDER}:/data -i ${TTY} "${DOCKER_IMAGE}" "${@}"
else
echo "Loading .envrc variables ..."
. .envrc
# exec ${CMD}
echo "Please install docker in order to use this program!, otherwise you can try to use the clients with the environment variables defined. "
exit 1
fi