diff --git a/.dockerignore b/.dockerignore index bf934021..1ecdf2fa 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,6 @@ .git +.idea +tmp state build dist diff --git a/build.sh b/build.sh index f7cb9e61..fc7d4f78 100755 --- a/build.sh +++ b/build.sh @@ -8,17 +8,15 @@ export DOCKER_IMAGE=rancher-os-build source ./scripts/version ./scripts/ci -mkdir -p dist -docker run --rm -it -e CHOWN_ID=$(id -u) -v $(pwd)/dist:/source/target $DOCKER_IMAGE -# Stupidest argparse ever -if echo "$@" | grep -q -- '--images'; then - ./scripts/build-extra-images -fi +rm -rf dist -# And again -if echo "$@" | grep -q -- '--push'; then - docker push rancher/ubuntuconsole:${VERSION} -fi +echo "Build complete. Copying artifacts..." +DIST_CONTAINER=$(docker create ${DOCKER_IMAGE}) +cleanup() { + docker rm -v ${DIST_CONTAINER} +} +trap cleanup EXIT +docker cp ${DIST_CONTAINER}:/source/dist/artifacts dist ls -l dist/artifacts diff --git a/cmd/control/config.go b/cmd/control/config.go index 3450e7d2..2f63ff35 100644 --- a/cmd/control/config.go +++ b/cmd/control/config.go @@ -5,6 +5,7 @@ import ( "io" "io/ioutil" "os" + "sort" "strings" log "github.com/Sirupsen/logrus" @@ -37,6 +38,17 @@ func configSubcommands() []cli.Command { }, }, }, + { + Name: "images", + Usage: "List Docker images for a configuration from a file", + Action: runImages, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "input, i", + Usage: "File from which to read config", + }, + }, + }, { Name: "export", Usage: "export configuration", @@ -64,6 +76,36 @@ func configSubcommands() []cli.Command { } } +func imagesFromConfig(cfg *config.Config) []string { + imagesMap := map[string]int{} + + for _, service := range cfg.BootstrapContainers { + imagesMap[service.Image] = 1 + } + for _, service := range cfg.SystemContainers { + imagesMap[service.Image] = 1 + } + + images := make([]string, len(imagesMap)) + i := 0 + for image := range imagesMap { + images[i] = image + i += 1 + } + sort.Strings(images) + return images +} + +func runImages(c *cli.Context) { + configFile := c.String("input") + cfg := config.ReadConfig(configFile) + if cfg == nil { + log.Fatalf("Could not read config from file %v", configFile) + } + images := imagesFromConfig(cfg) + fmt.Println(strings.Join(images, " ")) +} + func runImport(c *cli.Context) { var input io.ReadCloser var err error diff --git a/os-config.yml b/os-config.yml index 62f019c8..7ad94179 100644 --- a/os-config.yml +++ b/os-config.yml @@ -1,6 +1,6 @@ bootstrap_containers: udev: - image: udev + image: rancher/os-udev command: [] dns: [] dns_search: [] @@ -12,6 +12,7 @@ bootstrap_containers: links: [] log_driver: json-file net: host + uts: host privileged: true volumes: - /dev:/host/dev @@ -41,7 +42,7 @@ state: dev: LABEL=RANCHER_STATE system_containers: acpid: - image: acpid + image: rancher/os-acpid command: [] dns: [] dns_search: [] @@ -51,12 +52,13 @@ system_containers: io.rancher.os.scope: system links: [] net: host + uts: host privileged: true volumes_from: - command-volumes - system-volumes all-volumes: - image: state + image: rancher/os-state command: [] dns: [] dns_search: [] @@ -76,7 +78,7 @@ system_containers: - user-volumes - system-volumes cloud-init: - image: cloudinit + image: rancher/os-cloudinit command: [] dns: [] dns_search: [] @@ -91,12 +93,13 @@ system_containers: - cloud-init-pre - network net: host + uts: host privileged: true volumes_from: - command-volumes - system-volumes cloud-init-pre: - image: cloudinit + image: rancher/os-cloudinit command: [] dns: [] dns_search: [] @@ -110,12 +113,13 @@ system_containers: links: - preload-system-images net: host + uts: host privileged: true volumes_from: - command-volumes - system-volumes command-volumes: - image: state + image: rancher/os-state command: [] dns: [] dns_search: [] @@ -144,7 +148,7 @@ system_containers: - /lib/modules:/lib/modules - /usr/bin/docker:/usr/bin/docker:ro console: - image: console + image: rancher/os-console command: [] dns: [] dns_search: [] @@ -156,6 +160,7 @@ system_containers: links: - cloud-init net: host + uts: host pid: host ipc: host privileged: true @@ -163,7 +168,7 @@ system_containers: volumes_from: - all-volumes docker: - image: docker + image: rancher/os-docker command: [] dns: [] dns_search: [] @@ -174,6 +179,7 @@ system_containers: links: - network net: host + uts: host pid: host ipc: host privileged: true @@ -181,7 +187,7 @@ system_containers: volumes_from: - all-volumes docker-volumes: - image: state + image: rancher/os-state command: [] dns: [] dns_search: [] @@ -200,7 +206,7 @@ system_containers: - /var/lib/docker:/var/lib/docker - /var/lib/system-docker:/var/lib/system-docker dockerwait: - image: dockerwait + image: rancher/os-dockerwait command: [] dns: [] dns_search: [] @@ -212,10 +218,11 @@ system_containers: links: - docker net: host + uts: host volumes_from: - all-volumes network: - image: network + image: rancher/os-network command: [] dns: [] dns_search: [] @@ -227,12 +234,13 @@ system_containers: links: - cloud-init-pre net: host + uts: host privileged: true volumes_from: - command-volumes - system-volumes ntp: - image: ntp + image: rancher/os-ntp command: [] dns: [] dns_search: [] @@ -244,10 +252,11 @@ system_containers: - cloud-init - network net: host + uts: host privileged: true restart: always preload-system-images: - image: preload + image: rancher/os-preload command: [] dns: [] dns_search: [] @@ -265,7 +274,7 @@ system_containers: - command-volumes - system-volumes preload-user-images: - image: preload + image: rancher/os-preload command: [] dns: [] dns_search: [] @@ -284,7 +293,7 @@ system_containers: - command-volumes - system-volumes syslog: - image: syslog + image: rancher/os-syslog command: [] dns: [] dns_search: [] @@ -295,12 +304,13 @@ system_containers: links: [] log_driver: json-file net: host + uts: host privileged: true restart: always volumes_from: - system-volumes system-volumes: - image: state + image: rancher/os-state command: [] dns: [] dns_search: [] @@ -324,7 +334,7 @@ system_containers: - /var/run:/var/run - /var/log:/var/log udev: - image: udev + image: rancher/os-udev command: [] dns: [] dns_search: [] @@ -336,12 +346,13 @@ system_containers: io.rancher.os.scope: system links: [] net: host + uts: host privileged: true restart: always volumes_from: - system-volumes user-volumes: - image: state + image: rancher/os-state command: [] dns: [] dns_search: [] diff --git a/scripts/build-common b/scripts/build-common index ab4f02f3..7be7eba0 100644 --- a/scripts/build-common +++ b/scripts/build-common @@ -1,46 +1,12 @@ #!/bin/bash -set -e : ${ARTIFACTS:=$(pwd)/assets} : ${BUILD:=$(pwd)/build} : ${CONFIG:=$(pwd)/config} : ${DIST:=$(pwd)/dist} -BUILDROOT=buildroot-2014.11.tar.bz2 DOCKER_FILE=${CONFIG}/.dockerfile -mkdir -p ${BUILD} ${DIST} - -busybox_install() -{ - local conf=$1 - local bbconf=$2 - local target=$3 - - if [ "$#" = "2" ]; then - target=$2 - bbconf= - fi - - apt-get update - apt-get install -y build-essential wget libncurses5-dev unzip bc - - cd ${BUILD} - - rm -rf ${BUILDROOT/.tar.bz2//} - tar xvjf ${ARTIFACTS}/${BUILDROOT} - cd ${BUILDROOT/.tar.bz2//} - - cp $conf .config - if [ -n "$bbconf" ]; then - cp $bbconf package/busybox/ - fi - make oldconfig - make - - cp output/images/rootfs.tar $target -} - write_base() { if [ "${BASE_WRITTEN}" = "true" ]; then @@ -54,7 +20,6 @@ FROM ${DOCKER_BASE:=ubuntu:14.04.2} ENV TERM xterm ENV IN_DOCKER true WORKDIR /source -CMD ["/source/scripts/install"] EOF BASE_WRITTEN=true diff --git a/scripts/build-extra-images b/scripts/build-extra-images deleted file mode 100755 index 0e9fb8e3..00000000 --- a/scripts/build-extra-images +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -set -e - -cd $(dirname $0)/.. - -source scripts/build-common -source scripts/version - ->${BUILD}/tags -for i in scripts/extraimages/[0-9]*; do - tag=$(echo $i | cut -f2 -d-):${VERSION} - echo Building $tag - docker build -t rancher/$tag -f $i . - echo $tag >> ${BUILD}/tags -done diff --git a/scripts/build-images b/scripts/build-images index 78019163..ca419177 100755 --- a/scripts/build-images +++ b/scripts/build-images @@ -1,46 +1,47 @@ #!/bin/bash -set -e - -VERSION=v0.0.1 +set -ex cd $(dirname $0)/.. source scripts/build-common +source scripts/version +ARTIFACTS=${ARTIFACTS:?"ARTIFACTS not set"} +VERSION=${VERSION:?"VERSION not set"} +BUILD=${BUILD:?"BUILD not set"} +DIST=${DIST:?"DIST not set"} -mkdir -p ${BUILD}/initrd ${DIST}/artifacts - -echo Extracting ${ARTIFACTS}/os-base.tar.xz -tar xJf ${ARTIFACTS}/os-base.tar.xz -C ${BUILD} - -tar xvf ${BUILD}/dist/kernel/*.tar -C ${BUILD}/dist/kernel - -cp /etc/ssl/certs/ca-certificates.crt ${ARTIFACTS}/ca.crt -cp /etc/ssl/certs/ca-certificates.crt ${BUILD}/initrd/ca.crt -cp ${BUILD}/dist/rootfs.tar ${ARTIFACTS} - -rm -rf ${BUILD}/initrd/lib -cp -rf ${BUILD}/dist/kernel/lib ${BUILD}/initrd -cp -rf ${BUILD}/dist/kernel/headers/* ${BUILD}/initrd -cp -f ${ARTIFACTS}/docker* ${BUILD}/initrd/docker -chmod +x ${BUILD}/initrd/docker - -cp ${BUILD}/dist/kernel/boot/vmlinuz* ${DIST}/artifacts/vmlinuz - -tar xf ${BUILD}/dist/rootfs-static.tar -C ${BUILD}/initrd --strip-components=2 ./bin/busybox -tar xf ${BUILD}/dist/rootfs-static.tar -C ${BUILD}/initrd --strip-components=3 ./usr/sbin/xtables-multi - -if ! docker info >/dev/null 2>&1 && [ -x "$(which wrapdocker)" ]; then +if [ -x "$(which wrapdocker)" ] && ! docker info >/dev/null 2>&1; then wrapdocker fi ->${BUILD}/tags -for i in scripts/dockerimages/[0-9]*; do - tag=$(echo $i | cut -f2 -d-) - echo Building $tag - docker build -t $tag -f $i . - docker build -t ${tag}:${VERSION} -f $i . - echo $tag >> ${BUILD}/tags -done +CONTAINER_INITRDBASE=$(docker create rancher/os-initrdbase:${VERSION}) +cleanup_initrdbase() { + docker rm -v ${CONTAINER_INITRDBASE} +} +trap cleanup_initrdbase EXIT +docker cp ${CONTAINER_INITRDBASE}:/initrd ${BUILD} # copies files to ${BUILD}/initrd -echo Creating images.tar -docker save $(<${BUILD}/tags) > ${BUILD}/initrd/images.tar +INITRD_DIR=${BUILD}/initrd + + +mkdir -p ${DIST}/artifacts + +CONTAINER_KERNEL=$(docker create rancher/os-kernel:${VERSION}) +cleanup_kernel() { + docker rm -v ${CONTAINER_KERNEL} +} +trap cleanup_kernel EXIT +docker cp ${CONTAINER_KERNEL}:/kernel ${BUILD} # copies files to ${BUILD}/kernel +mv ${BUILD}/kernel/vmlinuz ${DIST}/artifacts/ #kernel + + +cp -f ${ARTIFACTS}/docker* ${INITRD_DIR}/docker #initrd2-docker: /docker +chmod +x ${INITRD_DIR}/docker #initrd2-docker: /docker + +ln -sf bin/rancheros ./ros + +for i in $(./ros c images -i os-config.yml); do + docker pull ${i}:${VERSION} + docker tag -f ${i}:${VERSION} ${i} +done +docker save $(./ros c images -i os-config.yml) > ${INITRD_DIR}/images.tar #initrd2-images: /images.tar diff --git a/scripts/build-vbox-vm b/scripts/build-vbox-vm index de7df721..0637c7f6 100755 --- a/scripts/build-vbox-vm +++ b/scripts/build-vbox-vm @@ -18,7 +18,7 @@ fi GITSHA=$(git rev-parse --short HEAD) VM="RancherOS-${GITSHA}" -sudo chown -R `whoami`:`whoami` ./dist +sudo chown -R `whoami` ./dist VBoxManage createhd --format vmdk --filename ./dist/artifacts/$VM.vmdk --size 40000 diff --git a/scripts/ci b/scripts/ci index b82652ef..4c9dad40 100755 --- a/scripts/ci +++ b/scripts/ci @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -ex cd $(dirname $0)/.. @@ -7,6 +7,7 @@ export DOCKER_IMAGE=${DOCKER_IMAGE:=rancher-os-build} export DOCKER_BASE=rancher/dind:v0.1.0 source scripts/build-common +mkdir -p ${BUILD} DOCKER_FILE=$(pwd)/.dockerfile @@ -25,7 +26,7 @@ generate_images() echo Running: docker run -d --privileged ${DOCKER_IMAGE} /source/scripts/build-images CID=$(docker run -d --privileged ${DOCKER_IMAGE} /source/scripts/build-images) docker logs -f ${CID} & - trap "docker rm -f ${CID}" exit + trap "docker rm -fv ${CID}" exit [ "$(docker wait $CID)" == 0 ] DOCKER_BASE=$(docker commit $CID) @@ -38,16 +39,8 @@ if [ -x "$(which wrapdocker)" ] && ! docker info >/dev/null 2>&1; then fi run ./scripts/bootstrap -run ./scripts/test -run --assets ./scripts/build-common --assets ./assets ./scripts/download -run --assets ./scripts/dockerimages --assets ./scripts/build-images -finish - -generate_images - -reset_docker_build ARGS= -for i in $(ls -d * .* | sort -u | grep -Ev '(\.|\.\.|\.dockerfile|build|dist|.git|scripts|bin|state)$'); do +for i in $(ls -d * .* | sort -u | grep -Ev '(\.|\.\.|\.dockerfile|build|tmp|dist|.git|.idea|.vagrant|scripts|bin|state)$'); do if [ -d $i ]; then run --assets $i else @@ -55,5 +48,12 @@ for i in $(ls -d * .* | sort -u | grep -Ev '(\.|\.\.|\.dockerfile|build|dist|.gi fi done run --assets ./scripts/version --assets "${ARGS}" ./scripts/build -run --assets ./scripts/install ./scripts/package "$@" +run --assets ./scripts/build-common --assets ./assets ./scripts/download +run --assets ./scripts/build-images +finish + +generate_images + +reset_docker_build +run ./scripts/package "$@" finish diff --git a/scripts/dockerimages/00-base b/scripts/dockerimages/00-base deleted file mode 100644 index 6fa7e16f..00000000 --- a/scripts/dockerimages/00-base +++ /dev/null @@ -1,36 +0,0 @@ -FROM scratch -ADD assets/rootfs.tar / -RUN ln -s /dev/null /etc/udev/rules.d/80-net-name-slot.rules -# Cleanup Buildroot -RUN rm /sbin/poweroff /sbin/reboot /sbin/halt && \ - sed -i '/^root/s!/bin/sh!/bin/bash!' /etc/passwd && \ - echo 'RancherOS \n \l' > /etc/issue && \ - rm -rf /run \ - /linuxrc \ - /etc/os-release \ - /var/cache \ - /var/lock \ - /var/log \ - /var/run \ - /var/spool \ - /var/lib/misc && \ - mkdir -p \ - /run \ - /var/cache \ - /var/lock \ - /var/log \ - /var/run \ - /var/spool && \ - passwd -l root && \ - addgroup -g 1100 rancher && \ - addgroup -g 1101 docker && \ - addgroup -g 1103 sudo && \ - adduser -u 1100 -G rancher -D -h /home/rancher -s /bin/bash rancher && \ - adduser -u 1101 -G docker -D -h /home/docker -s /bin/bash docker && \ - sed -i 's/\(^docker.*\)/\1rancher/g' /etc/group && \ - sed -i 's/\(^sudo.*\)/\1rancher,docker/g' /etc/group && \ - echo '%sudo ALL=(ALL) ALL' >> /etc/sudoers -COPY scripts/dockerimages/scripts/inputrc /etc/inputrc -COPY scripts/dockerimages/scripts/entry.sh /usr/sbin/entry.sh - -ENTRYPOINT ["/usr/sbin/entry.sh"] diff --git a/scripts/dockerimages/01-state b/scripts/dockerimages/01-state deleted file mode 100644 index b34cd085..00000000 --- a/scripts/dockerimages/01-state +++ /dev/null @@ -1,2 +0,0 @@ -FROM base -CMD ["echo"] diff --git a/scripts/dockerimages/02-udev b/scripts/dockerimages/02-udev deleted file mode 100644 index 478e0472..00000000 --- a/scripts/dockerimages/02-udev +++ /dev/null @@ -1,3 +0,0 @@ -FROM base -COPY scripts/dockerimages/scripts/udev.sh / -CMD ["/udev.sh"] diff --git a/scripts/dockerimages/03-network b/scripts/dockerimages/03-network deleted file mode 100644 index 23bf0dbf..00000000 --- a/scripts/dockerimages/03-network +++ /dev/null @@ -1,2 +0,0 @@ -FROM base -CMD ["netconf"] diff --git a/scripts/dockerimages/04-cloudinit b/scripts/dockerimages/04-cloudinit deleted file mode 100644 index b84ed95a..00000000 --- a/scripts/dockerimages/04-cloudinit +++ /dev/null @@ -1,3 +0,0 @@ -FROM base -COPY scripts/dockerimages/scripts/cloud-init.sh / -CMD ["/cloud-init.sh"] diff --git a/scripts/dockerimages/05-docker b/scripts/dockerimages/05-docker deleted file mode 100644 index 4a2db946..00000000 --- a/scripts/dockerimages/05-docker +++ /dev/null @@ -1,4 +0,0 @@ -FROM base -COPY scripts/dockerimages/scripts/docker.sh / -COPY assets/ca.crt /etc/ssl/certs/ca-certificates.crt -CMD ["/docker.sh"] diff --git a/scripts/dockerimages/06-console b/scripts/dockerimages/06-console deleted file mode 100644 index 0a90b784..00000000 --- a/scripts/dockerimages/06-console +++ /dev/null @@ -1,12 +0,0 @@ -FROM base -COPY scripts/dockerimages/scripts/console.sh /usr/sbin/ -COPY scripts/dockerimages/scripts/update-ssh-keys /usr/bin/ -COPY scripts/dockerimages/scripts/rancheros-install /usr/sbin/ -RUN sed -i 's/rancher:!/rancher:*/g' /etc/shadow && \ - sed -i 's/docker:!/docker:*/g' /etc/shadow && \ - sed -i 's/#ClientAliveInterval 0/ClientAliveInterval 180/g' /etc/ssh/sshd_config && \ - echo '## allow password less for rancher user' >> /etc/sudoers && \ - echo 'rancher ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers && \ - echo '## allow password less for docker user' >> /etc/sudoers && \ - echo 'docker ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers -CMD ["/usr/sbin/console.sh"] diff --git a/scripts/dockerimages/07-rescue b/scripts/dockerimages/07-rescue deleted file mode 100644 index 9232f12d..00000000 --- a/scripts/dockerimages/07-rescue +++ /dev/null @@ -1,2 +0,0 @@ -FROM console -CMD ["/bin/sh"] diff --git a/scripts/dockerimages/08-ntp b/scripts/dockerimages/08-ntp deleted file mode 100644 index f13d0083..00000000 --- a/scripts/dockerimages/08-ntp +++ /dev/null @@ -1,3 +0,0 @@ -FROM base -COPY scripts/dockerimages/scripts/ntp.sh / -CMD ["/ntp.sh"] diff --git a/scripts/dockerimages/09-syslog b/scripts/dockerimages/09-syslog deleted file mode 100644 index ca3b12a5..00000000 --- a/scripts/dockerimages/09-syslog +++ /dev/null @@ -1,4 +0,0 @@ -FROM base -COPY scripts/dockerimages/scripts/syslog.sh / -RUN sed -i 1,10d /etc/rsyslog.conf -CMD ["/syslog.sh"] diff --git a/scripts/dockerimages/10-autoformat b/scripts/dockerimages/10-autoformat deleted file mode 100644 index 6568c265..00000000 --- a/scripts/dockerimages/10-autoformat +++ /dev/null @@ -1,3 +0,0 @@ -FROM base -COPY scripts/dockerimages/scripts/auto-format.sh /usr/sbin/ -ENTRYPOINT ["/usr/sbin/auto-format.sh"] diff --git a/scripts/dockerimages/11-dockerwait b/scripts/dockerimages/11-dockerwait deleted file mode 100644 index 70f30187..00000000 --- a/scripts/dockerimages/11-dockerwait +++ /dev/null @@ -1,2 +0,0 @@ -FROM base -CMD ["/usr/sbin/wait-for-docker"] diff --git a/scripts/dockerimages/12-acpid b/scripts/dockerimages/12-acpid deleted file mode 100644 index 3e5a8705..00000000 --- a/scripts/dockerimages/12-acpid +++ /dev/null @@ -1,2 +0,0 @@ -FROM base -CMD ["/usr/sbin/acpid", "-f"] diff --git a/scripts/dockerimages/13-preload b/scripts/dockerimages/13-preload deleted file mode 100644 index 660f1d92..00000000 --- a/scripts/dockerimages/13-preload +++ /dev/null @@ -1,3 +0,0 @@ -FROM base -COPY scripts/dockerimages/scripts/preload.sh / -CMD ["/preload.sh"] diff --git a/scripts/dockerimages/scripts/auto-format.sh b/scripts/dockerimages/scripts/auto-format.sh deleted file mode 100755 index 64f9f2b2..00000000 --- a/scripts/dockerimages/scripts/auto-format.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -set -ex - -if [ -n "$1" ]; then - # Test for our magic string (it means that the disk was made by ./boot2docker init) - HEADER=`dd if=$1 bs=1 count=${#MAGIC} 2>/dev/null` - - if [ "$HEADER" = "$MAGIC" ]; then - # save the preload userdata.tar file - dd if=$1 of=/userdata.tar bs=1 count=8192 - fi - - mkfs.ext4 -L RANCHER_STATE $1 - - if [ -e "/userdata.tar" ]; then - mount -t ext4 $1 /var/ - mkdir -p /var/lib/rancher/conf/cloud-config.d - echo $(tar -xvf /userdata.tar) - AUTHORIZED_KEY1=$(cat /.ssh/authorized_keys) - AUTHORIZED_KEY2=$(cat /.ssh/authorized_keys2) - tee /var/lib/rancher/conf/cloud-config.d/machine.yml << EOF -#cloud-config - -rancher: - network: - interfaces: - eth0: - dhcp: true - eth1: - dhcp: true - lo: - address: 127.0.0.1/8 - -ssh_authorized_keys: - - $AUTHORIZED_KEY1 - - $AUTHORIZED_KEY2 - -users: - - name: docker - ssh_authorized_keys: - - $AUTHORIZED_KEY1 - - $AUTHORIZED_KEY2 -EOF - fi -fi - diff --git a/scripts/dockerimages/scripts/cloud-init.sh b/scripts/dockerimages/scripts/cloud-init.sh deleted file mode 100755 index 333568b4..00000000 --- a/scripts/dockerimages/scripts/cloud-init.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -set -x -e - -MOUNT_POINT=/media/config-2 -CONFIG_DEV=$(blkid | grep -- 'LABEL="config-2"' | cut -f1 -d:) - -mkdir -p ${MOUNT_POINT} - -if [ -e "${CONFIG_DEV}" ]; then - mount ${CONFIG_DEV} ${MOUNT_POINT} -else - mount -t 9p -o trans=virtio,version=9p2000.L config-2 ${MOUNT_POINT} 2>/dev/null || true -fi - -ros config get cloud_init - -cloud-init -save -network=${CLOUD_INIT_NETWORK:-true} diff --git a/scripts/dockerimages/scripts/console.sh b/scripts/dockerimages/scripts/console.sh deleted file mode 100755 index 1ea72aed..00000000 --- a/scripts/dockerimages/scripts/console.sh +++ /dev/null @@ -1,114 +0,0 @@ -#!/bin/bash -set -e - -setup_ssh() -{ - for i in rsa dsa ecdsa ed25519; do - local output=/etc/ssh/ssh_host_${i}_key - if [ ! -e $output ]; then - local saved="$(rancherctl config get ssh.keys.${i})" - local pub="$(rancherctl config get ssh.keys.${i}-pub)" - - if [[ -n "$saved" && -n "$pub" ]]; then - ( - umask 477 - echo "$saved" > ${output} - echo "$pub" > ${output}.pub - ) - else - ssh-keygen -f $output -N '' -t $i - rancherctl config set -- ssh.keys.${i} "$(<${output})" - rancherctl config set -- ssh.keys.${i}-pub "$(<${output}.pub)" - fi - fi - done - - mkdir -p /var/run/sshd -} - -RANCHER_HOME=/home/rancher -if [ ! -d ${RANCHER_HOME} ]; then - mkdir -p ${RANCHER_HOME} - chown rancher:rancher ${RANCHER_HOME} - chmod 2755 ${RANCHER_HOME} -fi - -DOCKER_HOME=/home/docker -if [ ! -d ${DOCKER_HOME} ]; then - mkdir -p ${DOCKER_HOME} - chown docker:docker ${DOCKER_HOME} - chmod 2755 ${DOCKER_HOME} -fi - -for i in $( /etc/lsb-release << EOF -DISTRIB_ID=RancherOS -DISTRIB_RELEASE=${VERSION} -DISTRIB_DESCRIPTION="RancherOS ${VERSION}" -EOF - -cat > /etc/respawn.conf << EOF -/sbin/getty 115200 tty1 -/sbin/getty 115200 tty2 -/sbin/getty 115200 tty3 -/sbin/getty 115200 tty4 -/sbin/getty 115200 tty5 -/sbin/getty 115200 tty6 -/usr/sbin/sshd -D -EOF - -if ! grep -q '^UseDNS no' /etc/ssh/sshd_config; then - echo "UseDNS no" >> /etc/ssh/sshd_config -fi - -ID_TYPE="busybox" -if [ -e /etc/os-release ] && grep -q 'ID_LIKE=' /etc/os-release; then - ID_TYPE=$(grep 'ID_LIKE=' /etc/os-release | cut -d'=' -f2) -fi - -cat > /etc/os-release << EOF -NAME="RancherOS" -VERSION=$VERSION -ID=rancheros -ID_LIKE=$ID_TYPE -VERSION_ID=$VERSION -PRETTY_NAME="RancherOS" -HOME_URL= -SUPPORT_URL= -BUG_REPORT_URL= -BUILD_ID= -EOF - -if ! grep -q "$(hostname)" /etc/hosts; then - echo 127.0.1.1 $(hostname) >> /etc/hosts -fi - -echo $(/sbin/ifconfig | grep -B1 "inet addr" |awk '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' |awk -F: '{ print $1 ": " $3}') >> /etc/issue - -if [ -x /opt/rancher/bin/start.sh ]; then - echo Executing custom script - /opt/rancher/bin/start.sh || true -fi - -exec respawn -f /etc/respawn.conf diff --git a/scripts/dockerimages/scripts/docker.sh b/scripts/dockerimages/scripts/docker.sh deleted file mode 100755 index 73c49011..00000000 --- a/scripts/dockerimages/scripts/docker.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -set -x -e - -TLS_PATH=/etc/docker/tls -CGROUPS="perf_event net_cls freezer devices blkio memory cpuacct cpu cpuset" - -mkdir -p /sys/fs/cgroup -mount -t tmpfs none /sys/fs/cgroup - -for i in $CGROUPS; do - mkdir -p /sys/fs/cgroup/$i - mount -t cgroup -o $i none /sys/fs/cgroup/$i -done - -if ! lsmod | grep -q br_netfilter; then - modprobe br_netfilter 2>/dev/null || true -fi - -rm -f /var/run/docker.pid - -ARGS=$(echo $(ros config get user_docker.args | sed 's/^-//')) -ARGS="$ARGS $(echo $(ros config get user_docker.extra_args | sed 's/^-//'))" - -if [ "$(ros config get user_docker.tls)" = "true" ]; then - ARGS="$ARGS $(echo $(ros config get user_docker.tls_args | sed 's/^-//'))" - ros tls generate --server -d $TLS_PATH - cd $TLS_PATH -fi - -if [ -e /var/lib/rancher/conf/docker ]; then - source /var/lib/rancher/conf/docker -fi - -exec $ARGS $DOCKER_OPTS >/var/log/docker.log 2>&1 diff --git a/scripts/dockerimages/scripts/entry.sh b/scripts/dockerimages/scripts/entry.sh deleted file mode 100755 index ca1f5198..00000000 --- a/scripts/dockerimages/scripts/entry.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -if [ -e /host/dev ]; then - mount --rbind /host/dev /dev -fi - -CA_BASE=/etc/ssl/certs/ca-certificates.crt.rancher -CA=/etc/ssl/certs/ca-certificates.crt - -if [[ -e ${CA_BASE} && ! -e ${CA} ]]; then - cp $CA_BASE $CA -fi - -exec "$@" diff --git a/scripts/dockerimages/scripts/inputrc b/scripts/dockerimages/scripts/inputrc deleted file mode 100644 index d3da9859..00000000 --- a/scripts/dockerimages/scripts/inputrc +++ /dev/null @@ -1,67 +0,0 @@ -# /etc/inputrc - global inputrc for libreadline -# See readline(3readline) and `info rluserman' for more information. - -# Be 8 bit clean. -set input-meta on -set output-meta on - -# To allow the use of 8bit-characters like the german umlauts, uncomment -# the line below. However this makes the meta key not work as a meta key, -# which is annoying to those which don't need to type in 8-bit characters. - -# set convert-meta off - -# try to enable the application keypad when it is called. Some systems -# need this to enable the arrow keys. -# set enable-keypad on - -# see /usr/share/doc/bash/inputrc.arrows for other codes of arrow keys - -# do not bell on tab-completion -# set bell-style none -# set bell-style visible - -# some defaults / modifications for the emacs mode -$if mode=emacs - -# allow the use of the Home/End keys -"\e[1~": beginning-of-line -"\e[4~": end-of-line - -# allow the use of the Delete/Insert keys -"\e[3~": delete-char -"\e[2~": quoted-insert - -# mappings for "page up" and "page down" to step to the beginning/end -# of the history -# "\e[5~": beginning-of-history -# "\e[6~": end-of-history - -# alternate mappings for "page up" and "page down" to search the history -# "\e[5~": history-search-backward -# "\e[6~": history-search-forward - -# mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving -"\e[1;5C": forward-word -"\e[1;5D": backward-word -"\e[5C": forward-word -"\e[5D": backward-word -"\e\e[C": forward-word -"\e\e[D": backward-word - -$if term=rxvt -"\e[7~": beginning-of-line -"\e[8~": end-of-line -"\eOc": forward-word -"\eOd": backward-word -$endif - -# for non RH/Debian xterm, can't hurt for RH/Debian xterm -# "\eOH": beginning-of-line -# "\eOF": end-of-line - -# for freebsd console -# "\e[H": beginning-of-line -# "\e[F": end-of-line - -$endif diff --git a/scripts/dockerimages/scripts/ntp.sh b/scripts/dockerimages/scripts/ntp.sh deleted file mode 100755 index 7ca088ab..00000000 --- a/scripts/dockerimages/scripts/ntp.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -exec ntpd diff --git a/scripts/dockerimages/scripts/preload.sh b/scripts/dockerimages/scripts/preload.sh deleted file mode 100755 index d8b67fce..00000000 --- a/scripts/dockerimages/scripts/preload.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -set -e - -BASE=${1:-${PRELOAD_DIR}} -BASE=${BASE:-/mnt/preload} - -should_load() { - file=${1} - if [[ ${file} =~ \.done$ ]]; then echo false - elif [ -f ${file} ]; then - if [ ! -e ${file}.done ]; then echo true - elif [[ $(stat -c %Y ${file}) > $(stat -c %Y ${file}.done) ]]; then echo true - else echo false - fi - else echo false - fi -} - -if [ -d ${BASE} ]; then - echo Preloading docker images from ${BASE}... - - for file in $(ls ${BASE}); do - path=${BASE}/${file} - loading=$(should_load ${path}) - if [ ${loading} == "true" ]; then - CAT="cat ${path}" - if [[ ${file} =~ \.t?gz$ ]]; then CAT="${CAT} | gunzip"; fi - if [[ ${file} =~ \.t?xz$ ]]; then CAT="${CAT} | unxz"; fi - CAT="${CAT} | docker load" - echo loading from ${path} - eval ${CAT} || : - touch ${path}.done || : - fi - done - - echo Done. -else - echo Can not preload images from ${BASE}: not a dir or does not exist. -fi - diff --git a/scripts/dockerimages/scripts/rancheros-install b/scripts/dockerimages/scripts/rancheros-install deleted file mode 100755 index 01daa5e9..00000000 --- a/scripts/dockerimages/scripts/rancheros-install +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/bash - -set -e - -usage() -{ -cat <&2 - exit 1 -fi - -if [ -x /usr/bin/ros ]; then - INSTALL_CONTAINER_IMAGE="$(ros config get upgrade.image)" -fi - -if [ -n "$(grep RancherOS /etc/lsb-release)" ]; then - INSTALLER_VERSION=$(grep DISTRIB_RELEASE /etc/lsb-release|cut -d'=' -f2) -fi - -EXTRA_ARGS= - -while getopts "c:d:ft:v:h" OPTION -do - case $OPTION in - c) CLOUD_CONFIG="$OPTARG" ;; - d) DEVICE="$OPTARG" ;; - f) FORCE_INSTALL="true" ;; - t) INSTALL_TYPE="${OPTARG}" ;; - v) INSTALLER_VERSION="$OPTARG" ;; - h) usage; exit ;; - *) exit 1 ;; - esac -done - -if [[ -z "${INSTALL_TYPE}" ]]; then - echo "No install type specified...defaulting to generic" - INSTALL_TYPE="generic" -fi - -if [ -z "${CLOUD_CONFIG}" ] && [ "${INSTALL_TYPE}" != "amazon-ebs" ]; then - echo "$0: called without cloud config. Can not proceed without -c" 1>&2 - exit 1 -fi - -if [[ -z "${DEVICE}" ]]; then - echo "$0: No device defined. Can not proceed without -d specified" 1>&2 - exit 1 -fi - -if [ "${INSTALL_TYPE}" == "generic" ]; then - PARTITION_FLAG="true" -fi - -if [[ ! -z "${CLOUD_CONFIG}" ]]; then - cp ${CLOUD_CONFIG} /opt/user_config.yml - EXTRA_ARGS='-c /opt/user_config.yml' -fi - -if [ "${FORCE_INSTALL}" != "true" ] && [ "${INSTALL_TYPE}" != "rancher-upgrade" ]; then - echo "All data will be wiped from this device" - printf "Partition: ${PARTITION_FLAG}\nDEVICE: ${DEVICE}\n" - read -p "Are you sure you want to continue? [yN]" -n 1 -r confirmation - if [ "$confirmation" != "y" ]; then - echo "Exiting..." - exit 1 - fi -fi - -if [ "$PARTITION_FLAG" == "true" ]; then - system-docker run --net=host -it --privileged --entrypoint=/scripts/set-disk-partitions --volumes-from=all-volumes ${INSTALL_CONTAINER_IMAGE}:${INSTALLER_VERSION} ${DEVICE} - system-docker start udev -fi - -system-docker run --volumes-from=user-volumes --net=host -it --privileged ${INSTALL_CONTAINER_IMAGE}:${INSTALLER_VERSION} -d ${DEVICE} -t ${INSTALL_TYPE} ${EXTRA_ARGS} - -echo "RancherOS has been installed. Please reboot..." diff --git a/scripts/dockerimages/scripts/syslog.sh b/scripts/dockerimages/scripts/syslog.sh deleted file mode 100755 index 285ffefa..00000000 --- a/scripts/dockerimages/scripts/syslog.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!bin/bash - -set -x -e - -exec rsyslogd -n diff --git a/scripts/dockerimages/scripts/udev.sh b/scripts/dockerimages/scripts/udev.sh deleted file mode 100755 index 870d9688..00000000 --- a/scripts/dockerimages/scripts/udev.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -if [ "$DAEMON" = true ]; then - exec udevd -fi - -udevd --daemon -udevadm trigger --action=add -udevadm settle diff --git a/scripts/dockerimages/scripts/update-ssh-keys b/scripts/dockerimages/scripts/update-ssh-keys deleted file mode 100755 index f2a0c637..00000000 --- a/scripts/dockerimages/scripts/update-ssh-keys +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -USERNAME=$1 -HOME_DIR=$(grep ^$USERNAME /etc/passwd | cut -f6 -d:) - -if [ ! -d $HOME_DIR/.ssh ]; then - mkdir -p $HOME_DIR/.ssh - chmod 0700 $HOME_DIR/.ssh -fi - -if [ ! -e $HOME_DIR/.ssh/authorized_keys ]; then - touch $HOME_DIR/.ssh/authorized_keys - chmod 0600 $HOME_DIR/.ssh/authorized_keys -fi - -if ! grep -q "$2" $HOME_DIR/.ssh/authorized_keys; then - echo "$2" >> $HOME_DIR/.ssh/authorized_keys -fi - -chown -R $USERNAME $HOME_DIR/.ssh diff --git a/scripts/download b/scripts/download index 486cdca2..f5792284 100755 --- a/scripts/download +++ b/scripts/download @@ -4,5 +4,4 @@ cd $(dirname $0)/.. source scripts/build-common -download 49d339d888df757e37433d613bdcdd5acb78ca15 https://github.com/rancherio/os-base/releases/download/v0.3.1/os-base.tar.xz -download a6344119513201ea48a8e584b9cf83bd5f3905a1 https://github.com/rancherio/docker/releases/download/v1.6.2-ros-1/docker-1.6.2 +download 1d325a529b17c5e8fd9baee29df24c222a9f2e25 https://github.com/rancherio/docker/releases/download/v1.7.0-ros-1/docker-1.7.0 diff --git a/scripts/extraimages/00-ubuntuconsole b/scripts/extraimages/00-ubuntuconsole deleted file mode 100644 index 2ae5d340..00000000 --- a/scripts/extraimages/00-ubuntuconsole +++ /dev/null @@ -1,21 +0,0 @@ -FROM ubuntu:14.04.2 -RUN apt-get update && \ - apt-get upgrade --no-install-recommends -y && \ - apt-get install -y --no-install-recommends openssh-server rsync vim -RUN rm -rf /etc/ssh/*key* -COPY scripts/dockerimages/scripts/entry.sh /usr/sbin/ -COPY scripts/dockerimages/scripts/console.sh /usr/sbin/ -COPY scripts/dockerimages/scripts/update-ssh-keys /usr/bin/ -COPY scripts/dockerimages/scripts/rancheros-install /usr/sbin/ -RUN echo 'RancherOS \\n \l' > /etc/issue -RUN locale-gen en_US.UTF-8 -RUN addgroup --gid 1100 rancher && \ - addgroup --gid 1101 docker && \ - useradd -u 1100 -g rancher -G docker,sudo -m -s /bin/bash rancher && \ - useradd -u 1101 -g docker -G docker,sudo -m -s /bin/bash docker && \ - echo ClientAliveInterval 180 >> /etc/ssh/sshd_config && \ - echo '## allow password less for rancher user' >> /etc/sudoers && \ - echo 'rancher ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers && \ - echo 'docker ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers -ENTRYPOINT ["/usr/sbin/entry.sh"] -CMD ["/usr/sbin/console.sh"] diff --git a/scripts/extraimages/01-debianconsole b/scripts/extraimages/01-debianconsole deleted file mode 100644 index f9a6e89c..00000000 --- a/scripts/extraimages/01-debianconsole +++ /dev/null @@ -1,21 +0,0 @@ -FROM debian:jessie -RUN apt-get update && \ - apt-get upgrade --no-install-recommends -y && \ - apt-get install -y --no-install-recommends openssh-server rsync locales sudo vim less -RUN rm -rf /etc/ssh/*key* -COPY scripts/dockerimages/scripts/entry.sh /usr/sbin/ -COPY scripts/dockerimages/scripts/console.sh /usr/sbin/ -COPY scripts/dockerimages/scripts/update-ssh-keys /usr/bin/ -COPY scripts/dockerimages/scripts/rancheros-install /usr/sbin/ -RUN echo 'RancherOS \\n \l' > /etc/issue -RUN locale-gen en_US.UTF-8 -RUN addgroup --gid 1100 rancher && \ - addgroup --gid 1101 docker && \ - useradd -u 1100 -g rancher -G docker,sudo -m -s /bin/bash rancher && \ - useradd -u 1101 -g docker -G docker,sudo -m -s /bin/bash docker && \ - echo ClientAliveInterval 180 >> /etc/ssh/sshd_config && \ - echo '## allow password less for rancher user' >> /etc/sudoers && \ - echo 'rancher ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers && \ - echo 'docker ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers -ENTRYPOINT ["/usr/sbin/entry.sh"] -CMD ["/usr/sbin/console.sh"] diff --git a/scripts/install b/scripts/install deleted file mode 100755 index 1c74fd2a..00000000 --- a/scripts/install +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -set -x - -cd $(dirname $0)/.. - -. scripts/build-common - -mkdir -p target -rm -rf target/artifacts - -cp -rf ${DIST}/artifacts target diff --git a/scripts/package b/scripts/package index 77a829e9..6fabf2c0 100755 --- a/scripts/package +++ b/scripts/package @@ -1,10 +1,11 @@ #!/bin/bash -set -e +set -ex cd $(dirname $0)/.. source scripts/build-common +cp bin/rancheros ${DIST}/artifacts/ cp bin/rancheros ${BUILD}/initrd/init cp ./os-config.yml ${BUILD}/initrd/ diff --git a/scripts/run b/scripts/run index 24fee3f7..f36ed448 100755 --- a/scripts/run +++ b/scripts/run @@ -48,24 +48,17 @@ if [ ! -d ${INITRD_TMP} ]; then mkdir -p ${INITRD_TMP} pushd ${INITRD_TMP} if [ -e ${NO_COMPRESS_INITRD} ]; then - cat ${NO_COMPRESS_INITRD} | sudo cpio -idmv + cat ${NO_COMPRESS_INITRD} | cpio -idmv else - xz -dc ${INITRD} | sudo cpio -idmv + xz -dc ${INITRD} | cpio -idmv fi rm -f init popd fi -if [ -e $INITRD_CURRENT ]; then - rm -f ${INITRD_CURRENT} -fi -ln -s ${INITRD_TMP} ${INITRD_CURRENT} +ln -sf ${INITRD_TMP} ${INITRD_CURRENT} -if [ ! -e bin/rancheros ]; then - ./scripts/build -fi - -cp bin/rancheros ${INITRD_TMP}/init +cp dist/artifacts/rancheros ${INITRD_TMP}/init cp -f os-config.yml ${INITRD_TMP}/ cd ${INITRD_TMP} @@ -73,7 +66,7 @@ find | cpio -H newc -o > ${INITRD_TEST} if [ ! -e ${HD} ]; then mkdir -p $(dirname ${HD}) - zcat ${HD_GZ} > ${HD} + gzcat ${HD_GZ} > ${HD} fi mkdir -p $(dirname $USER_DATA) diff --git a/scripts/version b/scripts/version index a7ff4de7..2a4aebbb 100644 --- a/scripts/version +++ b/scripts/version @@ -1 +1 @@ -VERSION=v0.3.1 +VERSION=v0.3.2