Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #490 from imikushin/installer
Browse files Browse the repository at this point in the history
build rancher/os docker image together with iso
  • Loading branch information
imikushin committed Aug 14, 2015
2 parents cec7699 + f1c7aa3 commit 74a7c0a
Show file tree
Hide file tree
Showing 14 changed files with 290 additions and 8 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
.git
.idea
.dockerignore
bin
gopath
tmp
Expand Down
11 changes: 11 additions & 0 deletions .dockerignore.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.DS_Store
.git
.idea
.dockerignore
bin
gopath
tmp
state
build
assets
Godeps/_workspace/pkg
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
FROM ros-build-base
FROM debian:jessie
COPY ./scripts/installer /scripts
COPY ./scripts/version /scripts/
RUN /scripts/bootstrap

ENV CONTAINED=1
COPY ./dist/artifacts/vmlinuz /dist/vmlinuz
COPY ./dist/artifacts/initrd /dist/initrd

COPY . ./
ENTRYPOINT ["/scripts/lay-down-os"]
4 changes: 4 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM ros-build-base

COPY . ./
COPY .dockerignore.docker .dockerignore
File renamed without changes.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ all: clean ros-build-base build-all


ros-build-base:
docker build -t ros-build-base -f Dockerfile.base .
docker build -t ros-build-base -f Dockerfile.build-base .


ros-build-image:
docker build -t ros-build .
docker build -t ros-build -f Dockerfile.build .


bin/rancheros: ros-build-image
Expand Down
5 changes: 4 additions & 1 deletion Makefile.docker
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ $(DIST)/artifacts/iso-checksums.txt: $(DIST)/artifacts/rancheros.iso
version:
@echo $(VERSION)

installer: $(DIST)/artifacts/initrd $(DIST)/artifacts/vmlinuz
docker build -t rancher/os:$(VERSION) .

build-all: \
installer \
bin/rancheros \
$(DIST)/artifacts/initrd \
$(DIST)/artifacts/vmlinuz \
$(DIST)/artifacts/rancheros.iso \
$(DIST)/artifacts/iso-checksums.txt


.PHONY: build-all version bin/rancheros
.PHONY: build-all installer version bin/rancheros
4 changes: 2 additions & 2 deletions scripts/ci
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ if [ -x "$(which wrapdocker)" ] && ! docker info >/dev/null 2>&1; then
wrapdocker
fi

docker build -t ros-build-base -f Dockerfile.base .
docker build -t ros-build .
docker build -t ros-build-base -f Dockerfile.build-base .
docker build -t ros-build -f Dockerfile.build .
./scripts/docker-run.sh make -f Makefile.docker build-all
6 changes: 6 additions & 0 deletions scripts/installer/bootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

export DEBIAN_FRONTEND=noninteractive

apt-get update
apt-get install -y grub2 parted
4 changes: 4 additions & 0 deletions scripts/installer/conf/cloud-config-local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rancher:
cloud_init:
datasources:
- file:/var/lib/rancher/conf/user_config.yml
3 changes: 3 additions & 0 deletions scripts/installer/conf/vagrant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#cloud-config
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
181 changes: 181 additions & 0 deletions scripts/installer/lay-down-os
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
#!/bin/bash
set -e -x

. $(dirname $0)/version

while getopts "i:f:c:d:t:r:o:p:" OPTION
do
case $OPTION in
i) DIST="$OPTARG" ;;
f) FILES="$OPTARG" ;;
c) CLOUD_CONFIG="$OPTARG" ;;
d) DEVICE="$OPTARG" ;;
o) OEM="$OPTARG" ;;
p) PARTITION="$OPTARG" ;;
r) ROLLBACK_VERSION="$OPTARG" ;;
t) ENV="$OPTARG" ;;
*) exit 1 ;;
esac
done

DIST=${DIST:-/dist}
BASE_DIR="/mnt/new_img"
# TODO: Change this to a number so that users can specify.
# Will need to make it so that our builds and packer APIs remain consistent.
PARTITION=${PARTITION:=${DEVICE}1}

device_defined()
{
if [[ -z "$1" ]]; then
echo "Need to Pass a device name -d <dev>." 1>&2
exit 1
fi
}

format_device()
{
device_defined ${DEVICE}
mkfs.ext4 -F -i 4096 -L RANCHER_STATE ${PARTITION}
}

mount_device()
{
local label=RANCHER_STATE
local raw="${1:-false}"

mkdir -p ${BASE_DIR}

if [ "$(lsblk -o name|grep RANCHER_BOOT | wc -l)" -eq "1" ]; then
label=RANCHER_BOOT
fi

local mount_opts="-L ${label}"
if [ "${raw}" == "true" ]; then
device_defined ${DEVICE}
mount_opts=${PARTITION}
fi

mount $mount_opts ${BASE_DIR}
trap "umount ${BASE_DIR}" EXIT
}

create_boot_dirs()
{
mkdir -p ${BASE_DIR}/boot/grub
}

install_grub() {
grub-install --boot-directory=${BASE_DIR}/boot ${DEVICE}
}

grub2_config(){
local grub_cfg=${BASE_DIR}/boot/grub/grub.cfg
local append_line="${1}"
cat >$grub_cfg <<EOF
set default="0"
set timeout="1"
#set fallback=1
menuentry "RancherOS-current" {
set root=(hd0,msdos1)
linux /boot/vmlinuz-${VERSION}-rancheros ${append_line} console=tty0 console=ttyS0
initrd /boot/initrd-${VERSION}-rancheros
}
EOF

if [ ! -z $ROLLBACK_VERSION ]; then
sed -i 's/^#set/set/' ${grub_cfg}
cat >>$grub_cfg <<EOF
menuentry "RancherOS-rollback" {
set root=(hd0,msdos1)
linux /boot/vmlinuz-${ROLLBACK_VERSION}-rancheros ${append_line} console=tty0 console=ttyS0
initrd /boot/initrd-${ROLLBACK_VERSION}-rancheros
}
EOF
fi

}

install_rancher()
{
cp ${DIST}/initrd /mnt/new_img/boot/initrd-${VERSION}-rancheros
cp ${DIST}/vmlinuz /mnt/new_img/boot/vmlinuz-${VERSION}-rancheros
}

pvgrub_config()
{
local grub_file=/mnt/new_img/boot/grub/menu.lst
local append_line="${1}"
cat > $grub_file<<EOF
default 0
timeout 0
#fallback 1
hiddenmenu
title RancherOS ${VERSION}-(current)
root (hd0)
kernel /boot/vmlinuz-${VERSION}-rancheros ${append_line} console=tty0 console=ttyS0
initrd /boot/initrd-${VERSION}-rancheros
EOF

if [ ! -z $ROLLBACK_VERSION ]; then
sed -i 's/^#\(fallback\)/\1/' $grub_file
cat >> $grub_file<<EOF
title RancherOS ${ROLLBACK_VERSION}-(rollback)
root (hd0)
kernel /boot/vmlinuz-${ROLLBACK_VERSION}-rancheros ${append_line} console=tty0 console=ttyS0
initrd /boot/initrd-${ROLLBACK_VERSION}-rancheros
EOF
fi
}

format_and_mount()
{
format_device
mount_device
create_boot_dirs
}

KERNEL_ARGS=${KERNEL_ARGS:-""}
if [ -n ${ENV} ]; then
case ${ENV} in
"generic")
format_and_mount
install_grub
/scripts/seed-data $BASE_DIR $CLOUD_CONFIG $FILES
;;
"amazon-ebs-pv"|"amazon-ebs-hvm")
format_and_mount
if [ "${ENV}" == "amazon-ebs-hvm" ]; then
install_grub
fi
# AWS Networking recommends disabling.
/scripts/seed-data $BASE_DIR $CLOUD_CONFIG $FILES
;;
"googlecompute")
format_and_mount
install_grub
/scripts/seed-data $BASE_DIR $CLOUD_CONFIG $FILES
;;
"bootstrap")
mount_device true
create_boot_dirs
KERNEL_ARGS="${KERNEL_ARGS} rancher.cloud_init.datasources=[ec2,gce]"
;;
"rancher-upgrade")
mount_device
create_boot_dirs
;;
*)
echo "$ENV is not a valid environment" 1>&2
exit 1
;;
esac
fi

grub2_config "${KERNEL_ARGS}"
pvgrub_config "${KERNEL_ARGS}"
install_rancher
22 changes: 22 additions & 0 deletions scripts/installer/seed-data
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e -x

BASE_DIR=${1}
CLOUD_DATA=${2}
IFS=',' read -ra FILES <<< "${3}"

if [ -z ${BASE_DIR} ]; then
echo "Need base directory to place files" 1>&2
exit 1
fi

mkdir -p ${BASE_DIR}/lib/rancher/conf/cloud-config.d

cp ${CLOUD_DATA} ${BASE_DIR}/lib/rancher/conf/cloud-config.d/

for f in ${FILES[@]}; do
IFS=":" read s d <<< "${f}"
mkdir -p $(dirname ${BASE_DIR}/${d})
cp -a -T ${s} ${BASE_DIR}/${d}
done
43 changes: 43 additions & 0 deletions scripts/installer/set-disk-partitions
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

set -e
set -x

DEVICE=${1}

if [[ -z $DEVICE ]]; then
echo "Need to Pass a device name as arg1." 1>&2
exit 1
fi

PARTITION_COUNT=$(grep $(echo $DEVICE | cut -d '/' -f3) /proc/partitions | wc -l)
if [ "$PARTITION_COUNT" -gt "1" ]; then
echo "Device ${DEVICE} already partitioned!"
echo "Checking to see if it is mounted"

# Check this container first...
if grep -q "${DEVICE}" /proc/mounts; then
echo "Device is mounted, we can not repartition" 1>&2
exit 1
fi

# Check other system containers...
for container in $(system-docker ps -q); do
if system-docker exec $container grep -q "${DEVICE}" /proc/mounts; then
echo "Device is mounted in system container ${container}, we can not repartition" 1>&2
exit 1
fi
done

dd if=/dev/zero of=${DEVICE} bs=512 count=1
partprobe ${DEVICE}
fi

fdisk ${DEVICE} <<EOF
n
p
1
w
EOF

0 comments on commit 74a7c0a

Please sign in to comment.