1
0
mirror of https://github.com/rancher/os.git synced 2025-07-04 18:46:15 +00:00

Add build-moby and run-moby to start

Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
Sven Dowideit 2017-05-03 15:40:30 +10:00
parent af965e9446
commit a366336895
10 changed files with 196 additions and 109 deletions

View File

@ -1,4 +1,4 @@
TARGETS := $(shell ls scripts | grep -vE 'clean|run|help|docs|release')
TARGETS := $(shell ls scripts | grep -vE 'clean|run|help|docs|release|moby')
.dapper:
@echo Downloading dapper
@ -28,6 +28,12 @@ run: build/initrd/.id .dapper
docs:
./scripts/docs
build-moby:
./scripts/build-moby
run-moby:
./scripts/run-moby
shell-bind: .dapper
./.dapper -m bind -s

13
scripts/build-moby Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
set -e
cd $(dirname $0)/..
docker build -t zombie/os - < scripts/moby/Dockerfile
cd dist
mkdir -p moby
cd moby
moby build ../../scripts/moby/rancheros

View File

@ -4,3 +4,6 @@ set -e
cd $(dirname $0)/..
rm -rf build dist bin images/*/build state
rm -rf ./scripts/images/openstack/dist
docker rmi $(docker images --format "{{.Repository}}:{{.Tag}}" | grep rancher) || true
docker rmi $(docker images --filter dangling=true -q) ||true

View File

@ -7,117 +7,13 @@ cd $(dirname $0)/..
ARTIFACTS=$(pwd)/dist/artifacts
BUILD=build
INITRD_DIR=${BUILD}/initrd
export ARTIFACTS BUILD INITRD_DIR VERSION
echo Create initrd layout in $INITRD_DIR
rm -rf ${INITRD_DIR}
mkdir -p ${INITRD_DIR}/usr/{etc,lib,bin,share/ros,var/lib/cni/bin}
./scripts/template
cp -rf assets/selinux ${INITRD_DIR}/usr/etc
cp -rf assets/docker ${INITRD_DIR}/usr/etc
cp build/images.tar ${INITRD_DIR}/usr/share/ros/
cp bin/ros ${INITRD_DIR}/usr/bin/
ln -s usr/bin/ros ${INITRD_DIR}/init
ln -s bin ${INITRD_DIR}/usr/sbin
ln -s usr/sbin ${INITRD_DIR}/sbin
ln -s ros ${INITRD_DIR}/usr/bin/system-docker
ln -s ros ${INITRD_DIR}/usr/bin/docker-runc
ln -s ../../../../usr/bin/ros ${INITRD_DIR}/usr/var/lib/cni/bin/bridge
ln -s ../../../../usr/bin/ros ${INITRD_DIR}/usr/var/lib/cni/bin/host-local
cat <<HERE > ${INITRD_DIR}/usr/share/ros/os-release
NAME="RancherOS"
VERSION=${VERSION}
ID=rancheros
ID_LIKE=
VERSION_ID=${VERSION}
PRETTY_NAME="RancherOS ${VERSION}"
HOME_URL="http://rancher.com/rancher-os/"
SUPPORT_URL="https://forums.rancher.com/c/rancher-os"
BUG_REPORT_URL="https://github.com/rancher/os/issues"
BUILD_ID=
HERE
# TODO: usr/lib dir is overwritten by the kernel modules and firmware
ln -s ../share/ros/os-release ${INITRD_DIR}/usr/lib/
# Support upgrades from old persistent consoles that bind mount these
touch ${INITRD_DIR}/usr/bin/docker-containerd
touch ${INITRD_DIR}/usr/bin/docker-containerd-shim
touch ${INITRD_DIR}/usr/bin/docker
# Override using a local kernel build
if [ -e ${DAPPER_SOURCE}/assets/kernel.tar.gz ]; then
echo "copying ${DAPPER_SOURCE}/assets/kernel.tar.gz ${DOWNLOADS}/kernel.tar.gz"
cp ${DAPPER_SOURCE}/assets/kernel.tar.gz ${DOWNLOADS}/kernel.tar.gz
fi
if [ -e ${DOWNLOADS}/kernel.tar.gz ]; then
mkdir -p ${BUILD}/kernel
tar xf ${DOWNLOADS}/kernel.tar.gz -C ${BUILD}/kernel
for i in vmlinuz vmlinux; do
if [ -e ${BUILD}/kernel/boot/${i}-* ]; then
mkdir -p ${ARTIFACTS}
# 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 ${ARTIFACTS}/vmlinuz-${KERNEL_VERSION}"
cp ${BUILD}/kernel/boot/${i}-* ${ARTIFACTS}/vmlinuz-${KERNEL_VERSION}
# use an unversioned filename for `scripts/run`
cp ${BUILD}/kernel/boot/${i}-* ${BUILD}/kernel/vmlinuz
break
fi
done
# TODO: move these into a separate tar.gz and add to the syslinux initrd line
if [ -d ${BUILD}/kernel/lib ]; then
rm -rf ${INITRD_DIR}/usr/lib
cp -rf ${BUILD}/kernel/lib ${INITRD_DIR}/usr/
depmod -b ${INITRD_DIR}/usr $(basename ${INITRD_DIR}/usr/lib/modules/*)
#TODO:
# new: put the kernel modules into their own initrd file
#mkdir -p ${BUILD}/kernel-fs/usr/
#pushd .
#cp -rf ${BUILD}/kernel/lib ${BUILD}/kernel-fs/usr/
#depmod -b ${BUILD}/kernel-fs/usr $(basename ${BUILD}/kernel-fs/usr/lib/modules/*)
## and then package it up cpio
#cd ${BUILD}/kernel-fs/
#echo Creating kernel ${ARTIFACTS}/linuxmods-${KERNEL_VERSION}
#if [ "$COMPRESS" == "" ]; then
# COMPRESS="gzip -1"
#fi
#find | cpio -H newc -o | ${COMPRESS} > ${ARTIFACTS}/linuxmods-${KERNEL_VERSION}
#popd
#echo Done creating kernel ${ARTIFACTS}/linuxmods-${KERNEL_VERSION}
## use an unversioned filename for `scripts/run`
#cp ${ARTIFACTS}/linuxmods-${KERNEL_VERSION} ${BUILD}/kernel/linuxmods
fi
else
if [ "$ARCH" == "amd64" ]; then
echo "no ${DOWNLOADS}/kernel.tar.gz found"
exit 1
fi
fi
if [ "$ARCH" == "amd64" ]; then
ls -lah ${ARTIFACTS}/vmlinuz-*
if [ ! -e "${ARTIFACTS}/vmlinuz-${KERNEL_VERSION}" ]; then
echo "Can't find ${ARTIFACTS}/vmlinuz-${KERNEL_VERSION}"
exit -1
fi
fi
if [ -e ${DOWNLOADS}/policy.29 ]; then
mkdir -p ${INITRD_DIR}/usr/etc/selinux/ros/policy/
cp ${DOWNLOADS}/policy.29 ${INITRD_DIR}/usr/etc/selinux/ros/policy/
fi
./scripts/layout-initrd
./scripts/layout-kernel
DFS_ARCH=$(docker create ${DFS_IMAGE}${SUFFIX})
trap "docker rm -fv ${DFS_ARCH} >/dev/null" EXIT
docker export ${DFS_ARCH} | tar xf - -C ${INITRD_DIR} --exclude=usr/bin/docker* \
--exclude=usr/share/git-core \
--exclude=usr/bin/git \

58
scripts/layout-initrd Executable file
View File

@ -0,0 +1,58 @@
echo Create initrd layout in $INITRD_DIR
rm -rf ${INITRD_DIR}
mkdir -p ${INITRD_DIR}/usr/{etc,lib,bin,share/ros,var/lib/cni/bin}
./scripts/template
cp -rf assets/selinux ${INITRD_DIR}/usr/etc
cp -rf assets/docker ${INITRD_DIR}/usr/etc
cp build/images.tar ${INITRD_DIR}/usr/share/ros/
cp bin/ros ${INITRD_DIR}/usr/bin/
ln -s usr/bin/ros ${INITRD_DIR}/init
ln -s bin ${INITRD_DIR}/usr/sbin
ln -s usr/sbin ${INITRD_DIR}/sbin
ln -s ros ${INITRD_DIR}/usr/bin/system-docker
ln -s ros ${INITRD_DIR}/usr/bin/docker-runc
ln -s ../../../../usr/bin/ros ${INITRD_DIR}/usr/var/lib/cni/bin/bridge
ln -s ../../../../usr/bin/ros ${INITRD_DIR}/usr/var/lib/cni/bin/host-local
cat <<HERE > ${INITRD_DIR}/usr/share/ros/os-release
NAME="RancherOS"
VERSION=${VERSION}
ID=rancheros
ID_LIKE=
VERSION_ID=${VERSION}
PRETTY_NAME="RancherOS ${VERSION}"
HOME_URL="http://rancher.com/rancher-os/"
SUPPORT_URL="https://forums.rancher.com/c/rancher-os"
BUG_REPORT_URL="https://github.com/rancher/os/issues"
BUILD_ID=
HERE
# TODO: usr/lib dir is overwritten by the kernel modules and firmware
ln -s ../share/ros/os-release ${INITRD_DIR}/usr/lib/
# Support upgrades from old persistent consoles that bind mount these
touch ${INITRD_DIR}/usr/bin/docker-containerd
touch ${INITRD_DIR}/usr/bin/docker-containerd-shim
touch ${INITRD_DIR}/usr/bin/docker
if [ -e ${DOWNLOADS}/policy.29 ]; then
mkdir -p ${INITRD_DIR}/usr/etc/selinux/ros/policy/
cp ${DOWNLOADS}/policy.29 ${INITRD_DIR}/usr/etc/selinux/ros/policy/
fi
# make rancher/os-initrd image
cat <<HERE > ${INITRD_DIR}/../Dockerfile.initrd
FROM scratch
COPY initrd/* /
HERE
name="os-initrd"
tag="${OS_REPO}/${name}:${VERSION}${SUFFIX}"
pushd .
cd ${INITRD_DIR}/..
docker build -t ${OS_REPO}/${name} -f Dockerfile.initrd .
docker tag rancher/${name} ${tag}
popd

66
scripts/layout-kernel Executable file
View File

@ -0,0 +1,66 @@
#!/bin/bash
set -e
# Override using a local kernel build
if [ -e ${DAPPER_SOURCE}/assets/kernel.tar.gz ]; then
echo "copying ${DAPPER_SOURCE}/assets/kernel.tar.gz ${DOWNLOADS}/kernel.tar.gz"
cp ${DAPPER_SOURCE}/assets/kernel.tar.gz ${DOWNLOADS}/kernel.tar.gz
fi
if [ -e ${DOWNLOADS}/kernel.tar.gz ]; then
mkdir -p ${BUILD}/kernel
tar xf ${DOWNLOADS}/kernel.tar.gz -C ${BUILD}/kernel
for i in vmlinuz vmlinux; do
if [ -e ${BUILD}/kernel/boot/${i}-* ]; then
mkdir -p ${ARTIFACTS}
# 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 ${ARTIFACTS}/vmlinuz-${KERNEL_VERSION}"
cp ${BUILD}/kernel/boot/${i}-* ${ARTIFACTS}/vmlinuz-${KERNEL_VERSION}
# use an unversioned filename for `scripts/run`
cp ${BUILD}/kernel/boot/${i}-* ${BUILD}/kernel/vmlinuz
break
fi
done
# TODO: move these into a separate tar.gz and add to the syslinux initrd line
if [ -d ${BUILD}/kernel/lib ]; then
rm -rf ${INITRD_DIR}/usr/lib
cp -rf ${BUILD}/kernel/lib ${INITRD_DIR}/usr/
depmod -b ${INITRD_DIR}/usr $(basename ${INITRD_DIR}/usr/lib/modules/*)
#TODO:
# new: put the kernel modules into their own initrd file
#mkdir -p ${BUILD}/kernel-fs/usr/
#pushd .
#cp -rf ${BUILD}/kernel/lib ${BUILD}/kernel-fs/usr/
#depmod -b ${BUILD}/kernel-fs/usr $(basename ${BUILD}/kernel-fs/usr/lib/modules/*)
## and then package it up cpio
#cd ${BUILD}/kernel-fs/
#echo Creating kernel ${ARTIFACTS}/linuxmods-${KERNEL_VERSION}
#if [ "$COMPRESS" == "" ]; then
# COMPRESS="gzip -1"
#fi
#find | cpio -H newc -o | ${COMPRESS} > ${ARTIFACTS}/linuxmods-${KERNEL_VERSION}
#popd
#echo Done creating kernel ${ARTIFACTS}/linuxmods-${KERNEL_VERSION}
## use an unversioned filename for `scripts/run`
#cp ${ARTIFACTS}/linuxmods-${KERNEL_VERSION} ${BUILD}/kernel/linuxmods
fi
else
if [ "$ARCH" == "amd64" ]; then
echo "no ${DOWNLOADS}/kernel.tar.gz found"
exit 1
fi
fi
if [ "$ARCH" == "amd64" ]; then
ls -lah ${ARTIFACTS}/vmlinuz-*
if [ ! -e "${ARTIFACTS}/vmlinuz-${KERNEL_VERSION}" ]; then
echo "Can't find ${ARTIFACTS}/vmlinuz-${KERNEL_VERSION}"
exit -1
fi
fi

20
scripts/moby/Dockerfile Normal file
View File

@ -0,0 +1,20 @@
FROM rancher/os
# replace this with `rancher/os-initrd`
RUN mkdir /tmp/initrd \
&& cd /tmp/initrd \
&& cat /dist/initrd-* | gunzip | cpio -i \
&& rm -rf usr/lib \
&& rm /tmp/initrd/usr/var/lib/cni/bin/host-local /tmp/initrd/usr/var/lib/cni/bin/bridge \
&& mkdir -p /tmp/initrd/var/lib/cni/bin \
&& ln -s ../../../../usr/bin/ros /tmp/initrd/var/lib/cni/bin/host-local \
&& ln -s ../../../../usr/bin/ros /tmp/initrd/var/lib/cni/bin/bridge \
&& cp -r --update --dereference --force /tmp/initrd/* / \
&& cd / \
&& rm -rf /tmp/initrd
#FROM rancher/os-installer
#RUN cp /bin/ros /init
#FROM rancher/os-installer
#RUN cp /bin/ros /init

View File

@ -0,0 +1,13 @@
kernel:
image: "linuxkit/kernel:4.9.x"
# cmdline: "debug ignore_loglevel log_buf_len=10M print_fatal_signals=1 LOGLEVEL=8 earlyprintk sched_debug initcall_debug option.debug=Y break=y console=ttyS0 console=tty0 console=tty1 page_poison=1 printk.devkmsg=on rancher.debug=true rancher.password=rancher rancher.autologin=ttyS0 rancher.autologin=tty0 rancher.autologin=tty1"
cmdline: 'printk.devkmsg=on rancher.debug=true rancher.password=rancher console=ttyS0 rancher.autologin=ttyS0 console=tty0 rancher.autologin=tty0 console=tty1 rancher.autologin=tty1 rancher.state.dev=LABEL=RANCHER_STATE rancher.state.autoformat=[/dev/sda,/dev/vda] rancher.rm_usr'
init:
- zombie/os
# - rancher/os-installer
# - rancher/os-initrd
outputs:
- format: kernel+initrd
- format: iso-bios
# - format: iso-efi
# - format: gcp-img

View File

@ -62,8 +62,9 @@ cp -r ${DIST}/boot/* ./scripts/installer/build/boot
cp $DOCKERFILE ./scripts/installer/build/Dockerfile
# Full installer image with initrd - used for pulling from network
docker build \
-t ${OS_REPO}/os:${VERSION}${SUFFIX} \
-t ${OS_REPO}/os \
./scripts/installer/build
docker tag ${OS_REPO}/os ${OS_REPO}/os:${VERSION}${SUFFIX}
docker save -o ${ARTIFACTS}/fullinstaller.tar ${OS_REPO}/os:${VERSION}${SUFFIX}
echo ${OS_REPO}/os:${VERSION}${SUFFIX} >> dist/images

11
scripts/run-moby Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
cd $(dirname $0)/../dist/moby
qemu-system-x86_64 \
-nographic \
-kernel ./rancheros-kernel \
-initrd ./rancheros-initrd.img \
-m 2048 \
-net nic,vlan=0,model=virtio \
-net user,vlan=0,hostfwd=tcp::3333-:22,hostname=rancher-moby \
-append 'printk.devkmsg=on rancher.debug=true rancher.password=rancher console=ttyS0 rancher.autologin=ttyS0 console=tty0 rancher.autologin=tty0 console=tty1 rancher.autologin=tty1 rancher.state.dev=LABEL=RANCHER_STATE rancher.state.autoformat=[/dev/sda,/dev/vda] rancher.rm_usr'