-
Notifications
You must be signed in to change notification settings - Fork 53
/
install
executable file
·89 lines (76 loc) · 3.37 KB
/
install
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
#!/usr/bin/env bash
set -euo pipefail
CONTEXT=${1-k3d-tns}
BASEDIR="$(cd "`dirname $0`"; pwd)"
PROD="$BASEDIR/production/sample"
MODE=${2-standard}
function install_env {
echo "installing ${1}"
ENV=$1
tk env add environments/$ENV --server-from-context $CONTEXT --namespace $ENV # Creates/configures the environment.
ln -sf "$PROD/$ENV/main.jsonnet" environments/$ENV/main.jsonnet # Copies the base configuration for your env.
if [[ $# > 1 ]]; then
echo "$2" > environments/$ENV/config.jsonnet
fi
tk apply environments/$ENV # Installs everything for your environment.
}
if [[ "$MODE" != "app-only" ]] && [[ "$MODE" != "grafana-cloud" ]] && [[ $(docker info --format "{{.MemTotal}}") -lt 2560000000 ]]; then
echo "WARNING: your docker daemon will likely need more memory in order to schedule all required pods"
fi
if [ -e "$BASEDIR/tanka" ]; then
echo "tanka/ directory already exists. Please remove and try again."
exit 1
fi
if ! kubectl --context $CONTEXT get ns>/dev/null 2>&1; then
echo "$CONTEXT is not a valid KUBECONFIG context. Please check and try again."
exit 2
fi
mkdir "$BASEDIR/tanka" && cd "$BASEDIR/tanka"
# Initialise Tanka
tk init --k8s=1.22
# Workaround for https://github.com/jsonnet-libs/k8s/issues/132
echo "(import 'github.com/jsonnet-libs/k8s-libsonnet/1.22/main.libsonnet') + { extensions:: null }" > lib/k.libsonnet
# Copy dependency list into workdir
ln -sf "$PROD"/jsonnetfile.json jsonnetfile.json
ln -sf "$PROD"/jsonnetfile.lock.json jsonnetfile.lock.json
# Install dependencies
jb install
# Install apps into separate namespaces
if [[ "$MODE" == "app-only" ]]; then
install_env tns-cloud # Only install (modified) TNS demo app into existing K8s cluster
elif [[ "$MODE" == "grafana-cloud" ]]; then
read -p "Please enter your org slug: " ORGSLUG
read -p "Please enter your API-Key: " APIKEY
INSTANCESFILE=$(mktemp)
curl --silent -H "Authorization: Bearer $APIKEY" "https://grafana.com/api/orgs/$ORGSLUG/instances" > $INSTANCESFILE
STACKS=$(jq -r '[.items[].slug] | join(",")' $INSTANCESFILE)
read -p "Please select your stack (available: $STACKS): " STACK
read -r -d '' GCLOUD_CONFIG <<EOF
{
_config+:: {
apiKey: '$APIKEY',
prometheus+: {
endpoint: '$(jq -r --arg STACK $STACK '.items[] | select(.slug==$STACK) | .hmInstancePromUrl' $INSTANCESFILE)/api/prom/push',
user: $(jq --arg STACK $STACK '.items[] | select(.slug==$STACK) | .hmInstancePromId' $INSTANCESFILE),
},
loki+: {
endpoint: '$(jq -r --arg STACK $STACK '.items[] | select(.slug==$STACK) | .hlInstanceUrl' $INSTANCESFILE)/loki/api/v1/push',
user: $(jq --arg STACK $STACK '.items[] | select(.slug==$STACK) | .hlInstanceId' $INSTANCESFILE),
},
tempo+: {
endpoint: '$(jq -r --arg STACK $STACK '.items[] | select(.slug==$STACK) | .htInstanceUrl' $INSTANCESFILE):443',
user: $(jq --arg STACK $STACK '.items[] | select(.slug==$STACK) | .htInstanceId' $INSTANCESFILE),
},
},
}
EOF
install_env grafana-cloud "$GCLOUD_CONFIG"
rm $INSTANCESFILE
install_env tns-cloud
else
install_env loki # Install loki logging app
install_env tns # Install TNS demo app
install_env tempo # Install tempo tracing app
install_env mimir # Install Mimir metrics app
install_env default # Install default monitoring stack
fi