github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/e2e/terraform/packer/ubuntu-jammy-amd64/setup.sh (about) 1 #!/usr/bin/env bash 2 # setup script for Ubuntu Linux 22.04. Assumes that Packer has placed 3 # build-time config files at /tmp/linux 4 5 set -e 6 7 NOMAD_PLUGIN_DIR=/opt/nomad/plugins/ 8 9 mkdir_for_root() { 10 sudo mkdir -p "$1" 11 sudo chmod 755 "$1" 12 } 13 14 # Disable interactive apt prompts 15 export DEBIAN_FRONTEND=noninteractive 16 echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections 17 18 mkdir_for_root /opt 19 mkdir_for_root /srv/data # for host volumes 20 21 # Dependencies 22 sudo apt-get update 23 sudo apt-get upgrade -y 24 sudo apt-get install -y \ 25 software-properties-common \ 26 dnsmasq unzip tree redis-tools jq curl tmux awscli nfs-common \ 27 apt-transport-https ca-certificates gnupg2 28 29 # Install sockaddr 30 aws s3 cp "s3://nomad-team-dev-test-binaries/tools/sockaddr_linux_amd64" /tmp/sockaddr 31 sudo mv /tmp/sockaddr /usr/local/bin 32 sudo chmod +x /usr/local/bin/sockaddr 33 sudo chown root:root /usr/local/bin/sockaddr 34 35 # Disable the firewall 36 sudo ufw disable || echo "ufw not installed" 37 38 echo "Install HashiCorp apt repositories" 39 curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - 40 sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" 41 sudo apt-get update 42 43 echo "Install Consul and Nomad" 44 sudo apt-get install -y \ 45 consul-enterprise \ 46 nomad 47 48 # Note: neither service will start on boot because we haven't enabled 49 # the systemd unit file and we haven't uploaded any configuration 50 # files for Consul and Nomad 51 52 echo "Configure Consul" 53 mkdir_for_root /etc/consul.d 54 mkdir_for_root /opt/consul 55 sudo mv /tmp/linux/consul.service /etc/systemd/system/consul.service 56 57 echo "Configure Nomad" 58 mkdir_for_root /etc/nomad.d 59 mkdir_for_root /opt/nomad 60 mkdir_for_root $NOMAD_PLUGIN_DIR 61 sudo mv /tmp/linux/nomad.service /etc/systemd/system/nomad.service 62 63 echo "Installing third-party apt repositories" 64 65 # Docker 66 distro=$(lsb_release -si | tr '[:upper:]' '[:lower:]') 67 curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - 68 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/${distro} $(lsb_release -cs) stable" 69 70 # Java 71 sudo add-apt-repository -y ppa:openjdk-r/ppa 72 73 # Podman 74 . /etc/os-release 75 curl -fsSL "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/Release.key" | sudo apt-key add - 76 sudo add-apt-repository "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /" 77 78 sudo apt-get update 79 80 echo "Installing Docker" 81 sudo apt-get install -y docker-ce 82 83 echo "Installing Java" 84 sudo apt-get install -y openjdk-17-jdk-headless 85 86 echo "Installing CNI plugins" 87 sudo mkdir -p /opt/cni/bin 88 wget -q -O - \ 89 https://github.com/containernetworking/plugins/releases/download/v1.0.0/cni-plugins-linux-amd64-v1.0.0.tgz \ 90 | sudo tar -C /opt/cni/bin -xz 91 92 echo "Installing Podman" 93 sudo apt-get -y install podman 94 95 # get catatonit (to check podman --init switch) 96 wget -q -P /tmp https://github.com/openSUSE/catatonit/releases/download/v0.1.4/catatonit.x86_64 97 mkdir -p /usr/libexec/podman 98 sudo mv /tmp/catatonit* /usr/libexec/podman/catatonit 99 sudo chmod +x /usr/libexec/podman/catatonit 100 101 echo "Installing latest podman task driver" 102 # install nomad-podman-driver and move to plugin dir 103 latest_podman=$(curl -s https://releases.hashicorp.com/nomad-driver-podman/index.json | jq --raw-output '.versions |= with_entries(select(.key|match("^\\d+\\.\\d+\\.\\d+$"))) | .versions | keys[]' | sort -rV | head -n1) 104 105 wget -q -P /tmp "https://releases.hashicorp.com/nomad-driver-podman/${latest_podman}/nomad-driver-podman_${latest_podman}_linux_amd64.zip" 106 sudo unzip -q "/tmp/nomad-driver-podman_${latest_podman}_linux_amd64.zip" -d "$NOMAD_PLUGIN_DIR" 107 sudo chmod +x "${NOMAD_PLUGIN_DIR}/nomad-driver-podman" 108 109 # enable varlink socket (not included in ubuntu package) 110 sudo mv /tmp/linux/io.podman.service /etc/systemd/system/io.podman.service 111 sudo mv /tmp/linux/io.podman.socket /etc/systemd/system/io.podman.socket 112 113 if [ -a "/tmp/linux/nomad-driver-ecs" ]; then 114 echo "Installing nomad-driver-ecs" 115 sudo install --mode=0755 --owner=ubuntu /tmp/linux/nomad-driver-ecs "$NOMAD_PLUGIN_DIR" 116 else 117 echo "nomad-driver-ecs not found: skipping install" 118 fi 119 120 echo "Configuring dnsmasq" 121 122 # disable systemd stub resolver 123 sudo sed -i 's|#DNSStubListener=yes|DNSStubListener=no|g' /etc/systemd/resolved.conf 124 125 # disable systemd-resolved and configure dnsmasq to forward local requests to 126 # consul. the resolver files need to dynamic configuration based on the VPC 127 # address and docker bridge IP, so those will be rewritten at boot time. 128 sudo systemctl disable systemd-resolved.service 129 sudo systemctl stop systemd-resolved.service 130 sudo mv /tmp/linux/dnsmasq /etc/dnsmasq.d/default 131 sudo chown root:root /etc/dnsmasq.d/default 132 133 # this is going to be overwritten at provisioning time, but we need something 134 # here or we can't fetch binaries to do the provisioning 135 echo 'nameserver 8.8.8.8' > /tmp/resolv.conf 136 sudo mv /tmp/resolv.conf /etc/resolv.conf 137 138 sudo mv /tmp/linux/dnsmasq.service /etc/systemd/system/dnsmasq.service 139 sudo mv /tmp/linux/dnsconfig.sh /usr/local/bin/dnsconfig.sh 140 sudo chmod +x /usr/local/bin/dnsconfig.sh 141 sudo systemctl daemon-reload 142 143 echo "Updating boot parameters" 144 145 # enable cgroup_memory and swap 146 sudo sed -i 's/GRUB_CMDLINE_LINUX="[^"]*/& cgroup_enable=memory swapaccount=1/' /etc/default/grub 147 sudo update-grub 148 149 echo "Configuring user shell" 150 sudo tee -a /home/ubuntu/.bashrc << 'EOF' 151 IP_ADDRESS=$(/usr/local/bin/sockaddr eval 'GetPrivateIP') 152 export CONSUL_RPC_ADDR=$IP_ADDRESS:8400 153 export CONSUL_HTTP_ADDR=$IP_ADDRESS:8500 154 export VAULT_ADDR=http://$IP_ADDRESS:8200 155 export NOMAD_ADDR=http://$IP_ADDRESS:4646 156 export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/bin 157 158 EOF