-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevelope.sh
executable file
·103 lines (98 loc) · 2.57 KB
/
develope.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
# Watch and upgrade files inside a release as you code.
readonly CONFIG="./.helm-developerc"
function check_deps () {
# install inotify-tools if necesary
if [[ -a !$(which inotifywait) ]]; then
echo 'Would you like to install inotify-tools? (y/n)';
read install
case "${install}" in
y)
echo 'Installing inotify-tools'
sudo apt-get install -y inotify-tools
;;
n)
echo 'You can still use this plugin to manualy copy code to your release'
;;
*)
echo 'Usage: type "y" or "n"'
exit
;;
esac
fi
}
function watch () {
inotifywait -m -r --format %w%f --event modify,moved_to "$(pwd)" | while read file; do
EXT=${file##*.}
if [ $EXT = "php" ]
then
echo "uploading ${file}"
kubectl cp "${file}" "${pod}":"${file//$(pwd)/${app_path}}" -c "${container}"
fi
done
}
function create_config () {
# select a release from the cluster
echo "Select a release"
echo "Fetching release names from cluster..."
function select_release () {
local releases
releases="$(helm ls | tail -n+2 | awk -F"\t" '{ print $1 }')"
select release in ${releases}; do
echo "${release}"
break
done
}
current_release="$(select_release)"
# select a pod
echo "Select a pod in the ${current_release} release"
echo "Fetching pod names from cluster..."
function select_pod () {
local pods
pods="$(kubectl get po -l release="${current_release}" | tail -n+2 | awk -F" " '{ print $1 }')"
select pod in ${pods}; do
echo "${pod}"
break
done
}
current_pod="$(select_pod)"
# select a container
echo "Select a container in the ${current_pod} pod"
echo "Fetching container names from cluster..."
function select_container () {
local containers
containers="$(kubectl get po "${current_pod}" -o jsonpath="{.spec.containers[*].name}")"
select container in ${containers}; do
echo "${container}"
break
done
}
current_container="$(select_container)"
function select_path () {
read path
echo "${path}"
}
echo "Where does your code live inside the container?"
current_path="$(select_path)"
cat <<-EOF > "${CONFIG}"
release="${current_release}"
pod="${current_pod}"
container="${current_container}"
app_path="${current_path}"
EOF
}
function main () {
check_deps
if [[ ! -f ${CONFIG} ]]; then
create_config
fi
. "${CONFIG}"
echo Your current config is:
echo
echo Release: "${release}"
echo Pod: "${pod}"
echo Container: "${container}"
echo Path: "${app_path}";
watch
}
main