-
Notifications
You must be signed in to change notification settings - Fork 3
/
y-cluster-provision-k3s-docker
executable file
·48 lines (36 loc) · 1.99 KB
/
y-cluster-provision-k3s-docker
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
#!/usr/bin/env bash
[ -z "$DEBUG" ] || set -x
set -eo pipefail
[ -z "$KUBECONFIG" ] && echo "Provision requires an explicit KUBECONFIG env" && exit 1
[ -z "$CONTEXTNAME" ] && CONTEXTNAME=local
[ -z "$YSTACK_HOST" ] && YSTACK_HOST=ystack.local
[ -z "$YSTACK_PORTS_IP" ] && export YSTACK_PORTS_IP=$(y-localhost $YSTACK_HOST show 2>/dev/null)
[ -z "$YSTACK_PORTS_IP" ] || echo "Will bind ports to $YSTACK_PORTS_IP $YSTACK_HOST"
COMPOSEFILES="-f $YSTACK_HOME/docker-compose.test.yml -f $YSTACK_HOME/docker-compose.dev-overrides.yml -f $YSTACK_HOME/docker-compose.builds.yml $COMPOSEFILES"
echo "# docker-compose $COMPOSEFILES"
status=$(docker-compose $COMPOSEFILES ps -q)
if [ ! -z "$status" ]; then
echo "# Aborting because there seems to exist ystack containers already. See:"
echo docker-compose $COMPOSEFILES ps
echo "# To tear down:"
echo docker-compose $COMPOSEFILES up cleanup
echo docker-compose $COMPOSEFILES down --remove-orphans -v
exit 1
fi
# --no-build is a workaround for https://github.com/docker/compose/issues/3729
docker-compose $COMPOSEFILES up --no-build -d master1
docker-compose $COMPOSEFILES exec master1 rm /admin/.kube/kubeconfig.yaml
docker-compose $COMPOSEFILES up --no-build -d ystack-proxy
hostreplace="s/127.0.0.1:17143/$YSTACK_HOST:17143/"
[ -z "$YSTACK_PORTS_IP" ] && hostreplace="s/127.0.0.1:17143/127.0.0.1:17143/"
docker-compose $COMPOSEFILES exec master1 \
sh -c 'until test -f /admin/.kube/kubeconfig.yaml; do sleep 1; done; cat /admin/.kube/kubeconfig.yaml' \
| sed $hostreplace | tee "$KUBECONFIG.tmp" | grep server
KUBECONFIG="$KUBECONFIG.tmp" kubectl config rename-context default $CONTEXTNAME
KUBECONFIG="$KUBECONFIG.tmp" kubectl --context=local cluster-info
y-kubeconfig-import "$KUBECONFIG.tmp"
YSTACK_SUT_KEEP_RUNNING=false docker-compose $COMPOSEFILES up --no-build sut
# specs currently don't clean up after themselves
kubectl --context=$CONTEXTNAME -n ystack-specs scale --replicas=0 deploy --all
echo "Done"
echo "Note the remarks about /etc/hosts in README.md"