test.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/bin/bash
  2. set -ex
  3. # https://www.packet.net/help/kb/how-to-provision-a-host-with-docker-machine/
  4. # needs both docker-machine and the docker-machine packet.net driver
  5. # https://github.com/packethost/docker-machine-driver-packet/releases
  6. if [ "${PACKET_API_KEY}" == "" ]; then
  7. echo "need to set the PACKET_API_KEY"
  8. exit
  9. fi
  10. if [ "${PACKET_PROJECT_ID}" == "" ]; then
  11. echo "need to set the PACKET_PROJECT_ID"
  12. exit
  13. fi
  14. # facilities
  15. # New York Metro (EWR1) </span>
  16. # Silicon Valley (SJC1) </span>
  17. # Amsterdam, NL (AMS1) </span>
  18. # Tokyo, JP (NRT1) </span>
  19. FACILITY=sjc1
  20. # plan - the server types
  21. PLAN=baremetal_0
  22. # randomizing the hostname makes debugging things harder atm
  23. #HOSTHASH=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 6 | head -n 1)
  24. HOST=sven-${FACILITY}-${PLAN/_/-}
  25. if ! docker-machine inspect $HOST ; then
  26. docker-machine create -d packet \
  27. --packet-api-key=${PACKET_API_KEY} --packet-project-id=${PACKET_PROJECT_ID} \
  28. --packet-facility-code ${FACILITY} \
  29. --packet-plan ${PLAN} \
  30. --packet-os=ubuntu_16_04 \
  31. ${HOST}
  32. fi
  33. SSH="docker-machine ssh $HOST"
  34. SCP="docker-machine scp"
  35. echo "- setup.."
  36. #Spin up an Ubuntu 16.04 Packet instance. There are two different categories: Type-0 and the other types. We'll need to test one from each category.
  37. #SSH into the instance and change the root password.
  38. USER="root"
  39. PASS=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
  40. echo "echo '$USER:$PASS' | chpasswd"
  41. echo "echo '$USER:$PASS' | chpasswd" > /tmp/pass
  42. chmod 755 /tmp/pass
  43. $SCP /tmp/pass $HOST:~/pass
  44. $SSH ./pass
  45. #$SSH echo "root:$HOST" | chpasswd
  46. #Download the initrd and vmlinuz for the RC.
  47. $SCP ./scripts/hosting/packet/packet.sh $HOST:~/
  48. #$SCP ./dist/artifacts/initrd $HOST:~/
  49. #$SCP ./dist/artifacts/vmlinuz-4.9-rancher2 $HOST:~/vmlinuz
  50. $SSH wget -c https://github.com/rancher/os/releases/download/v0.7.1/vmlinuz
  51. $SSH wget -c https://github.com/rancher/os/releases/download/v0.7.1/initrd
  52. #Install the kexec-tools package.
  53. $SSH sudo apt-get update
  54. #SSH into the SOS shell for the instance. There's a button labelled "Console" on the page for the instance. If you click on that it'll give you an SSH command to paste into your terminal.
  55. FACILITY=$(docker-machine inspect ${HOST} | grep Facility | sed 's/.*Facility": "\(.*\)".*/\1/')
  56. DEVICEID=$(docker-machine inspect ${HOST} | grep DeviceID | sed 's/.*DeviceID": "\(.*\)".*/\1/')
  57. SSHKEYPATH=$(docker-machine inspect ${HOST} | grep SSHKeyPath | sed 's/.*SSHKeyPath": "\(.*\)".*/\1/')
  58. SSHSOS="./scripts/hosting/packet/test.expect $SSHKEYPATH $DEVICEID@sos.$FACILITY.packet.net $USER $PASS"
  59. echo "--------------------------------------------------------------------------"
  60. $SSHSOS uname -a
  61. #$SSH DEBIAN_FRONTEND=noninteractive sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install -yqq kexec-tools
  62. #USING the SOSSSH expect script to get past the "Should kexec-tools handle reboots? [yes/no]"
  63. $SSHSOS sudo DEBIAN_FRONTEND=noninteractive apt-get install -yqq kexec-tools
  64. $SSHSOS reboot
  65. echo "- kexecing"
  66. $SSHSOS sudo kexec -f -l vmlinuz --initrd=initrd --append "rancher.password=${PASS} tinkerbell=http://bdba494d.ngrok.io console=ttyS1,115200n8 rancher.network.interfaces.eth0.dhcp=true rancher.network.interfaces.eth2.dhcp=true"
  67. #The server will restart and then you should be running RancherOS from memory.
  68. $SSHSOS reboot
  69. ## need to change the user for the exepct script
  70. USER="rancher"
  71. SSHSOS="./scripts/hosting/packet/test.expect $SSHKEYPATH $DEVICEID@sos.$FACILITY.packet.net $USER $PASS"
  72. echo "--------------------------------------------------------------------------"
  73. $SSHSOS uname -a
  74. # need to retrieve the packet.sh, vmlinuz and initrd from the disk
  75. # TODO: this makes sense on type-0 - dunno about raid
  76. # TODO: don't use dev, use LABEL - if&when we switch to running this on RancherOS
  77. $SSHSOS sudo mount /dev/sda3 /mnt
  78. $SSHSOS cp /mnt/root/* .
  79. exit
  80. #Clear the disk(s).
  81. $SSHSOS sudo dd if=/dev/zero of=/dev/sda count=4 bs=1024
  82. #If you're not running a type-0, also run the following command:
  83. if [ "$PLAN" != "baremetal_0" ]; then
  84. $SSHSOS sudo dd if=/dev/zero of=/dev/sdb count=4 bs=1024
  85. fi
  86. #Both of these will hang after you run them. Just let them run for a second or two and then hit ctrl+c.
  87. #Download and run the Packet install script.
  88. $SSHSOS bash ./packet.sh
  89. #Reboot and then RancherOS should be fully installed.
  90. #$SSHSOS reboot
  91. #$SSH uname -a