From 096c281dedcdb7d93a66c124c48677cdde87e5a0 Mon Sep 17 00:00:00 2001 From: Sven Dowideit Date: Thu, 13 Apr 2017 10:14:28 +1000 Subject: [PATCH 1/6] add a fedora based cloud-initi RancherOS install cloud-init script Signed-off-by: Sven Dowideit --- .../hosting/digitalocean/fedora-symbiote.yml | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 scripts/hosting/digitalocean/fedora-symbiote.yml diff --git a/scripts/hosting/digitalocean/fedora-symbiote.yml b/scripts/hosting/digitalocean/fedora-symbiote.yml new file mode 100644 index 00000000..82fdbca5 --- /dev/null +++ b/scripts/hosting/digitalocean/fedora-symbiote.yml @@ -0,0 +1,28 @@ +#!/bin/bash + +ROS_VERSION="v0.9.2-symbiote" +URL_BASE="https://github.com/SvenDowideit/os/releases/download/${ROS_VERSION}" +VMLINUX="vmlinuz-4.9.21-rancher" +INITRD="initrd + +cd /tmp +echo "downloading ${URL_BASE}/${VMLINUX}" > /dev/kmsg +curl -O -L "${URL_BASE}/${VMLINUX}" +echo "downloading ${URL_BASE}/${INITRD}" > /dev/kmsg +curl -O -L "${URL_BASE}/${INITRD}" + +if [ "$(ros config get rancher.environment.installer)" == "true" ] && ros --version &>/dev/null; then + ros install -f -c cloud-config.yml -d /dev/vda -p /dev/vda1 \ + --statedir ros -t noformat \ + --append "rancher.state.directory=ros rancher.debug=true printk.devkmsg=on notsc clocksource=kvm-clock rancher.network.interfaces.eth0.ipv4ll rancher.cloud_init.datasources=[digitalocean] rancher.autologin=tty1 rancher.autologin=ttyS0" + exit 0 +fi + +echo "installing kexec" > /dev/kmsg +#apt-get update && apt-get install -y kexec-tools ipcalc +#dnf update +dnf install -y kexec-tools ipcalc + +echo "running kexec" > /dev/kmsg + +kexec --initrd=${INITRD} -l ${VMLINUX} -f --command-line="rancher.debug=true printk.devkmsg=on notsc clocksource=kvm-clock rancher.network.interfaces.eth0.ipv4ll rancher.cloud_init.datasources=[digitalocean] rancher.autologin=tty1 rancher.autologin=ttyS0 rancher.environment.installer=true" From 4a518ebfc9b4347c249c38b0946fa58993d1782b Mon Sep 17 00:00:00 2001 From: Sven Dowideit Date: Tue, 11 Apr 2017 10:19:11 +0000 Subject: [PATCH 2/6] statedir and noformat together to keep base OS Signed-off-by: Sven Dowideit --- cmd/control/install.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/cmd/control/install.go b/cmd/control/install.go index f3e3c737..3da5503c 100755 --- a/cmd/control/install.go +++ b/cmd/control/install.go @@ -55,6 +55,10 @@ var installCommand = cli.Command{ Name: "partition, p", Usage: "partition to install to", }, + cli.StringFlag{ + Name: "statedir", + Usage: "install to rancher.state.directory", + }, cli.BoolFlag{ Name: "force, f", Usage: "[ DANGEROUS! Data loss can happen ] partition/format without prompting", @@ -130,6 +134,10 @@ func installAction(c *cli.Context) error { } device := c.String("device") partition := c.String("partition") + statedir := c.String("statedir") + if statedir != "" && installType != "noformat" { + log.Fatal("--statedir %s requires --type noformat", statedir) + } if installType != "noformat" && installType != "raid" && installType != "bootstrap" && @@ -155,7 +163,7 @@ func installAction(c *cli.Context) error { cloudConfig = uc } - if err := runInstall(image, installType, cloudConfig, device, partition, kappend, force, kexec, isoinstallerloaded, debug); err != nil { + if err := runInstall(image, installType, cloudConfig, device, partition, statedir, kappend, force, kexec, isoinstallerloaded, debug); err != nil { log.WithFields(log.Fields{"err": err}).Fatal("Failed to run install") return err } @@ -168,7 +176,7 @@ func installAction(c *cli.Context) error { return nil } -func runInstall(image, installType, cloudConfig, device, partition, kappend string, force, kexec, isoinstallerloaded, debug bool) error { +func runInstall(image, installType, cloudConfig, device, partition, statedir, kappend string, force, kexec, isoinstallerloaded, debug bool) error { fmt.Printf("Installing from %s\n", image) if !force { @@ -339,7 +347,7 @@ func runInstall(image, installType, cloudConfig, device, partition, kappend stri } } - err := layDownOS(image, installType, cloudConfig, device, partition, kappend, kexec) + err := layDownOS(image, installType, cloudConfig, device, partition, statedir, kappend, kexec) if err != nil { log.Errorf("error layDownOS %s", err) return err @@ -381,7 +389,7 @@ func mountBootIso() error { return err } -func layDownOS(image, installType, cloudConfig, device, partition, kappend string, kexec bool) error { +func layDownOS(image, installType, cloudConfig, device, partition, statedir, kappend string, kexec bool) error { // ENV == installType //[[ "$ARCH" == "arm" && "$ENV" != "upgrade" ]] && ENV=arm @@ -396,6 +404,9 @@ func layDownOS(image, installType, cloudConfig, device, partition, kappend strin baseName := "/mnt/new_img" bootDir := "boot/" kernelArgs := "printk.devkmsg=on rancher.state.dev=LABEL=RANCHER_STATE rancher.state.wait" // console="+CONSOLE + if statedir != "" { + kernelArgs = kernelArgs + " rancher.state.directory="+statedir + } // unmount on trap defer util.Unmount(baseName) @@ -465,6 +476,9 @@ func layDownOS(image, installType, cloudConfig, device, partition, kappend strin return err } installSyslinux(device, baseName, bootDir, diskType) + if err := os.MkdirAll(filepath.Join(baseName, statedir), 0755); err != nil { + return err + } case "raid": var err error device, partition, err = mountdevice(baseName, bootDir, device, partition, false) From 738cfefdbd45a878056aa60d50a27e1d294e0aba Mon Sep 17 00:00:00 2001 From: Sven Dowideit Date: Thu, 13 Apr 2017 01:37:26 +0000 Subject: [PATCH 3/6] make the host.sh script a little easier to use Signed-off-by: Sven Dowideit --- scripts/hosting/digitalocean/host.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/hosting/digitalocean/host.sh b/scripts/hosting/digitalocean/host.sh index 19989811..14034ccc 100755 --- a/scripts/hosting/digitalocean/host.sh +++ b/scripts/hosting/digitalocean/host.sh @@ -14,6 +14,10 @@ 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/artifacts" ]]; then + cd scripts/hosting/digitalocean +fi + if [[ ! -e "$DIST" ]]; then echo "Need to 'make release' so that there are files to serve. Aborting." exit 1 @@ -26,15 +30,23 @@ INITRD="initrd-${VERSION}" IP=$(curl ipinfo.io/ip) PORT=2115 +#SOURCECONFIG="cloud-config.yml" +SOURCECONFIG="fedora-symbiote.yml" CLOUDCONFIG="digitalocean.sh" -cat cloud-config.yml \ +cat ${SOURCECONFIG} \ | 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}" +echo "Usage:" +echo +echo "#include" +echo "http://${IP}:${PORT}/${CLOUDCONFIG}" +echo +echo cd ${DIST} caddy -port ${PORT} From 75f8c5c4ffcada9989b597eb01c9baedeb8bea42 Mon Sep 17 00:00:00 2001 From: Sven Dowideit Date: Thu, 13 Apr 2017 07:36:35 +0000 Subject: [PATCH 4/6] pass on the statedir and partition parameters to the inner installer images Signed-off-by: Sven Dowideit --- cmd/control/install.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/control/install.go b/cmd/control/install.go index 3da5503c..1cb44651 100755 --- a/cmd/control/install.go +++ b/cmd/control/install.go @@ -290,6 +290,12 @@ func runInstall(image, installType, cloudConfig, device, partition, statedir, ka if debug { installerCmd = append(installerCmd, "--debug") } + if partition != "" { + installerCmd = append(installerCmd, "--partition", partition) + } + if statedir != "" { + installerCmd = append(installerCmd, "--statedir", statedir) + } // TODO: mount at /mnt for shared mount? if useIso { From f50e9fc8a53620e60f7612662f9795df1c82c279 Mon Sep 17 00:00:00 2001 From: Sven Dowideit Date: Thu, 13 Apr 2017 09:28:46 +0000 Subject: [PATCH 5/6] remove some fedora files so the smapshots load faster Signed-off-by: Sven Dowideit --- .../hosting/digitalocean/fedora-symbiote.yml | 43 +++++++++++++++---- scripts/hosting/digitalocean/host.sh | 2 +- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/scripts/hosting/digitalocean/fedora-symbiote.yml b/scripts/hosting/digitalocean/fedora-symbiote.yml index 82fdbca5..a0c11e20 100644 --- a/scripts/hosting/digitalocean/fedora-symbiote.yml +++ b/scripts/hosting/digitalocean/fedora-symbiote.yml @@ -1,8 +1,22 @@ #!/bin/bash -ROS_VERSION="v0.9.2-symbiote" -URL_BASE="https://github.com/SvenDowideit/os/releases/download/${ROS_VERSION}" -VMLINUX="vmlinuz-4.9.21-rancher" +# +# This can be invoked either from the commandline of a fedora 25 vm, or as user-data +# either way, the part inside the "if" needs to be run by hand from the console atmA +# +# The most experimental way, is to use the ./scripts/hosting/digitalocean/host.sh script to modify this one for the current build +# push the rancher/os:sha image to hub, and then use +# doctl.exe compute droplet create --enable-ipv6 --enable-private-networking --image fedora-25-x64 --region sfo1 --size 2gb --ssh-keys 6956055 --ssh-keys 7170404 --user-data-file digitalocean.yml sven +# where: +#$ cat digitalocean.yml +##include +#http://:2115/digitalocean.sh +# +# + +ROS_VERSION="v1.0.1-rc1" +URL_BASE="https://github.com/rancher/os/releases/download/${ROS_VERSION}" +VMLINUX="vmlinuz-4.9.22-rancher" INITRD="initrd cd /tmp @@ -11,11 +25,24 @@ curl -O -L "${URL_BASE}/${VMLINUX}" echo "downloading ${URL_BASE}/${INITRD}" > /dev/kmsg curl -O -L "${URL_BASE}/${INITRD}" -if [ "$(ros config get rancher.environment.installer)" == "true" ] && ros --version &>/dev/null; then - ros install -f -c cloud-config.yml -d /dev/vda -p /dev/vda1 \ - --statedir ros -t noformat \ - --append "rancher.state.directory=ros rancher.debug=true printk.devkmsg=on notsc clocksource=kvm-clock rancher.network.interfaces.eth0.ipv4ll rancher.cloud_init.datasources=[digitalocean] rancher.autologin=tty1 rancher.autologin=ttyS0" - exit 0 +if type ros 2>/dev/null; then + if [ "$(ros config get rancher.environment.installer)" == "true" ] && ros --version &>/dev/null; then + # This stuff isn't called automatically atm, need to ru manually + #FIXME removing the grub dir stops `ros os upgrade` from re-installing syslinux, which seems to cause havoc + system-docker run -dit --privileged --name stuff alpine top + system-docker exec -it stuff mount /dev/vda1 /mnt + system-docker exec -it stuff rm -rf /mnt/boot/grub /mnt/boot/*fc25* /mnt/var /mnt/usr /mnt/dev /mnt/proc /mnt/sys /mnt/tmp + system-docker exec -it stuff umount /mnt + system-docker rm -f stuff + + + ros config set rancher.debug true + ros install -f --no-reboot \ + -d /dev/vda -p /dev/vda1 \ + --statedir ros -t noformat \ + --append "rancher.state.dev=LABEL=DOROOT rancher.state.directory=ros rancher.debug=true printk.devkmsg=on notsc clocksource=kvm-clock rancher.network.interfaces.eth0.ipv4ll rancher.cloud_init.datasources=[digitalocean] rancher.autologin=tty1 rancher.autologin=ttyS0" + exit 0 + fi fi echo "installing kexec" > /dev/kmsg diff --git a/scripts/hosting/digitalocean/host.sh b/scripts/hosting/digitalocean/host.sh index 14034ccc..11ffed1e 100755 --- a/scripts/hosting/digitalocean/host.sh +++ b/scripts/hosting/digitalocean/host.sh @@ -49,4 +49,4 @@ echo echo cd ${DIST} -caddy -port ${PORT} +caddy -log stdout -port ${PORT} From 544695d67014d3826c3abc082616d5feb5816d59 Mon Sep 17 00:00:00 2001 From: Sven Dowideit Date: Thu, 13 Apr 2017 11:21:28 +0000 Subject: [PATCH 6/6] go fmt Signed-off-by: Sven Dowideit --- cmd/control/install.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/control/install.go b/cmd/control/install.go index 1cb44651..09ac95d7 100755 --- a/cmd/control/install.go +++ b/cmd/control/install.go @@ -135,7 +135,7 @@ func installAction(c *cli.Context) error { device := c.String("device") partition := c.String("partition") statedir := c.String("statedir") - if statedir != "" && installType != "noformat" { + if statedir != "" && installType != "noformat" { log.Fatal("--statedir %s requires --type noformat", statedir) } if installType != "noformat" && @@ -411,7 +411,7 @@ func layDownOS(image, installType, cloudConfig, device, partition, statedir, kap bootDir := "boot/" kernelArgs := "printk.devkmsg=on rancher.state.dev=LABEL=RANCHER_STATE rancher.state.wait" // console="+CONSOLE if statedir != "" { - kernelArgs = kernelArgs + " rancher.state.directory="+statedir + kernelArgs = kernelArgs + " rancher.state.directory=" + statedir } // unmount on trap