diff --git a/scripts/hosting/digitalocean/cloud-config.yml b/scripts/hosting/digitalocean/cloud-config.yml index 2042f1cb..de771526 100644 --- a/scripts/hosting/digitalocean/cloud-config.yml +++ b/scripts/hosting/digitalocean/cloud-config.yml @@ -1,5 +1,15 @@ #!/bin/bash +# get the kernel and initrd +URL_BASE="https://releases.rancher.com/os/latest" +VMLINUX="vmlinuz" +INITRD="initrd" + +cd /tmp +curl -O -L "${URL_BASE}/${VMLINUX}" +curl -O -L "${URL_BASE}/${INITRD}" + +# setup the host ready for kexec PUBLIC_IPV4=$(wget -qO- http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address) if [ "$(ros config get rancher.environment.installer)" == "true" ] && ros --version &>/dev/null; then @@ -21,11 +31,6 @@ EOF exit 0 fi -URL_BASE="https://releases.rancher.com/os/latest" -cd /tmp -curl -O -L "${URL_BASE}/vmlinuz" -curl -O -L "${URL_BASE}/initrd" - export DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y kexec-tools ipcalc @@ -34,4 +39,4 @@ PUBLIC_IPV4_CIDR=$(ipcalc ${PUBLIC_IPV4}/${PUBLIC_IPV4_NETMASK} | awk '/^Network PUBLIC_IPV4_GATEWAY=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/gateway) -kexec --initrd=initrd -l vmlinuz -f --command-line="quiet rancher.network.interfaces.eth0.address=${PUBLIC_IPV4}/${PUBLIC_IPV4_CIDR} rancher.network.interfaces.eth0.gateway=${PUBLIC_IPV4_GATEWAY} rancher.network.interfaces.eth0.dhcp=false rancher.cloud_init.datasources=[digitalocean] rancher.environment.installer=true" +kexec --initrd=${INITRD} -l ${VMLINUX} -f --command-line="quiet rancher.network.interfaces.eth0.address=${PUBLIC_IPV4}/${PUBLIC_IPV4_CIDR} rancher.network.interfaces.eth0.gateway=${PUBLIC_IPV4_GATEWAY} rancher.network.interfaces.eth0.dhcp=false rancher.cloud_init.datasources=[digitalocean] rancher.environment.installer=true" diff --git a/scripts/hosting/digitalocean/host.sh b/scripts/hosting/digitalocean/host.sh new file mode 100755 index 00000000..26234438 --- /dev/null +++ b/scripts/hosting/digitalocean/host.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# +# This script will make a shell script that can be used as a cloud-init style user data script +# or run as root from a debian/ubuntu DigitalOcean VM to replace that distribution with +# RancherOS +# +# Its intended to be used for development, but can easily be modified to be more generally +# useful - make a Pull Request :) +# +# Note: this script will run caddy in your os/dist/artifacts/ directory, so don't leave it +# running unsupervised. + +DIST="../../../dist/artifacts" +command -v caddy >/dev/null 2>&1 || { echo >&2 "I require caddy but it's not installed, see https://github.com/mholt/caddy#quick-start . Aborting."; exit 1; } + +if [[ ! -e "$DIST" ]]; then + echo "Need to 'make release' so that there are files to serve. Aborting." + exit 1 +fi + +source ${DIST}/../../scripts/version +VMLINUX=$(ls -1 ${DIST}/vmlinuz-* | head -n1) +INITRD="${DIST}/initrd-${VERSION}" + +IP=$(curl ipinfo.io/ip) +PORT=2115 + +CLOUDCONFIG="digitalocean.sh" + +cat cloud-config.yml \ + | sed "s|^URL_BASE.*$|URL_BASE=http://${IP}:${PORT}|g" \ + | sed "s|^VMLINUX.*$|VMLINUX=${VMLINUX}|g" \ + | sed "s|^INITRD.*$|INITRD=${INITRD}|g" \ + > ${DIST}/${CLOUDCONFIG} + +echo "Hosting a cloud-config script at http://${IP}:${PORT}/${CLOUDCONFIG}" + +cd ${DIST} +caddy -port ${PORT}