-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbootstrap
More file actions
87 lines (76 loc) · 2.63 KB
/
bootstrap
File metadata and controls
87 lines (76 loc) · 2.63 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
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
function denv() {
DENV_TAG=${DENV_TAG:-latest}
local DENV_IMAGE=nodeintegration/denv
local DENV_IMAGE_TAG=${DENV_IMAGE_TAG:-${DENV_TAG}}
local DENV_CMD=$1
shift
local additional_envs_args=''
if [ -z "${DENV_CMD}" ]; then
echo "[ERROR]: you must supply at least a command argument to denv!"
return 1
fi
if [ -f .denv.yml ]; then
local YQ=$(which yq)
if [ -z "${YQ}" ]; then
echo "#[INFO]: no local yq detected, determining config in denv container"
YQ="docker run --rm -v ${PWD}:/workspace ${DENV_IMAGE}:${DENV_TAG} yq"
fi
# Process global environment variables
local global_envs=$(${YQ} -r ".global.environment // [] | keys[] // empty" .denv.yml)
for e in ${global_envs}; do
if [ ! -z ${!e+x} ]; then
additional_envs_args+=" -e ${e}"
else
local v=$(${YQ} -r ".global.environment.${e} // empty" .denv.yml)
if [ -n "${v+set}" ] ; then
additional_envs_args+=" -e ${e}=\"${v}\""
fi
fi
done
# Process command config
local cmd_config=$(${YQ} -r ".commands.${DENV_CMD} // empty" .denv.yml)
if [ -n "${cmd_config}" ]; then
local image=$(${YQ} -r ".commands.${DENV_CMD}.image // empty" .denv.yml)
DENV_IMAGE=${image:-$DENV_CMD}
local tag=$(${YQ} -r ".commands.${DENV_CMD}.tag // empty" .denv.yml)
DENV_IMAGE_TAG=${tag:-latest}
local cmd=$(${YQ} -r ".commands.${DENV_CMD}.cmd // empty" .denv.yml)
DENV_CMD=${cmd:-$DENV_CMD}
shift
fi
fi
DENV_INTERACTIVE=${DENV_INTERACTIVE:-true}
DENV_EXTRA_OPTS=''
if [ "${DENV_INTERACTIVE}" == 'true' ]; then
DENV_EXTRA_OPTS+=' -it'
fi
docker run --rm \
-u $(id -u):$(id -g) \
-v ${PWD}:/workspace \
${DENV_EXTRA_OPTS} \
${additional_envs_args} \
${env_file_args} \
${DENV_IMAGE}:${DENV_IMAGE_TAG} \
${DENV_CMD} ${@}
}
function denv-pull() {
if [ -f .denv.yml ]; then
local YQ=$(which yq)
local DENV_TAG=${DENV_TAG:-latest}
local DENV_IMAGE=nodeintegration/denv
if [ -z "${YQ}" ]; then
echo "#[DEBUG]: no local yq detected, determining config in denv container"
YQ="docker run --rm -v ${PWD}:/workspace ${DENV_IMAGE}:${DENV_TAG} yq"
fi
local commands=$(${YQ} -r ".commands | keys[] // empty" .denv.yml)
for cmd in ${commands}; do
local image=$(${YQ} -r ".commands.${cmd}.image // empty" .denv.yml)
image=${image:-$cmd}
local tag=$(${YQ} -r ".commands.${cmd}.tag // empty" .denv.yml)
echo "#[INFO]: processing command: ${cmd} image: ${image} tag: ${tag}"
docker pull ${image}:${tag}
done
else
echo "#[INFO]: no .denv.yml detected. nothing to do."
fi
}