1
0
mirror of https://github.com/rancher/os.git synced 2025-08-01 23:17:50 +00:00

make the iso run also get the ssh and cloud-init so testing the installer is easier

Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
Sven Dowideit 2016-12-04 21:27:06 +10:00
parent 087bc6fd2d
commit cc78ff7bd1
13 changed files with 155 additions and 78 deletions

View File

@ -10,6 +10,7 @@ RUN apt-get update && \
dosfstools \
gccgo \
genisoimage \
gettext \
git \
isolinux \
less \
@ -34,7 +35,7 @@ RUN apt-get update && \
ENV DAPPER_ENV VERSION DEV_BUILD RUNTEST
ENV DAPPER_DOCKER_SOCKET true
ENV DAPPER_SOURCE /go/src/github.com/rancher/os
ENV DAPPER_OUTPUT ./bin ./dist ./build/initrd
ENV DAPPER_OUTPUT ./bin ./dist ./build/initrd ./build/kernel
ENV DAPPER_RUN_ARGS --privileged
ENV TRASH_CACHE ${DAPPER_SOURCE}/.trash-cache
ENV SHELL /bin/bash
@ -55,7 +56,8 @@ ARG DOCKER_BUILD_VERSION=1.10.3
ARG DOCKER_BUILD_PATCH_VERSION=v${DOCKER_BUILD_VERSION}-ros1
ARG SELINUX_POLICY_URL=https://github.com/rancher/refpolicy/releases/download/v0.0.3/policy.29
ARG KERNEL_URL_amd64=https://github.com/rancher/os-kernel/releases/download/v4.9-rancher2/linux-4.9-rancher2-x86.tar.gz
ARG KERNEL_VERSION_amd64=4.9.3-rancher
ARG KERNEL_URL_amd64=https://github.com/rancher/os-kernel/releases/download/v${KERNEL_VERSION_amd64}/linux-${KERNEL_VERSION_amd64}-x86.tar.gz
ARG KERNEL_URL_arm64=https://github.com/imikushin/os-kernel/releases/download/Estuary-4.4.0-arm64.8/linux-4.4.0-rancher-arm64.tar.gz
ARG DOCKER_URL_amd64=https://get.docker.com/builds/Linux/x86_64/docker-${DOCKER_VERSION}.tgz
@ -100,6 +102,7 @@ ENV BUILD_DOCKER_URL=BUILD_DOCKER_URL_${ARCH} \
GOARCH=$ARCH \
HOSTNAME_DEFAULT=${HOSTNAME_DEFAULT} \
IMAGE_NAME=${IMAGE_NAME} \
KERNEL_VERSION=${KERNEL_VERSION_amd64} \
KERNEL_URL=KERNEL_URL_${ARCH} \
KERNEL_URL_amd64=${KERNEL_URL_amd64} \
KERNEL_URL_arm64=${KERNEL_URL_arm64} \
@ -119,7 +122,8 @@ RUN mkdir -p ${DOWNLOADS}
# Download kernel
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN if [ -n "${!KERNEL_URL}" ]; then \
RUN echo "... Downloading ${!KERNEL_URL}"; \
if [ -n "${!KERNEL_URL}" ]; then \
curl -fL ${!KERNEL_URL} > ${DOWNLOADS}/kernel.tar.gz \
;fi

View File

@ -189,10 +189,6 @@ func runInstall(image, installType, cloudConfig, device, kappend string, force,
"install",
"-t", installType,
"-d", device,
// "-f", strconv.FormatBool(force),
// "--no-reboot", strconv.FormatBool(!reboot),
// "-c", `"`+cloudConfig+`"`,
// "-a", `"`+kappend+`"`
}
if force {
installerCmd = append(installerCmd, "-f")
@ -280,9 +276,11 @@ func layDownOS(image, installType, cloudConfig, device, kappend string) error {
log.Errorf("%s", err)
return err
}
log.Infof("defer")
log.Infof("installGrub")
err = installGrub(baseName, device)
//log.Infof("installGrub")
//err = installGrub(baseName, device)
log.Infof("installSyslinux")
err = installSyslinux(device, baseName, bootDir)
if err != nil {
log.Errorf("%s", err)
return err
@ -529,6 +527,7 @@ p
1
a
w
`))
w.Close()
@ -566,7 +565,8 @@ func formatdevice(device, partition string) error {
log.Debugf("formatdevice %s", partition)
//mkfs.ext4 -F -i 4096 -L RANCHER_STATE ${partition}
cmd := exec.Command("mkfs.ext4", "-F", "-i", "4096", "-L", "RANCHER_STATE", partition)
// -O ^64bit: for syslinux: http://www.syslinux.org/wiki/index.php?title=Filesystem#ext
cmd := exec.Command("mkfs.ext4", "-F", "-i", "4096", "-O", "^64bit", "-L", "RANCHER_STATE", partition)
log.Debugf("Run(%v)", cmd)
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
if err := cmd.Run(); err != nil {
@ -645,21 +645,33 @@ func installSyslinux(device, baseName, bootDir string) error {
log.Debugf("installSyslinux")
//dd bs=440 count=1 if=/usr/lib/syslinux/mbr/mbr.bin of=${device}
cmd := exec.Command("dd", "bs=440", "count=1", "if=/usr/lib/syslinux/mbr/mbr.bin", "of="+device)
// ubuntu: /usr/lib/syslinux/mbr/mbr.bin
// alpine: /usr/share/syslinux/mbr.bin
cmd := exec.Command("dd", "bs=440", "count=1", "if=/usr/share/syslinux/mbr.bin", "of="+device)
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
log.Debugf("Run(%v)", cmd)
if err := cmd.Run(); err != nil {
log.Printf("%s", err)
log.Printf("dd: %s", err)
return err
}
//cp /usr/lib/syslinux/modules/bios/* ${baseName}/${bootDir}syslinux
cmd = exec.Command("sh", "-c", "cp", "/usr/lib/syslinux/modules/bios/*", filepath.Join(baseName, bootDir+"syslinux"))
if err := cmd.Run(); err != nil {
log.Printf("%s", err)
return err
files, _ := ioutil.ReadDir("/usr/share/syslinux/")
for _, file := range files {
if file.IsDir() {
continue
}
if err := dfs.CopyFile(filepath.Join("/usr/share/syslinux/", file.Name()), filepath.Join(baseName, bootDir, "syslinux"), file.Name()); err != nil {
log.Errorf("copy syslinux: %s", err)
return err
}
}
//extlinux --install ${baseName}/${bootDir}syslinux
cmd = exec.Command("extlinux", "--install", filepath.Join(baseName, bootDir+"syslinux"))
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
log.Debugf("Run(%v)", cmd)
if err := cmd.Run(); err != nil {
log.Printf("%s", err)
log.Printf("extlinuux: %s", err)
return err
}
return nil
@ -672,20 +684,26 @@ func installSyslinuxRaid(baseName, bootDir string) error {
//dd bs=440 count=1 if=/usr/lib/syslinux/mbr/mbr.bin of=/dev/sdb
//cp /usr/lib/syslinux/modules/bios/* ${baseName}/${bootDir}syslinux
//extlinux --install --raid ${baseName}/${bootDir}syslinux
cmd := exec.Command("dd", "bs=440", "count=1", "if=/usr/lib/syslinux/mbr/mbr.bin", "of=/dev/sda")
cmd := exec.Command("dd", "bs=440", "count=1", "if=/usr/share/syslinux/mbr.bin", "of=/dev/sda")
if err := cmd.Run(); err != nil {
log.Printf("%s", err)
return err
}
cmd = exec.Command("dd", "bs=440", "count=1", "if=/usr/lib/syslinux/mbr/mbr.bin", "of=/dev/sdb")
cmd = exec.Command("dd", "bs=440", "count=1", "if=/usr/share/syslinux/mbr.bin", "of=/dev/sdb")
if err := cmd.Run(); err != nil {
log.Printf("%s", err)
return err
}
cmd = exec.Command("sh", "-c", "cp", "/usr/lib/syslinux/modules/bios/*", filepath.Join(baseName, bootDir+"syslinux"))
if err := cmd.Run(); err != nil {
log.Printf("%s", err)
return err
//cp /usr/lib/syslinux/modules/bios/* ${baseName}/${bootDir}syslinux
files, _ := ioutil.ReadDir("/usr/share/syslinux/")
for _, file := range files {
if file.IsDir() {
continue
}
if err := dfs.CopyFile(filepath.Join("/usr/share/syslinux/", file.Name()), filepath.Join(baseName, bootDir, "syslinux"), file.Name()); err != nil {
log.Errorf("copy syslinux: %s", err)
return err
}
}
cmd = exec.Command("extlinux", "--install", filepath.Join(baseName, bootDir+"syslinux"))
if err := cmd.Run(); err != nil {
@ -784,13 +802,13 @@ func installRancher(baseName, bootDir, VERSION, DIST string) error {
log.Debugf("installRancher")
//cp ${DIST}/initrd ${baseName}/${bootDir}initrd-${VERSION}-rancheros
if err := dfs.CopyFile(DIST+"/initrd", baseName, bootDir+"initrd-"+VERSION+"-rancheros"); err != nil {
if err := dfs.CopyFile(DIST+"/initrd", filepath.Join(baseName, bootDir), "initrd-"+VERSION+"-rancheros"); err != nil {
log.Errorf("copy initrd: ", err)
return err
}
//cp ${DIST}/vmlinuz ${baseName}/${bootDir}vmlinuz-${VERSION}-rancheros
if err := dfs.CopyFile(DIST+"/vmlinuz", baseName, bootDir+"vmlinuz-"+VERSION+"-rancheros"); err != nil {
if err := dfs.CopyFile(DIST+"/vmlinuz", filepath.Join(baseName, bootDir), "vmlinuz-"+VERSION+"-rancheros"); err != nil {
log.Errorf("copy vmlinuz: %s", err)
return err
}

View File

@ -71,7 +71,6 @@ func loadModules(cfg *config.CloudConfig) (*config.CloudConfig, error) {
}
func sysInit(c *config.CloudConfig) (*config.CloudConfig, error) {
showMounts("sysInit")
args := append([]string{config.SysInitBin}, os.Args[1:]...)
cmd := &exec.Cmd{
@ -225,12 +224,10 @@ func RunInit() error {
var metadataFile []byte
initFuncs := []config.CfgFunc{
func(c *config.CloudConfig) (*config.CloudConfig, error) {
showMounts("dfs.PrepareFs")
return c, dfs.PrepareFs(&mountConfig)
},
mountOem,
func(_ *config.CloudConfig) (*config.CloudConfig, error) {
showMounts("showconfig")
cfg := config.LoadConfig()
if cfg.Rancher.Debug {
@ -246,7 +243,6 @@ func RunInit() error {
},
loadModules,
func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
showMounts("read B2D_STATE")
if util.ResolveDevice("LABEL=B2D_STATE") != "" {
boot2DockerEnvironment = true
cfg.Rancher.State.Dev = "LABEL=B2D_STATE"
@ -274,7 +270,6 @@ func RunInit() error {
return cfg, nil
},
func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
showMounts("tryMountAndBootstrap")
var err error
cfg, shouldSwitchRoot, err = tryMountAndBootstrap(cfg)
if err != nil {
@ -283,7 +278,6 @@ func RunInit() error {
return cfg, nil
},
func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
showMounts("cloudinit")
if err := os.MkdirAll(config.CloudConfigDir, os.ModeDir|0755); err != nil {
log.Error(err)
}
@ -319,7 +313,6 @@ func RunInit() error {
return cfg, nil
},
func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
showMounts("readconfig")
var err error
cloudConfigBootFile, err = ioutil.ReadFile(config.CloudConfigBootFile)
if err != nil {
@ -332,7 +325,6 @@ func RunInit() error {
return cfg, nil
},
func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
showMounts("switchroot")
if !shouldSwitchRoot {
return cfg, nil
}
@ -344,7 +336,6 @@ func RunInit() error {
},
mountOem,
func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
showMounts("write meta")
if err := os.MkdirAll(config.CloudConfigDir, os.ModeDir|0755); err != nil {
log.Error(err)
}
@ -357,7 +348,6 @@ func RunInit() error {
return cfg, nil
},
func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
showMounts("set sate")
if boot2DockerEnvironment {
if err := config.Set("rancher.state.dev", cfg.Rancher.State.Dev); err != nil {
log.Errorf("Failed to update rancher.state.dev: %v", err)
@ -370,12 +360,10 @@ func RunInit() error {
return config.LoadConfig(), nil
},
func(c *config.CloudConfig) (*config.CloudConfig, error) {
showMounts("preparefs2")
return c, dfs.PrepareFs(&mountConfig)
},
loadModules,
func(c *config.CloudConfig) (*config.CloudConfig, error) {
showMounts("setproxy")
network.SetProxyEnvironmentVariables(c)
return c, nil
},
@ -400,12 +388,3 @@ func RunInit() error {
return pidOne()
}
func showMounts(msg string) {
mounts, err := ioutil.ReadFile("/proc/mounts")
if err != nil {
log.Infof("+++++++++ showMounts(%s) ERROR: %s", msg, err)
} else {
log.Infof("+++++++++ showMounts(%s) %s", msg, mounts)
}
}

View File

@ -1,13 +1,17 @@
FROM ubuntu:16.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get install --no-install-recommends -y udev grub2 parted kexec-tools extlinux syslinux-common && \
rm -rf /var/lib/apt/*
FROM rancher/os-alpineconsole
# TODO: redo as cross platform
COPY ./build/vmlinuz ./build/initrd /dist/
COPY conf ./build/ros /scripts/
# not installed atm udev, grub2, kexe-toos
# parted: partprobe, e2fsprogs: mkfs.ext4, syslinux: extlinux&syslinux
RUN apk --no-cache add syslinux parted e2fsprogs
COPY conf /scripts/
ARG VERSION
ARG KERNEL_VERSION
ENV VERSION=${VERSION}
ENV KERNEL_VERSION=${KERNEL_VERSION}
# TODO: separate out the 3 elements below - so we can mix and match updates
COPY ./build/vmlinuz-${KERNEL_VERSION} ./build/initrd ./build/ros /dist/
ENTRYPOINT ["/scripts/ros"]

View File

@ -1,5 +1,5 @@
default rancheros
label rancheros
kernel /boot/vmlinuz
kernel /boot/vmlinuz-${KERNEL_VERSION}
initrd /boot/initrd
append quiet rancher.autologin=tty1 rancher.autologin=ttyS0

View File

@ -44,7 +44,11 @@ if [ -e ${DOWNLOADS}/kernel.tar.gz ]; then
for i in vmlinuz vmlinux; do
if [ -e ${BUILD}/kernel/boot/${i}-* ]; then
mkdir -p dist/artifacts
cp ${BUILD}/kernel/boot/${i}-* dist/artifacts/vmlinuz
# frustratingly, the vmlinuz versioned filename != the tag name, so we need to do some guessing
# for eg, 4.9-rc8-rancher2 is called vmlinuz-4.9.0-rc8-rancher
echo "Copy ${BUILD}/kernel/boot/${i}-* to dist/artifacts/vmlinuz-${KERNEL_VERSION}"
cp ${BUILD}/kernel/boot/${i}-* "dist/artifacts/vmlinuz-${KERNEL_VERSION}"
cp ${BUILD}/kernel/boot/${i}-* ${BUILD}/kernel/vmlinuz
break
fi
done
@ -54,6 +58,15 @@ if [ -e ${DOWNLOADS}/kernel.tar.gz ]; then
cp -rf ${BUILD}/kernel/lib ${INITRD_DIR}/usr/
depmod -b ${INITRD_DIR}/usr $(basename ${INITRD_DIR}/usr/lib/modules/*)
fi
else
echo "no ${DOWNLOADS}/kernel.tar.gz found"
exit 1
fi
ls -lah dist/artifacts/vmlinuz-*
if [ ! -e "dist/artifacts/vmlinuz-${KERNEL_VERSION}" ]; then
echo "Can't find dist/artifacts/vmlinuz-${KERNEL_VERSION}"
exit -1
fi
if [ -e ${DOWNLOADS}/policy.29 ]; then

View File

@ -10,7 +10,7 @@ INITRD=${ARTIFACTS}/initrd
mkdir -p ${ARTIFACTS}
if [ ! -f ${ARTIFACTS}/vmlinuz ]; then
if [ ! -f ${ARTIFACTS}/vmlinuz-${KERNEL_VERSION} ]; then
exit 0
fi

View File

@ -7,16 +7,22 @@ source ./scripts/version
DOCKERFILE=./scripts/installer/Dockerfile.${ARCH}
if [ ! -f $DOCKERFILE ] || [ ! -f dist/artifacts/vmlinuz ] || [ ! -f dist/artifacts/initrd ]; then
if [ ! -f $DOCKERFILE ] || [ ! -f dist/artifacts/vmlinuz-${KERNEL_VERSION} ] || [ ! -f dist/artifacts/initrd ]; then
exit 0
fi
mkdir -p ./scripts/installer/build
cp ./dist/artifacts/{initrd,vmlinuz} ./scripts/installer/build
cp ./dist/artifacts/initrd ./scripts/installer/build
cp ./dist/artifacts/vmlinuz-${KERNEL_VERSION} ./scripts/installer/build
cp ./bin/ros ./scripts/installer/build
trap "rm -rf ./scripts/installer/build" EXIT
docker build -t ${OS_REPO}/os:${VERSION}${SUFFIX} --build-arg VERSION=${VERSION} -f $DOCKERFILE ./scripts/installer
docker build \
-t ${OS_REPO}/os:${VERSION}${SUFFIX} \
--build-arg VERSION=${VERSION} \
--build-arg KERNEL_VERSION=${KERNEL_VERSION} \
-f $DOCKERFILE \
./scripts/installer
docker save -o dist/artifacts/installer.tar ${OS_REPO}/os:${VERSION}${SUFFIX}
echo ${OS_REPO}/os:${VERSION}${SUFFIX} >> dist/images
echo Built ${OS_REPO}/os:${VERSION}${SUFFIX}

View File

@ -13,13 +13,13 @@ CHECKSUM=iso-checksums.txt
mkdir -p ${CD}/boot/isolinux
mkdir -p ${CD}/rancheros
if [ ! -f ${ARTIFACTS}/vmlinuz ] || [ ! -f ${ARTIFACTS}/initrd ]; then
if [ ! -f ${ARTIFACTS}/vmlinuz-${KERNEL_VERSION} ] || [ ! -f ${ARTIFACTS}/initrd ]; then
exit 0
fi
cp ${ARTIFACTS}/initrd ${CD}/boot
cp ${ARTIFACTS}/vmlinuz ${CD}/boot
cp scripts/isolinux.cfg ${CD}/boot/isolinux
cp ${ARTIFACTS}/vmlinuz-${KERNEL_VERSION} ${CD}/boot
cat scripts/isolinux.cfg | envsubst > ${CD}/boot/isolinux/isolinux.cfg
cp /usr/lib/ISOLINUX/isolinux.bin ${CD}/boot/isolinux
cp /usr/lib/syslinux/modules/bios/ldlinux.c32 ${CD}/boot/isolinux
# add the installer image to the iso for non-network / dev/test

View File

@ -125,8 +125,7 @@ if [ "$QEMU" == "1" ] || [ "$BOOT_ISO" == "1" ]; then
fi
fi
if [ "$QEMU" == "1" ]; then
if [ "$QIND" != "1" ]; then
CCROOT=${BUILD}/cloud-config
rm -rf ${CCROOT}
mkdir -p ${CCROOT}
@ -143,6 +142,10 @@ if [ "$QEMU" == "1" ]; then
fi
HOME=${HOME:-/}
fi
if [ "$QEMU" == "1" ]; then
if [ "$INSTALLED" == "1" ]; then
# kernel args only works when using -kernel
KERNEL_ARGS=""
@ -185,6 +188,10 @@ elif [ "$BOOT_ISO" == "1" ]; then
$(eval "${hd["$ARCH"]} ${HD}") \
${SECOND_DRIVE_ENABLE} \
-smp 1 \
-fsdev local,security_model=passthrough,readonly,id=fsdev0,path=${CCROOT} \
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=config-2 \
-fsdev local,security_model=none,id=fsdev1,path=${HOME} \
-device virtio-9p-pci,id=fs1,fsdev=fsdev1,mount_tag=home \
-boot d \
-cdrom ./dist/artifacts/rancheros.iso
elif [ "$QIND" == "1" ]; then

View File

@ -34,7 +34,8 @@ BUILD=build
BASE=$(pwd)
UNAME=$(uname)
KERNEL=${BASE}/dist/artifacts/vmlinuz
#KERNEL=${BASE}/dist/artifacts/vmlinuz-${KERNEL_VERSION}*
KERNEL=${BASE}/build/kernel/vmlinuz
INITRD_SRC=${BASE}/build/initrd
INITRD=${BASE}/build/initrd.tmp

View File

@ -46,29 +46,37 @@ func (s *QemuSuite) TearDownTest(c *C) {
time.Sleep(time.Millisecond * 1000)
}
func (s *QemuSuite) RunQemu(c *C, additionalArgs ...string) {
runArgs := []string{
"--qemu",
"--no-rebuild",
"--no-rm-usr",
"--fresh",
}
runArgs = append(runArgs, additionalArgs...)
// RunQemuWith requires user to specify all the `scripts/run` arguments
func (s *QemuSuite) RunQemuWith(c *C, additionalArgs ...string) error {
c.Assert(s.runQemu(runArgs...), IsNil)
err := s.runQemu(additionalArgs...)
c.Assert(err, IsNil)
return err
}
func (s *QemuSuite) RunQemuInstalled(c *C, additionalArgs ...string) {
func (s *QemuSuite) RunQemu(c *C, additionalArgs ...string) error {
runArgs := []string{
"--qemu",
"--no-rebuild",
"--no-rm-usr",
"--installed",
"--fresh",
}
runArgs = append(runArgs, additionalArgs...)
c.Assert(s.runQemu(runArgs...), IsNil)
err := s.RunQemuWith(c, runArgs...)
c.Assert(err, IsNil)
return err
}
func (s *QemuSuite) RunQemuInstalled(c *C, additionalArgs ...string) error {
runArgs := []string{
"--fresh",
}
runArgs = append(runArgs, additionalArgs...)
err := s.RunQemu(c, runArgs...)
c.Assert(err, IsNil)
return err
}
func (s *QemuSuite) runQemu(args ...string) error {
@ -136,6 +144,14 @@ func (s *QemuSuite) CheckCall(c *C, additionalArgs ...string) {
c.Assert(s.MakeCall(additionalArgs...), IsNil)
}
func (s *QemuSuite) Stop(c *C) {
//s.MakeCall("sudo halt")
//time.Sleep(2000 * time.Millisecond)
//c.Assert(s.WaitForSSH(), IsNil)
c.Assert(s.qemuCmd.Process.Kill(), IsNil)
time.Sleep(time.Millisecond * 1000)
}
func (s *QemuSuite) Reboot(c *C) {
s.MakeCall("sudo reboot")
time.Sleep(3000 * time.Millisecond)

29
tests/installer_test.go Normal file
View File

@ -0,0 +1,29 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestInstall(c *C) {
// ./scripts/run --no-format --append "rancher.debug=true" --iso --fresh
runArgs := []string{
"--iso",
"--fresh",
"--no-format",
"--append", "rancher.debug=true",
}
s.RunQemuWith(c, runArgs...)
s.CheckCall(c, `
set -ex
sudo ros install --force --no-reboot --device /dev/vda`)
s.Stop(c)
// ./scripts/run --no-format --append "rancher.debug=true"
runArgs = []string{
"--no-format",
"--append", "rancher.debug=true",
}
s.RunQemuWith(c, runArgs...)
s.CheckCall(c, "sudo ros -v")
}