forked from chanwit/minifk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stop.sh
executable file
·137 lines (116 loc) · 3.13 KB
/
stop.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env bash
unset CDPATH
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "${SCRIPT_DIR}" || exit 1
. lib/functions.sh
. lib/footloose.sh
. lib/ignite.sh
. lib/jk.sh
. lib/wksctl.sh
# user-overrideable via ENV
if command -v sudo >/dev/null 2>&1; then
sudo="${sudo:-"sudo"}"
else
sudo="${sudo}"
fi
set -euo pipefail
JK_VERSION=0.3.0
FOOTLOOSE_VERSION=0.6.3
IGNITE_VERSION=0.5.5
WKSCTL_VERSION=0.8.1
config_backend() {
sed -n -e 's/^backend: *\(.*\)/\1/p' config.yaml
}
set_config_backend() {
local tmp=.config.yaml.tmp
sed -e "s/^backend: .*$/backend: ${1}/" config.yaml > "${tmp}" && \
mv "${tmp}" config.yaml && \
rm -f "${tmp}"
}
do_footloose() {
if [ "$(config_backend)" == "ignite" ]; then
$sudo env "PATH=${PATH}" footloose "${@}"
else
footloose "${@}"
fi
}
if git_current_branch > /dev/null 2>&1; then
log "Using git branch: $(git_current_branch)"
else
error "Please checkout a git branch."
fi
git_remote="$(git config --get "branch.$(git_current_branch).remote" || true)" # fallback to "", user may override
git_deploy_key=""
download="yes"
download_force="no"
setup_help() {
echo "
setup.sh
- ensure dependent binaries are available
- generate a cluster config
- bootstrap the gitops cluster
- push the changes to the remote for the cluster to pick up
optional flags:
--no-download Do not download dependent binaries
--force-download Force downloading version-specific dependent binaries
--git-remote string Override the remote used for pushing changes and configuring the cluster
--git-deploy-key filepath Provide a deploy key for private/authenticated repo access
-h, -help Print this help text
"
}
while test $# -gt 0; do
case "${1}" in
--no-download)
download="no"
;;
--force-download)
download_force="yes"
;;
--git-remote)
shift
git_remote="${1}"
;;
--git-deploy-key)
shift
git_deploy_key="--git-deploy-key=${1}"
log "Using git deploy key: ${1}"
;;
-h|--help)
setup_help
exit 0
;;
*)
setup_help
error "unknown argument '${1}'"
;;
esac
shift
done
if [ "${git_remote}" ]; then
log "Using git remote: ${git_remote}"
else
error "
Please configure a remote for your current branch:
git branch --set-upstream-to <remote_name>/$(git_current_branch)
Or use the --git-remote flag:
./setup.sh --git-remote <remote_name>
Your repo has the following remotes:
$(git remote -v)"
fi
echo
if [ "${download}" == "yes" ]; then
mkdir -p "${HOME}/.wks/bin"
export PATH="${HOME}/.wks/bin:${PATH}"
fi
# On macOS, we only support the docker backend.
if [ "$(goos)" == "darwin" ]; then
set_config_backend docker
fi
check_command docker
check_version jk "${JK_VERSION}"
check_version footloose "${FOOTLOOSE_VERSION}"
if [ "$(config_backend)" == "ignite" ]; then
check_version ignite "${IGNITE_VERSION}"
fi
check_version wksctl "${WKSCTL_VERSION}"
do_footloose stop