dev-install.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/bin/bash
  2. set -euo pipefail
  3. #
  4. # This script downloads and installs development dependencies required for
  5. # bridge development on Linux.
  6. #
  7. # Tested on amd64 with CentOS 8, Debian 10 and Ubuntu 20.04. Likely works on other distros as well.
  8. #
  9. # We use this to set up our CI, but you might find it useful for your own development needs.
  10. #
  11. # This installer pulls in binaries from, and therefore trusts, a number of third-party sources:
  12. #
  13. # - k3s.io by Rancher Labs.
  14. # - Go binary distribution by Google.
  15. # - Tilt binary distribution by Tilt.
  16. #
  17. # Idempotent and safe to run multiple times for upgrades (but restarts your cluster).
  18. # Goes without saying, but this is NOT for production, or anywhere close to it.
  19. #
  20. # If you want to allow other users on the host access to the k3s cluster, look into
  21. # run the installer script with an appropriate K3S_KUBECONFIG_MODE.
  22. if [[ $EUID -ne 0 ]]; then
  23. echo "This script must be run as root"
  24. exit 1
  25. fi
  26. if ! docker info; then
  27. echo "Please install and configure Docker first"
  28. exit 1
  29. fi
  30. # On Ubuntu/Debian, switch to iptables-legacy
  31. # https://github.com/rancher/k3s/issues/1114
  32. if update-alternatives --set iptables /usr/sbin/iptables-legacy; then
  33. systemctl restart docker
  34. fi
  35. # Ensure that our binaries are not shadowed by the distribution.
  36. export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/sbin:/bin
  37. # Install Go binaries.
  38. ARCH=amd64
  39. GO=1.15
  40. # TODO(leo): verify checksum
  41. (
  42. if [[ -d /usr/local/go ]]; then
  43. rm -rf /usr/local/go
  44. fi
  45. TMP=$(mktemp -d)
  46. (
  47. cd "$TMP"
  48. curl -OJ "https://dl.google.com/go/go${GO}.linux-${ARCH}.tar.gz"
  49. tar -C /usr/local -xzf "go${GO}.linux-${ARCH}.tar.gz"
  50. echo 'PATH=/usr/local/go/bin:$PATH' >/etc/profile.d/local_go.sh
  51. )
  52. rm -rf "$TMP"
  53. )
  54. . /etc/profile.d/local_go.sh
  55. # Install Tilt (latest stable release by Tilt). Install script looks fine.
  56. curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash
  57. # Install SELinux policies for k3s on CentOS/Fedora systems (ignored otherwise).
  58. if rpm -q libselinux-utils; then
  59. yum install -y container-selinux selinux-policy-base
  60. ! rpm -i https://rpm.rancher.io/k3s-selinux-0.1.1-rc1.el7.noarch.rpm
  61. fi
  62. # Install k3s with sane defaults and make it use the local Docker daemon.
  63. curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="v1.18.6+k3s1" INSTALL_K3S_EXEC="server
  64. --disable-cloud-controller
  65. --kube-scheduler-arg=address=127.0.0.1
  66. --kube-controller-manager-arg=address=127.0.0.1
  67. --disable traefik
  68. --docker
  69. " sh -s -
  70. cat <<'EOF' > /etc/profile.d/k3s.sh
  71. alias kc=kubectl
  72. source <(kubectl completion bash)
  73. complete -F __start_kubectl kc
  74. function use-namespace {
  75. kubectl config set-context --current --namespace=$1
  76. }
  77. # Required for tilt to find the local cluster
  78. export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
  79. EOF
  80. cat <<'EOF' > /etc/profile.d/buildkit.sh
  81. # Enable buildkit support in Docker for incremental builds
  82. export DOCKER_BUILDKIT=1
  83. EOF
  84. . /etc/profile.d/k3s.sh
  85. # Set default namespace to wormhole to make it easier to reset without deleting the cluster.
  86. kubectl create namespace wormhole
  87. use-namespace wormhole
  88. # Trick tilt into not pushing images by pretending to be docker-desktop
  89. # FIXME: https://github.com/tilt-dev/tilt/issues/3654
  90. sed -i 's/ name: default/ name: docker-desktop/g' $KUBECONFIG
  91. sed -i 's/current-context: default/current-context: docker-desktop/g' $KUBECONFIG
  92. sed -i 's/cluster: default/cluster: docker-desktop/g' $KUBECONFIG
  93. while ! k3s kubectl get all; do
  94. echo "Waiting for k3s..."
  95. systemctl status k3s.service
  96. sleep 5
  97. done