github.com/hernad/nomad@v1.6.112/e2e/terraform/packer/ubuntu-jammy-amd64/setup.sh (about)

     1  #!/usr/bin/env bash
     2  # Copyright (c) HashiCorp, Inc.
     3  # SPDX-License-Identifier: MPL-2.0
     4  
     5  # setup script for Ubuntu Linux 22.04. Assumes that Packer has placed
     6  # build-time config files at /tmp/linux
     7  
     8  set -euo pipefail
     9  
    10  NOMAD_PLUGIN_DIR=/opt/nomad/plugins/
    11  
    12  mkdir_for_root() {
    13      sudo mkdir -p "$1"
    14      sudo chmod 755 "$1"
    15  }
    16  
    17  # Disable interactive apt prompts
    18  export DEBIAN_FRONTEND=noninteractive
    19  echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections
    20  
    21  mkdir_for_root /opt
    22  mkdir_for_root /srv/data # for host volumes
    23  
    24  # Dependencies
    25  sudo apt-get update
    26  sudo apt-get upgrade -y
    27  sudo apt-get install -y \
    28       software-properties-common \
    29       dnsmasq unzip tree redis-tools jq curl tmux awscli nfs-common \
    30       apt-transport-https ca-certificates gnupg2
    31  
    32  # Install hc-install
    33  curl -o /tmp/hc-install.zip https://releases.hashicorp.com/hc-install/0.5.2/hc-install_0.5.2_linux_amd64.zip
    34  sudo unzip -d /usr/local/bin /tmp/hc-install.zip
    35  
    36  # Install sockaddr
    37  aws s3 cp "s3://nomad-team-dev-test-binaries/tools/sockaddr_linux_amd64" /tmp/sockaddr
    38  sudo mv /tmp/sockaddr /usr/local/bin
    39  sudo chmod +x /usr/local/bin/sockaddr
    40  sudo chown root:root /usr/local/bin/sockaddr
    41  
    42  # Disable the firewall
    43  sudo ufw disable || echo "ufw not installed"
    44  
    45  echo "Install HashiCorp apt repositories"
    46  curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
    47  sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
    48  sudo apt-get update
    49  
    50  echo "Install Consul and Nomad"
    51  sudo apt-get install -y \
    52       consul-enterprise \
    53       nomad
    54  
    55  # Note: neither service will start on boot because we haven't enabled
    56  # the systemd unit file and we haven't uploaded any configuration
    57  # files for Consul and Nomad
    58  
    59  echo "Configure Consul"
    60  mkdir_for_root /etc/consul.d
    61  mkdir_for_root /opt/consul
    62  sudo mv /tmp/linux/consul.service /etc/systemd/system/consul.service
    63  
    64  echo "Configure Nomad"
    65  mkdir_for_root /etc/nomad.d
    66  mkdir_for_root /opt/nomad
    67  mkdir_for_root $NOMAD_PLUGIN_DIR
    68  sudo mv /tmp/linux/nomad.service /etc/systemd/system/nomad.service
    69  
    70  echo "Installing third-party apt repositories"
    71  
    72  # Docker
    73  distro=$(lsb_release -si | tr '[:upper:]' '[:lower:]')
    74  curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
    75  sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/${distro} $(lsb_release -cs) stable"
    76  
    77  # Docker
    78  echo "Installing Docker"
    79  sudo apt-get install -y docker-ce
    80  
    81  # Java
    82  echo "Installing Java"
    83  sudo apt-get install -y openjdk-17-jdk-headless
    84  
    85  # CNI
    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  # Podman
    93  echo "Installing Podman"
    94  sudo apt-get -y install podman catatonit
    95  
    96  echo "Installing Podman Driver"
    97  sudo hc-install install --path ${NOMAD_PLUGIN_DIR} --version 0.4.2 nomad-driver-podman
    98  
    99  # ECS
   100  if [ -a "/tmp/linux/nomad-driver-ecs" ]; then
   101      echo "Installing nomad-driver-ecs"
   102      sudo install --mode=0755 --owner=ubuntu /tmp/linux/nomad-driver-ecs "$NOMAD_PLUGIN_DIR"
   103  else
   104      echo "nomad-driver-ecs not found: skipping install"
   105  fi
   106  
   107  echo "Configuring dnsmasq"
   108  
   109  # disable systemd stub resolver
   110  sudo sed -i 's|#DNSStubListener=yes|DNSStubListener=no|g' /etc/systemd/resolved.conf
   111  
   112  # disable systemd-resolved and configure dnsmasq to forward local requests to
   113  # consul. the resolver files need to dynamic configuration based on the VPC
   114  # address and docker bridge IP, so those will be rewritten at boot time.
   115  sudo systemctl disable systemd-resolved.service
   116  sudo systemctl stop systemd-resolved.service
   117  sudo mv /tmp/linux/dnsmasq /etc/dnsmasq.d/default
   118  sudo chown root:root /etc/dnsmasq.d/default
   119  
   120  # this is going to be overwritten at provisioning time, but we need something
   121  # here or we can't fetch binaries to do the provisioning
   122  echo 'nameserver 8.8.8.8' > /tmp/resolv.conf
   123  sudo mv /tmp/resolv.conf /etc/resolv.conf
   124  
   125  sudo mv /tmp/linux/dnsmasq.service /etc/systemd/system/dnsmasq.service
   126  sudo mv /tmp/linux/dnsconfig.sh /usr/local/bin/dnsconfig.sh
   127  sudo chmod +x /usr/local/bin/dnsconfig.sh
   128  sudo systemctl daemon-reload
   129  
   130  echo "Updating boot parameters"
   131  
   132  # enable cgroup_memory and swap
   133  sudo sed -i 's/GRUB_CMDLINE_LINUX="[^"]*/& cgroup_enable=memory swapaccount=1/' /etc/default/grub
   134  sudo update-grub
   135  
   136  echo "Configuring user shell"
   137  sudo tee -a /home/ubuntu/.bashrc << 'EOF'
   138  IP_ADDRESS=$(/usr/local/bin/sockaddr eval 'GetPrivateIP')
   139  export CONSUL_RPC_ADDR=$IP_ADDRESS:8400
   140  export CONSUL_HTTP_ADDR=$IP_ADDRESS:8500
   141  export VAULT_ADDR=http://$IP_ADDRESS:8200
   142  export NOMAD_ADDR=http://$IP_ADDRESS:4646
   143  export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/bin
   144  
   145  EOF