-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup-ci-endpoint
executable file
·88 lines (76 loc) · 2.34 KB
/
setup-ci-endpoint
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
#!/usr/bin/env bash
# -*- mode: sh; indent-tabs-mode: nil; sh-basic-offset: 4 -*-
# vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=bash
SCRIPT_DIR=$(dirname $0)
SCRIPT_DIR=$(readlink -e ${SCRIPT_DIR})
. ${SCRIPT_DIR}/base
CI_RUN_ENVIRONMENT="standalone"
CI_ENDPOINT="remotehosts"
REGISTRY_TLS_VERIFY="true"
longopts=",run-environment:,ci-endpoint:"
opts=$(getopt -q -o "" --longoptions "${longopts}" -n "$0" -- "$@")
if [ ${?} -ne 0 ]; then
echo "ERROR: Unrecognized option specified: $@"
exit 1
fi
eval set -- "${opts}"
while true; do
case "${1}" in
--ci-endpoint)
shift
CI_ENDPOINT="${1}"
shift
;;
--run-environment)
shift
CI_RUN_ENVIRONMENT="${1}"
shift
;;
--)
shift
break
;;
*)
echo "ERROR: Unexpected argument [${1}]"
shift
break
;;
esac
done
# validate inputs
validate_ci_run_environment
validate_ci_endpoint
# configure SSH for loopback connectivity
start_github_group "Configure loop SSH access"
apt install openssh-server
systemctl start sshd
ssh-keygen -t ed25519 -q -f /root/.ssh/id_ed25519 -N ""
bash -c "cat /root/.ssh/id_ed25519.pub > /root/.ssh/authorized_keys"
chmod 600 /root/.ssh/authorized_keys
if ! do_ssh -o StrictHostKeyChecking=no localhost echo "password-less root login over ssh works"; then
echo "ERROR: loopback ssh connection test failed"
exit 1
fi
stop_github_group
# ensure endpoint availability
case "${CI_ENDPOINT}" in
k8s)
start_github_group "Configure k8s endpoint"
# fixup some microk8s dependencies before installing it
update-alternatives --set iptables /usr/sbin/iptables-legacy
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
snap install microk8s --classic
if ! microk8s status --wait-ready; then
echo "ERROR: Failed to install and initialize microk8s"
exit 1
fi
printf "#%s/bin/bash\n\nmicrok8s kubectl \$@\n" "!" > /usr/local/bin/kubectl
chmod +x /usr/local/bin/kubectl
stop_github_group
;;
remotehosts)
start_github_group "Configure ${CI_ENDPOINT} endpoint"
echo "Nothing to do here"
stop_github_group
;;
esac