From 0bab70e84e9641eb2bb16db472aae8a24a4ac7ee Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Mon, 29 Feb 2016 13:26:41 -0800 Subject: [PATCH 1/7] cleanup Makefile a bit --- Makefile | 27 ++++++++++++--------------- scripts/mk-initrd.sh | 2 +- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index e6331d98..edb7b85d 100644 --- a/Makefile +++ b/Makefile @@ -18,9 +18,6 @@ else ARCH=amd64 VERSION=$(VERSION) ./scripts/mk-ros.sh $@ endif -pwd := $(shell pwd) -include scripts/build-common - assets/docker: mkdir -p $(dir $@) @@ -36,31 +33,31 @@ ifdef COMPILED_KERNEL_URL installer: minimal docker build -t $(IMAGE_NAME):$(VERSION) . -$(DIST)/artifacts/vmlinuz: $(BUILD)/kernel/ +dist/artifacts/vmlinuz: build/kernel/ mkdir -p $(dir $@) - mv $(BUILD)/kernel/boot/vmlinuz* $@ + mv build/kernel/boot/vmlinuz* $@ -$(BUILD)/kernel/: +build/kernel/: mkdir -p $@ curl -L "$(COMPILED_KERNEL_URL)" | tar -xzf - -C $@ -$(DIST)/artifacts/initrd: bin/ros assets/docker assets/selinux/policy.29 $(BUILD)/kernel/ $(BUILD)/images.tar +dist/artifacts/initrd: bin/ros assets/docker assets/selinux/policy.29 build/kernel/ build/images.tar mkdir -p $(dir $@) ARCH=$(ARCH) DFS_IMAGE=$(DFS_IMAGE) DEV_BUILD=$(DEV_BUILD) ./scripts/mk-initrd.sh $@ -$(DIST)/artifacts/rancheros.iso: minimal +dist/artifacts/rancheros.iso: minimal ./scripts/mk-rancheros-iso.sh all: minimal installer iso -initrd: $(DIST)/artifacts/initrd +initrd: dist/artifacts/initrd -minimal: initrd $(DIST)/artifacts/vmlinuz +minimal: initrd dist/artifacts/vmlinuz -iso: $(DIST)/artifacts/rancheros.iso $(DIST)/artifacts/iso-checksums.txt +iso: dist/artifacts/rancheros.iso dist/artifacts/iso-checksums.txt test: minimal cd tests/integration && tox @@ -74,22 +71,22 @@ build/os-config.yml: build/host_ros ARCH=$(ARCH) VERSION=$(VERSION) ./scripts/gen-os-config.sh $@ -$(BUILD)/images.tar: build/host_ros build/os-config.yml +build/images.tar: build/host_ros build/os-config.yml ARCH=$(ARCH) FORCE_PULL=$(FORCE_PULL) ./scripts/mk-images-tar.sh -$(DIST)/artifacts/rootfs.tar.gz: bin/ros assets/docker $(BUILD)/images.tar assets/selinux/policy.29 +dist/artifacts/rootfs.tar.gz: bin/ros assets/docker build/images.tar assets/selinux/policy.29 mkdir -p $(dir $@) ARCH=$(ARCH) DFS_IMAGE=$(DFS_IMAGE) DEV_BUILD=$(DEV_BUILD) IS_ROOTFS=1 ./scripts/mk-initrd.sh $@ -$(DIST)/artifacts/iso-checksums.txt: $(DIST)/artifacts/rancheros.iso +dist/artifacts/iso-checksums.txt: dist/artifacts/rancheros.iso ./scripts/mk-iso-checksums-txt.sh version: @echo $(VERSION) -rootfs: $(DIST)/artifacts/rootfs.tar.gz +rootfs: dist/artifacts/rootfs.tar.gz .PHONY: rootfs version bin/ros diff --git a/scripts/mk-initrd.sh b/scripts/mk-initrd.sh index dc3f1d6c..021a2fd7 100755 --- a/scripts/mk-initrd.sh +++ b/scripts/mk-initrd.sh @@ -1,7 +1,7 @@ #!/bin/bash set -ex -TARGET=${1} +TARGET=$(pwd)/${1} ARCH=${ARCH:-"amd64"} DFS_IMAGE=${DFS_IMAGE:?"DFS_IMAGE not set"} From a557961c65b93c7553642ff844b79950ee91b477 Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Mon, 7 Mar 2016 14:04:05 -0800 Subject: [PATCH 2/7] fix services repo URL for architectures other than default (amd64) --- os-config.tpl.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/os-config.tpl.yml b/os-config.tpl.yml index 1eaea44c..54438df3 100644 --- a/os-config.tpl.yml +++ b/os-config.tpl.yml @@ -66,7 +66,7 @@ rancher: nameservers: [8.8.8.8, 8.8.4.4] repositories: core: - url: {{.OS_SERVICES_REPO}}/{{.VERSION}} + url: {{.OS_SERVICES_REPO}}/{{.VERSION}}{{.SUFFIX}} state: fstype: auto dev: LABEL=RANCHER_STATE From 5cc96f67a7eb33b7e85ec06edb45d4f5af15af4d Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Tue, 8 Mar 2016 17:54:57 -0800 Subject: [PATCH 3/7] update to DFS v1.10.2-1 --- build.conf | 2 +- trash.yml | 2 +- .../rancher/docker-from-scratch/.drone.yml | 2 +- .../docker-from-scratch/Dockerfile.dapper | 21 +++++++++++-------- .../rancher/docker-from-scratch/scratch.go | 2 +- .../selinux/selinux_arm64.go | 6 ++++++ 6 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 vendor/github.com/rancher/docker-from-scratch/selinux/selinux_arm64.go diff --git a/build.conf b/build.conf index 549f8149..e4b2b201 100644 --- a/build.conf +++ b/build.conf @@ -1,6 +1,6 @@ IMAGE_NAME=rancher/os VERSION=v0.4.4-dev -DFS_IMAGE=rancher/docker:v1.10.2 +DFS_IMAGE=rancher/docker:v1.10.2-1 SELINUX_POLICY_URL=https://github.com/rancher/refpolicy/releases/download/v0.0.1/policy.29 HOSTNAME_DEFAULT=rancher diff --git a/trash.yml b/trash.yml index 4daae75d..3c86dc90 100644 --- a/trash.yml +++ b/trash.yml @@ -66,7 +66,7 @@ import: version: 1349b37bd56f4f5ce2690b5b2c0f53f88a261c67 - package: github.com/rancher/docker-from-scratch - version: v1.10.2 + version: v1.10.2-1 - package: github.com/rancher/netconf version: d7d620ef4ea62a9d04b51c7b3d9dc83fe7ffaa1b diff --git a/vendor/github.com/rancher/docker-from-scratch/.drone.yml b/vendor/github.com/rancher/docker-from-scratch/.drone.yml index 3719c182..6ddc20a4 100644 --- a/vendor/github.com/rancher/docker-from-scratch/.drone.yml +++ b/vendor/github.com/rancher/docker-from-scratch/.drone.yml @@ -1,5 +1,5 @@ build: - image: rancher/dapper:1.9.1 + image: rancher/dapper:1.10.2 volumes: - /var/run/docker.sock:/var/run/docker.sock commands: diff --git a/vendor/github.com/rancher/docker-from-scratch/Dockerfile.dapper b/vendor/github.com/rancher/docker-from-scratch/Dockerfile.dapper index b8e078d0..b5648a92 100644 --- a/vendor/github.com/rancher/docker-from-scratch/Dockerfile.dapper +++ b/vendor/github.com/rancher/docker-from-scratch/Dockerfile.dapper @@ -1,13 +1,13 @@ -FROM golang:1.5.3 +FROM golang:1.6 RUN apt-get update && apt-get -y install libselinux-dev pkg-config -RUN curl -o /usr/local/bin/docker -L https://get.docker.com/builds/Linux/x86_64/docker-1.9.1 && \ +RUN wget -O /usr/local/bin/docker -L https://get.docker.com/builds/Linux/x86_64/docker-1.10.2 && \ chmod +x /usr/local/bin/docker ENV DAPPER_SOURCE /go/src/github.com/rancher/docker-from-scratch ENV DAPPER_OUTPUT "" ENV DAPPER_DOCKER_SOCKET true -ENV DAPPER_ENV NO_TEST +ENV DAPPER_ENV NO_TEST ARCH ENV GO15VENDOREXPERIMENT 1 @@ -18,21 +18,24 @@ WORKDIR ${DAPPER_SOURCE} RUN mkdir -p assets WORKDIR ${DAPPER_SOURCE}/assets -RUN curl -OL https://github.com/rancher/docker-from-scratch/releases/download/bin-v0.3.1/base-files_amd64.tar.gz -RUN curl -OL https://github.com/rancher/docker-from-scratch/releases/download/bin-v0.3.1/base-files_arm.tar.gz +RUN wget https://github.com/rancher/docker-from-scratch/releases/download/bin-v0.4.0/base-files_amd64.tar.gz +RUN wget https://github.com/rancher/docker-from-scratch/releases/download/bin-v0.4.0/base-files_arm.tar.gz +RUN wget https://github.com/rancher/docker-from-scratch/releases/download/bin-v0.4.0/base-files_arm64.tar.gz -RUN curl -o ./docker_amd64 -L https://get.docker.com/builds/Linux/x86_64/docker-1.10.2 && \ +RUN wget -O ./docker_amd64 -L https://get.docker.com/builds/Linux/x86_64/docker-1.10.2 && \ chmod +x ./docker_amd64 -RUN curl -o ./docker_arm -L https://github.com/rancher/docker/releases/download/v1.10.2-ros_arm/docker-1.10.2 && \ +RUN wget -O ./docker_arm -L https://github.com/rancher/docker/releases/download/v1.10.2-arm2/docker-1.10.2_arm && \ chmod +x ./docker_arm +RUN wget -O ./docker_arm64 -L https://github.com/rancher/docker/releases/download/v1.10.2-arm2/docker-1.10.2_arm64 && \ + chmod +x ./docker_arm64 WORKDIR ${DAPPER_SOURCE} COPY ./scripts/crosstools.list /etc/apt/sources.list.d/ RUN sh -c 'curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | apt-key add -' && \ - dpkg --add-architecture armhf && \ + dpkg --add-architecture armhf && dpkg --add-architecture arm64 && \ apt-get update && \ - apt-get install -y crossbuild-essential-armhf + apt-get install -y crossbuild-essential-armhf crossbuild-essential-arm64 CMD ./scripts/ci diff --git a/vendor/github.com/rancher/docker-from-scratch/scratch.go b/vendor/github.com/rancher/docker-from-scratch/scratch.go index 3a5ecf09..45d1be6c 100644 --- a/vendor/github.com/rancher/docker-from-scratch/scratch.go +++ b/vendor/github.com/rancher/docker-from-scratch/scratch.go @@ -453,7 +453,7 @@ func touchSockets(args ...string) error { } func createLayout(config *Config) error { - if err := createDirs("/tmp", "/root/.ssh", "/var"); err != nil { + if err := createDirs("/tmp", "/root/.ssh", "/var", "/usr/lib"); err != nil { return err } diff --git a/vendor/github.com/rancher/docker-from-scratch/selinux/selinux_arm64.go b/vendor/github.com/rancher/docker-from-scratch/selinux/selinux_arm64.go new file mode 100644 index 00000000..9e305b33 --- /dev/null +++ b/vendor/github.com/rancher/docker-from-scratch/selinux/selinux_arm64.go @@ -0,0 +1,6 @@ +package selinux + +// SetFileContext is a stub for SELinux support on ARM +func SetFileContext(path string, context string) (int, error) { + return 0, nil +} From 60d3a828aeae48884cdb35e483672a4ac80baaef Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Tue, 8 Mar 2016 15:59:59 -0800 Subject: [PATCH 4/7] use docker-1.10.2 at build time --- .drone.yml | 2 +- Dockerfile.dapper | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index f40efaec..6f7ea8e4 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,5 +1,5 @@ build: - image: rancher/dapper:1.9.1 + image: rancher/dapper:1.10.2 volumes: - /var/run/docker.sock:/var/run/docker.sock commands: diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 9dee1dc8..887ea0fc 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -13,7 +13,7 @@ ENV PATH /go/bin:$PATH RUN pip install tox RUN curl -sSL https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz | tar -xz -C /usr/local -RUN curl -sL https://get.docker.com/builds/Linux/x86_64/docker-1.9.1 > /usr/local/bin/docker +RUN curl -sL https://get.docker.com/builds/Linux/x86_64/docker-1.10.2 > /usr/local/bin/docker RUN chmod +x /usr/local/bin/docker ENV DAPPER_DOCKER_SOCKET true From 142ec237780327307d05d353004a1550f7b53735 Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Mon, 29 Feb 2016 17:01:33 -0800 Subject: [PATCH 5/7] Build for ARM64 on ARM64, installer included --- .docker-env.sample | 2 + .dockerignore.docker => .dockerignore.dapper | 0 .drone.yml | 3 +- .gitignore | 1 + .wrap-docker-args | 1 - Dockerfile => Dockerfile.amd64 | 0 Dockerfile.arm64 | 15 ++++ Dockerfile.dapper | 87 +++++++++++--------- Makefile | 9 +- build.conf.amd64 | 3 + build.conf.arm | 5 +- build.conf.arm64 | 5 ++ build.sh | 9 +- scripts/ci | 6 +- scripts/dapper-common | 21 +++++ scripts/installer/lay-down-os | 5 ++ scripts/make.sh | 7 ++ scripts/mk-initrd.sh | 8 +- scripts/mk-ros.sh | 10 +-- scripts/run | 10 ++- selinux/selinux_linux_arm64.go | 6 ++ util/cutil.go | 9 +- 22 files changed, 145 insertions(+), 77 deletions(-) create mode 100644 .docker-env.sample rename .dockerignore.docker => .dockerignore.dapper (100%) delete mode 100644 .wrap-docker-args rename Dockerfile => Dockerfile.amd64 (100%) create mode 100644 Dockerfile.arm64 create mode 100644 build.conf.arm64 create mode 100755 scripts/dapper-common create mode 100755 scripts/make.sh create mode 100644 selinux/selinux_linux_arm64.go diff --git a/.docker-env.sample b/.docker-env.sample new file mode 100644 index 00000000..63d11429 --- /dev/null +++ b/.docker-env.sample @@ -0,0 +1,2 @@ +DOCKER_HOST="tcp://192.168.2.2:2375" +DOCKER_TLS_VERIFY= diff --git a/.dockerignore.docker b/.dockerignore.dapper similarity index 100% rename from .dockerignore.docker rename to .dockerignore.dapper diff --git a/.drone.yml b/.drone.yml index 6f7ea8e4..9a7fbf66 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,5 +3,4 @@ build: volumes: - /var/run/docker.sock:/var/run/docker.sock commands: - - dapper -O make ARCH=arm rootfs - - dapper -O make DEV_BUILD=1 test + - ./scripts/ci diff --git a/.gitignore b/.gitignore index f3fbff37..0d2534cd 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ /tests/integration/.tox *.pyc __pychache__ +.docker-env.* diff --git a/.wrap-docker-args b/.wrap-docker-args deleted file mode 100644 index 3c1a8ef1..00000000 --- a/.wrap-docker-args +++ /dev/null @@ -1 +0,0 @@ ---privileged diff --git a/Dockerfile b/Dockerfile.amd64 similarity index 100% rename from Dockerfile rename to Dockerfile.amd64 diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 new file mode 100644 index 00000000..5efe1566 --- /dev/null +++ b/Dockerfile.arm64 @@ -0,0 +1,15 @@ +FROM aarch64/debian:jessie +ENV DEBIAN_FRONTEND noninteractive +ENV ARCH arm + +RUN apt-get update && apt-get install -y parted + +# TODO add kexec-tools: build from sources for aarch64 + +COPY ./scripts/installer /scripts +COPY ./build.conf /scripts/ + +COPY ./dist/artifacts/vmlinuz /dist/ +COPY ./dist/artifacts/initrd /dist/ + +ENTRYPOINT ["/scripts/lay-down-os"] diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 887ea0fc..e0358e42 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -1,58 +1,71 @@ -FROM ubuntu:15.10 +FROM rancher/os-dapper-base + +ARG ARCH +ENV ARCH ${ARCH} +ARG DOCKER_BINARY_URL +ENV DOCKER_BINARY_URL ${DOCKER_BINARY_URL} RUN apt-get update && \ - apt-get -y install locales sudo vim less curl wget git rsync build-essential syslinux isolinux xorriso \ - libblkid-dev libmount-dev libselinux1-dev cpio genisoimage qemu-kvm python-pip ca-certificates pkg-config + apt-get -y install locales sudo vim less curl wget git rsync build-essential isolinux xorriso gccgo \ + libblkid-dev libmount-dev libselinux1-dev cpio genisoimage qemu-kvm python-pip ca-certificates pkg-config tox -RUN locale-gen en_US.UTF-8 -ENV LANG en_US.UTF-8 -ENV PATH $PATH:/usr/local/go/bin +RUN mkdir -p /usr/local && cd /usr/local && \ + wget -O - https://storage.googleapis.com/golang/go1.6.src.tar.gz | tar -xz && \ + cd go/src && GOROOT_BOOTSTRAP=/usr GOARCH=${ARCH} GOHOSTARCH=${ARCH} ./make.bash + +ENV PATH /usr/local/go/bin:$PATH RUN mkdir -p /go/src /go/bin && chmod -R 777 /go ENV GOPATH /go ENV PATH /go/bin:$PATH -RUN pip install tox -RUN curl -sSL https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz | tar -xz -C /usr/local -RUN curl -sL https://get.docker.com/builds/Linux/x86_64/docker-1.10.2 > /usr/local/bin/docker +RUN wget -O - ${DOCKER_BINARY_URL} > /usr/local/bin/docker RUN chmod +x /usr/local/bin/docker ENV DAPPER_DOCKER_SOCKET true ENV DAPPER_SOURCE /go/src/github.com/rancher/os -ENV DAPPER_OUTPUT ./bin ./dist +ENV DAPPER_OUTPUT ./bin ./dist ./build/os-config.yml ENV DAPPER_RUN_ARGS --privileged ENV SHELL /bin/bash WORKDIR ${DAPPER_SOURCE} -COPY .dockerignore.docker .dockerignore +COPY .dockerignore.dapper .dockerignore -RUN cd /usr/local/src && \ - for i in libselinux pcre3 util-linux; do \ - apt-get build-dep -y $i && \ - apt-get source -y $i \ - ;done +CMD make -RUN apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -RUN cd /usr/local/src/pcre3-* && \ - autoreconf && \ - CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ ./configure --host=arm-linux-gnueabihf --prefix=/usr/arm-linux-gnueabihf && \ - make -j$(nproc) && \ - make install +ARG TOOLCHAIN +ENV TOOLCHAIN ${TOOLCHAIN} -RUN cd /usr/local/src/libselinux-* && \ - CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ make CFLAGS=-Wall && \ - make PREFIX=/usr/arm-linux-gnueabihf DESTDIR=/usr/arm-linux-gnueabihf install +RUN if [ "${TOOLCHAIN}" != "" ]; then \ + cd /usr/local/src && \ + for i in libselinux pcre3 util-linux; do \ + apt-get build-dep -y $i && \ + apt-get source -y $i \ + ;done \ + ;fi -RUN cd /usr/local/src/util-linux-* && \ - autoreconf && \ - CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ ./configure --host=arm-linux-gnueabihf --prefix=/usr/arm-linux-gnueabihf \ - --disable-all-programs \ - --enable-libmount \ - --enable-libblkid \ - --enable-libuuid \ - --enable-mount && \ - make -j$(nproc) && \ - make install +RUN if [ "${TOOLCHAIN}" != "" ]; then \ + cd /usr/local/src/pcre3-* && \ + autoreconf && \ + CC=${TOOLCHAIN}-gcc CXX=${TOOLCHAIN}-g++ ./configure --host=${TOOLCHAIN} --prefix=/usr/${TOOLCHAIN} && \ + make -j$(nproc) && \ + make install \ + ;fi -CMD make all +RUN if [ "${TOOLCHAIN}" != "" ]; then \ + cd /usr/local/src/libselinux-* && \ + CC=${TOOLCHAIN}-gcc CXX=${TOOLCHAIN}-g++ make CFLAGS=-Wall && \ + make PREFIX=/usr/${TOOLCHAIN} DESTDIR=/usr/${TOOLCHAIN} install \ + ;fi -ENV DAPPER_OUTPUT ./bin ./dist ./build/os-config.yml +RUN if [ "${TOOLCHAIN}" != "" ]; then \ + cd /usr/local/src/util-linux-* && \ + autoreconf && \ + CC=${TOOLCHAIN}-gcc CXX=${TOOLCHAIN}-g++ ./configure --host=${TOOLCHAIN} --prefix=/usr/${TOOLCHAIN} \ + --disable-all-programs \ + --enable-libmount \ + --enable-libblkid \ + --enable-libuuid \ + --enable-mount && \ + make -j$(nproc) && \ + make install \ + ;fi diff --git a/Makefile b/Makefile index edb7b85d..65b74433 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ FORCE_PULL := 0 DEV_BUILD := 0 ARCH := amd64 +SUFFIX := $(if $(filter-out amd64,$(ARCH)),_$(ARCH)) include build.conf include build.conf.$(ARCH) @@ -12,11 +13,7 @@ bin/ros: build/host_ros: bin/ros mkdir -p $(dir $@) -ifeq "$(ARCH)" "amd64" ln -sf ../bin/ros $@ -else - ARCH=amd64 VERSION=$(VERSION) ./scripts/mk-ros.sh $@ -endif assets/docker: @@ -31,11 +28,11 @@ assets/selinux/policy.29: ifdef COMPILED_KERNEL_URL installer: minimal - docker build -t $(IMAGE_NAME):$(VERSION) . + docker build -t $(IMAGE_NAME):$(VERSION)$(SUFFIX) -f Dockerfile.$(ARCH) . dist/artifacts/vmlinuz: build/kernel/ mkdir -p $(dir $@) - mv build/kernel/boot/vmlinuz* $@ + mv $(or $(wildcard build/kernel/boot/vmlinuz*), $(wildcard build/kernel/boot/vmlinux*)) $@ build/kernel/: diff --git a/build.conf.amd64 b/build.conf.amd64 index bc92e52c..79fa82e1 100644 --- a/build.conf.amd64 +++ b/build.conf.amd64 @@ -1,2 +1,5 @@ +DAPPER_BASE=ubuntu:16.04 +TOOLCHAIN= #empty + COMPILED_KERNEL_URL=https://github.com/rancher/os-kernel/releases/download/Ubuntu-4.2.0-28.33-rancher/linux-4.2.8-ckt3-rancher-x86.tar.gz DOCKER_BINARY_URL=https://get.docker.com/builds/Linux/x86_64/docker-1.10.2 diff --git a/build.conf.arm b/build.conf.arm index 9f64d3d8..ea905e66 100644 --- a/build.conf.arm +++ b/build.conf.arm @@ -1 +1,4 @@ -DOCKER_BINARY_URL=https://github.com/rancher/docker/releases/download/v1.10.2-ros_arm/docker-1.10.2 +DAPPER_BASE=armhf/ubuntu:16.04 +TOOLCHAIN=arm-linux-gnueabihf + +DOCKER_BINARY_URL=https://github.com/rancher/docker/releases/download/v1.10.2-arm2/docker-1.10.2_arm diff --git a/build.conf.arm64 b/build.conf.arm64 new file mode 100644 index 00000000..d2367db9 --- /dev/null +++ b/build.conf.arm64 @@ -0,0 +1,5 @@ +DAPPER_BASE=aarch64/ubuntu:16.04 +TOOLCHAIN=aarch64-linux-gnu + +DOCKER_BINARY_URL=https://github.com/rancher/docker/releases/download/v1.10.2-arm2/docker-1.10.2_arm64 +COMPILED_KERNEL_URL=https://github.com/imikushin/os-kernel/releases/download/Estuary-4.1.18-arm64/linux-4.1.18-arm64.tar.gz diff --git a/build.sh b/build.sh index 8ca7cf59..00abad72 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,10 @@ #!/bin/bash set -e +export ARCH=${ARCH:-amd64} + +cd $(dirname $0) + if [ "$1" != "--dev" ]; then echo echo Running \"production\" build. Will use lzma to compress initrd, which is somewhat slow... @@ -8,10 +12,9 @@ if [ "$1" != "--dev" ]; then echo echo For \"developer\" builds, run ./build.sh --dev echo - dapper make all + ./scripts/make.sh all else - dapper make DEV_BUILD=1 all + ./scripts/make.sh DEV_BUILD=1 all fi - ls -lh dist/artifacts diff --git a/scripts/ci b/scripts/ci index cacce980..4b2bcd7b 100755 --- a/scripts/ci +++ b/scripts/ci @@ -1,7 +1,7 @@ -#!/bin/bash +#!/bin/sh set -ex cd $(dirname $0)/.. +. ./scripts/dapper-common -dapper -O make ARCH=arm rootfs -dapper -O make DEV_BUILD=1 test +dapper -d -O make ARCH=${ARCH} DEV_BUILD=1 test diff --git a/scripts/dapper-common b/scripts/dapper-common new file mode 100755 index 00000000..64bda766 --- /dev/null +++ b/scripts/dapper-common @@ -0,0 +1,21 @@ +#!/bin/sh +set -ex + +guessArch() { + docker version | grep 'OS/Arch:' | tail -n+2 | awk '{print $2}' | cut -f2 -d'/' +} + +ARCH=${ARCH:-"$(guessArch)"} +ARCH=${ARCH:?"Failed to guess ARCH"} +export ARCH + +cd $(dirname $0)/.. + +[ -f "./.docker-env.${ARCH}" ] && . ./.docker-env.${ARCH} || echo "WARNING: missing .docker-env.${ARCH} (to use an ${ARCH} docker host)" + +set -a +. ./build.conf.${ARCH} +set +a + +docker inspect $DAPPER_BASE >/dev/null 2>&1 || docker pull $DAPPER_BASE +docker tag $DAPPER_BASE rancher/os-dapper-base diff --git a/scripts/installer/lay-down-os b/scripts/installer/lay-down-os index cae0414a..b6a80a8c 100755 --- a/scripts/installer/lay-down-os +++ b/scripts/installer/lay-down-os @@ -21,6 +21,7 @@ do *) exit 1 ;; esac done +[ "$ARCH" == "arm" && "$ENV" != "rancher-upgrade" ] && ENV=arm DIST=${DIST:-/dist} CLOUD_CONFIG=${CLOUD_CONFIG:-"${SCRIPTS_DIR}/conf/empty.yml"} @@ -153,6 +154,10 @@ if [ -n ${ENV} ]; then install_grub "${SCRIPTS_DIR}/seed-data" ${BASE_DIR} ${CLOUD_CONFIG} ${FILES} ;; + "arm") + format_and_mount + "${SCRIPTS_DIR}/seed-data" ${BASE_DIR} ${CLOUD_CONFIG} ${FILES} + ;; "amazon-ebs-pv"|"amazon-ebs-hvm") CONSOLE=ttyS0 format_and_mount diff --git a/scripts/make.sh b/scripts/make.sh new file mode 100755 index 00000000..b040e471 --- /dev/null +++ b/scripts/make.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e + +cd $(dirname $0)/.. +. ./scripts/dapper-common + +dapper make ARCH=${ARCH} "$@" diff --git a/scripts/mk-initrd.sh b/scripts/mk-initrd.sh index 021a2fd7..9f34f1b7 100755 --- a/scripts/mk-initrd.sh +++ b/scripts/mk-initrd.sh @@ -3,7 +3,7 @@ set -ex TARGET=$(pwd)/${1} -ARCH=${ARCH:-"amd64"} +ARCH=${ARCH:?"ARCH not set"} DFS_IMAGE=${DFS_IMAGE:?"DFS_IMAGE not set"} IS_ROOTFS=${IS_ROOTFS:-0} @@ -53,12 +53,12 @@ docker export ${DFS_ARCH} | tar xvf - -C ${INITRD_DIR} --exclude=usr/bin/dockerl usr if [ "$IS_ROOTFS" == "1" ]; then - DFS=$(docker run -d --privileged -v /lib/modules/$(uname -r):/lib/modules/$(uname -r) ${DFS_IMAGE}) + DFS=$(docker run -d --privileged -v /lib/modules/$(uname -r):/lib/modules/$(uname -r) ${DFS_ARCH_IMAGE}) trap "docker rm -fv ${DFS_ARCH} ${DFS}" EXIT docker exec -i ${DFS} docker load < ${BUILD}/images.tar docker stop ${DFS} - docker run --rm --volumes-from=${DFS} debian:jessie tar -c -C /var/lib/docker ./image | tar -x -C ${INITRD_DIR}/var/lib/system-docker - docker run --rm --volumes-from=${DFS} debian:jessie tar -c -C /var/lib/docker ./overlay | tar -x -C ${INITRD_DIR}/var/lib/system-docker + docker run --rm --volumes-from=${DFS} rancher/os-dapper-base tar -c -C /var/lib/docker ./image | tar -x -C ${INITRD_DIR}/var/lib/system-docker + docker run --rm --volumes-from=${DFS} rancher/os-dapper-base tar -c -C /var/lib/docker ./overlay | tar -x -C ${INITRD_DIR}/var/lib/system-docker cd ${INITRD_DIR} diff --git a/scripts/mk-ros.sh b/scripts/mk-ros.sh index 2a538f2e..6f32d6af 100755 --- a/scripts/mk-ros.sh +++ b/scripts/mk-ros.sh @@ -8,12 +8,6 @@ VERSION=${VERSION:?"VERSION not set"} cd $(dirname $0)/.. -strip_bin=$(which strip) -if [ "${ARCH}" == "arm" ]; then - export GOARM=6 - export CC=/usr/bin/arm-linux-gnueabihf-gcc - export CGO_ENABLED=1 - strip_bin=/usr/arm-linux-gnueabihf/bin/strip -fi +[ "${ARCH}" == "arm" ] && export GOARM=6 GOARCH=${ARCH} go build -tags netgo -installsuffix netgo -ldflags "-X github.com/rancher/os/config.VERSION=${VERSION} -linkmode external -extldflags -static" -o ${ros} -${strip_bin} --strip-all ${ros} +strip --strip-all ${ros} diff --git a/scripts/run b/scripts/run index ea02a74c..c7ee2281 100755 --- a/scripts/run +++ b/scripts/run @@ -7,6 +7,9 @@ cd $(dirname $0)/.. source scripts/build-common BASE=$(pwd) +UNAME=$(uname) +QEMUARCH=$(uname -m) +[ "${UNAME}" == "Darwin" ] && QEMUARCH=x86_64 KERNEL=${BASE}/dist/artifacts/vmlinuz INITRD=${BASE}/dist/artifacts/initrd @@ -41,7 +44,7 @@ while [ "$#" -gt 0 ]; do fi ;; --qemu) - if [ -x $(which qemu-system-x86_64) ]; then + if [ -x $(which qemu-system-${QEMUARCH}) ]; then QEMU=1 fi ;; @@ -76,7 +79,6 @@ if [[ ! -e ${KERNEL} || ! -e ${INITRD} ]]; then exit 1 fi -UNAME=$(uname) # Linux and Darwin SHA1 sum binary are different, pick which to use if [ "$UNAME" == "Darwin" ]; then sha1sum=$(which shasum) elif [ "$UNAME" == "Linux" ]; then sha1sum=$(which sha1sum); @@ -102,7 +104,7 @@ if [ "$REBUILD" == "1" ]; then mkdir -p ${INITRD_TMP}/usr/{bin,share/ros} cp bin/ros ${INITRD_TMP}/usr/bin/ - cp -f os-config.yml ${INITRD_TMP}/usr/share/ros/ #FIXME: generate os-config.yml from os-config.tpl.yml + cp -f build/os-config.yml ${INITRD_TMP}/usr/share/ros/ pushd ${INITRD_TMP} find . | cpio -H newc -o | gzip > ${INITRD_TEST} @@ -166,7 +168,7 @@ if [ "$XHYVE" == "1" ] || [ "$QEMU" == "1" ]; then if [ "$KVM" == "1" ]; then KVM_ENABLE="-machine accel=kvm -cpu host" fi - exec qemu-system-x86_64 -serial stdio \ + exec qemu-system-${QEMUARCH} -serial stdio \ -kernel ${KERNEL} \ -initrd ${INITRD} \ -m 1024 \ diff --git a/selinux/selinux_linux_arm64.go b/selinux/selinux_linux_arm64.go new file mode 100644 index 00000000..ab4b38b0 --- /dev/null +++ b/selinux/selinux_linux_arm64.go @@ -0,0 +1,6 @@ +package selinux + +// InitializeSelinux is a stub for SELinux support on ARM64 +func InitializeSelinux() (int, error) { + return 0, nil +} diff --git a/util/cutil.go b/util/cutil.go index ac770ef7..07d58b6f 100644 --- a/util/cutil.go +++ b/util/cutil.go @@ -3,7 +3,7 @@ package util /* -#cgo LDFLAGS: -lmount -lblkid -luuid -lselinux +#cgo LDFLAGS: -lmount -lblkid -luuid #include #include #include @@ -34,10 +34,3 @@ func GetFsType(device string) (string, error) { } return "", errors.New("Error while getting fstype") } - -func intToBool(value C.int) bool { - if value == 0 { - return false - } - return true -} From 35ccb325ba415164e33adb2e908b7cef5060acbc Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Thu, 10 Mar 2016 10:23:15 -0800 Subject: [PATCH 6/7] add kexec to arm64 installer image --- Dockerfile.arm64 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 index 5efe1566..5cedb915 100644 --- a/Dockerfile.arm64 +++ b/Dockerfile.arm64 @@ -2,9 +2,12 @@ FROM aarch64/debian:jessie ENV DEBIAN_FRONTEND noninteractive ENV ARCH arm -RUN apt-get update && apt-get install -y parted +RUN apt-get update && apt-get install -y parted git gcc make autoconf -# TODO add kexec-tools: build from sources for aarch64 +RUN mkdir -p /usr/local/src && \ + cd /usr/local/src && \ + git clone https://git.linaro.org/people/takahiro.akashi/kexec-tools.git && \ + cd kexec-tools && git checkout kdump/for-14 && ./bootstrap && ./configure && make && make install COPY ./scripts/installer /scripts COPY ./build.conf /scripts/ From 356f25be20ca0d1811687a71a712fc7655cdcea4 Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Mon, 14 Mar 2016 18:26:21 -0700 Subject: [PATCH 7/7] cross-build is back `HOST_ARCH=arm64 ./make.sh minimal` builds vmlinuz and initrd for arm64 on arm64 (sourcing .docker-env.arm64 in the process) `ARCH=arm ./make.sh rootfs` builds rootfs.tar.gz for arm on your current docker environment --- Dockerfile.dapper | 17 ++++++++++------- Makefile | 9 +++++++-- build.conf.arm | 1 + build.conf.arm64 | 2 +- scripts/ci | 2 +- scripts/dapper-common | 21 ++++++++++----------- scripts/make.sh | 2 +- scripts/mk-initrd.sh | 11 +++-------- scripts/mk-ros.sh | 8 +++++++- 9 files changed, 41 insertions(+), 32 deletions(-) diff --git a/Dockerfile.dapper b/Dockerfile.dapper index e0358e42..d457b461 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -1,24 +1,23 @@ FROM rancher/os-dapper-base -ARG ARCH -ENV ARCH ${ARCH} -ARG DOCKER_BINARY_URL -ENV DOCKER_BINARY_URL ${DOCKER_BINARY_URL} - RUN apt-get update && \ apt-get -y install locales sudo vim less curl wget git rsync build-essential isolinux xorriso gccgo \ libblkid-dev libmount-dev libselinux1-dev cpio genisoimage qemu-kvm python-pip ca-certificates pkg-config tox +ARG HOST_ARCH +ENV HOST_ARCH ${HOST_ARCH} RUN mkdir -p /usr/local && cd /usr/local && \ wget -O - https://storage.googleapis.com/golang/go1.6.src.tar.gz | tar -xz && \ - cd go/src && GOROOT_BOOTSTRAP=/usr GOARCH=${ARCH} GOHOSTARCH=${ARCH} ./make.bash + cd go/src && GOROOT_BOOTSTRAP=/usr GOARCH=${HOST_ARCH} GOHOSTARCH=${HOST_ARCH} ./make.bash ENV PATH /usr/local/go/bin:$PATH RUN mkdir -p /go/src /go/bin && chmod -R 777 /go ENV GOPATH /go ENV PATH /go/bin:$PATH -RUN wget -O - ${DOCKER_BINARY_URL} > /usr/local/bin/docker +ARG HOST_DOCKER_BINARY_URL +ENV HOST_DOCKER_BINARY_URL ${HOST_DOCKER_BINARY_URL} +RUN wget -O - ${HOST_DOCKER_BINARY_URL} > /usr/local/bin/docker RUN chmod +x /usr/local/bin/docker ENV DAPPER_DOCKER_SOCKET true @@ -35,6 +34,10 @@ CMD make ARG TOOLCHAIN ENV TOOLCHAIN ${TOOLCHAIN} +RUN if [ "${TOOLCHAIN}" != "" ] && ! which ${TOOLCHAIN}-gcc; then \ + apt-get install -y gcc-${TOOLCHAIN} g++-${TOOLCHAIN} \ + ;fi + RUN if [ "${TOOLCHAIN}" != "" ]; then \ cd /usr/local/src && \ for i in libselinux pcre3 util-linux; do \ diff --git a/Makefile b/Makefile index 65b74433..cdff12e3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ FORCE_PULL := 0 DEV_BUILD := 0 +HOST_ARCH := amd64 ARCH := amd64 SUFFIX := $(if $(filter-out amd64,$(ARCH)),_$(ARCH)) @@ -13,7 +14,11 @@ bin/ros: build/host_ros: bin/ros mkdir -p $(dir $@) +ifeq "$(ARCH)" "$(HOST_ARCH)" ln -sf ../bin/ros $@ +else + ARCH=$(HOST_ARCH) TOOLCHAIN= VERSION=$(VERSION) ./scripts/mk-ros.sh $@ +endif assets/docker: @@ -42,7 +47,7 @@ build/kernel/: dist/artifacts/initrd: bin/ros assets/docker assets/selinux/policy.29 build/kernel/ build/images.tar mkdir -p $(dir $@) - ARCH=$(ARCH) DFS_IMAGE=$(DFS_IMAGE) DEV_BUILD=$(DEV_BUILD) ./scripts/mk-initrd.sh $@ + SUFFIX=$(SUFFIX) DFS_IMAGE=$(DFS_IMAGE) DEV_BUILD=$(DEV_BUILD) ./scripts/mk-initrd.sh $@ dist/artifacts/rancheros.iso: minimal @@ -74,7 +79,7 @@ build/images.tar: build/host_ros build/os-config.yml dist/artifacts/rootfs.tar.gz: bin/ros assets/docker build/images.tar assets/selinux/policy.29 mkdir -p $(dir $@) - ARCH=$(ARCH) DFS_IMAGE=$(DFS_IMAGE) DEV_BUILD=$(DEV_BUILD) IS_ROOTFS=1 ./scripts/mk-initrd.sh $@ + SUFFIX=$(SUFFIX) DFS_IMAGE=$(DFS_IMAGE) DEV_BUILD=$(DEV_BUILD) IS_ROOTFS=1 ./scripts/mk-initrd.sh $@ dist/artifacts/iso-checksums.txt: dist/artifacts/rancheros.iso diff --git a/build.conf.arm b/build.conf.arm index ea905e66..78e541b7 100644 --- a/build.conf.arm +++ b/build.conf.arm @@ -1,4 +1,5 @@ DAPPER_BASE=armhf/ubuntu:16.04 TOOLCHAIN=arm-linux-gnueabihf +COMPILED_KERNEL_URL= #empty DOCKER_BINARY_URL=https://github.com/rancher/docker/releases/download/v1.10.2-arm2/docker-1.10.2_arm diff --git a/build.conf.arm64 b/build.conf.arm64 index d2367db9..91c1b15d 100644 --- a/build.conf.arm64 +++ b/build.conf.arm64 @@ -1,5 +1,5 @@ DAPPER_BASE=aarch64/ubuntu:16.04 TOOLCHAIN=aarch64-linux-gnu -DOCKER_BINARY_URL=https://github.com/rancher/docker/releases/download/v1.10.2-arm2/docker-1.10.2_arm64 COMPILED_KERNEL_URL=https://github.com/imikushin/os-kernel/releases/download/Estuary-4.1.18-arm64/linux-4.1.18-arm64.tar.gz +DOCKER_BINARY_URL=https://github.com/rancher/docker/releases/download/v1.10.2-arm2/docker-1.10.2_arm64 diff --git a/scripts/ci b/scripts/ci index 4b2bcd7b..e78fd443 100755 --- a/scripts/ci +++ b/scripts/ci @@ -4,4 +4,4 @@ set -ex cd $(dirname $0)/.. . ./scripts/dapper-common -dapper -d -O make ARCH=${ARCH} DEV_BUILD=1 test +dapper -d -O make HOST_ARCH=${HOST_ARCH} ARCH=${ARCH} DEV_BUILD=1 test diff --git a/scripts/dapper-common b/scripts/dapper-common index 64bda766..3f5b7261 100755 --- a/scripts/dapper-common +++ b/scripts/dapper-common @@ -1,21 +1,20 @@ #!/bin/sh set -ex -guessArch() { - docker version | grep 'OS/Arch:' | tail -n+2 | awk '{print $2}' | cut -f2 -d'/' -} - -ARCH=${ARCH:-"$(guessArch)"} -ARCH=${ARCH:?"Failed to guess ARCH"} -export ARCH +HOST_ARCH=${HOST_ARCH:-$(docker version | grep 'OS/Arch:' | tail -n+2 | awk '{print $2}' | cut -f2 -d'/')} +HOST_ARCH=${HOST_ARCH:?"Failed to guess HOST_ARCH"} +ARCH=${ARCH:-"$HOST_ARCH"} +export HOST_ARCH ARCH cd $(dirname $0)/.. -[ -f "./.docker-env.${ARCH}" ] && . ./.docker-env.${ARCH} || echo "WARNING: missing .docker-env.${ARCH} (to use an ${ARCH} docker host)" +[ -f "./.docker-env.${HOST_ARCH}" ] && . ./.docker-env.${HOST_ARCH} || echo "WARNING: missing .docker-env.${HOST_ARCH} (to use an ${HOST_ARCH} docker host)" + +. ./build.conf.${HOST_ARCH} +export HOST_DOCKER_BINARY_URL=${DOCKER_BINARY_URL} +docker inspect $DAPPER_BASE >/dev/null 2>&1 || docker pull $DAPPER_BASE +docker tag $DAPPER_BASE rancher/os-dapper-base set -a . ./build.conf.${ARCH} set +a - -docker inspect $DAPPER_BASE >/dev/null 2>&1 || docker pull $DAPPER_BASE -docker tag $DAPPER_BASE rancher/os-dapper-base diff --git a/scripts/make.sh b/scripts/make.sh index b040e471..4b84c0b0 100755 --- a/scripts/make.sh +++ b/scripts/make.sh @@ -4,4 +4,4 @@ set -e cd $(dirname $0)/.. . ./scripts/dapper-common -dapper make ARCH=${ARCH} "$@" +dapper make HOST_ARCH=${HOST_ARCH} ARCH=${ARCH} "$@" diff --git a/scripts/mk-initrd.sh b/scripts/mk-initrd.sh index 9f34f1b7..31c02ad0 100755 --- a/scripts/mk-initrd.sh +++ b/scripts/mk-initrd.sh @@ -3,15 +3,10 @@ set -ex TARGET=$(pwd)/${1} -ARCH=${ARCH:?"ARCH not set"} +SUFFIX=${SUFFIX:-""} DFS_IMAGE=${DFS_IMAGE:?"DFS_IMAGE not set"} IS_ROOTFS=${IS_ROOTFS:-0} -suffix="" -[ "$ARCH" == "amd64" ] || suffix="_${ARCH}" - -DFS_ARCH_IMAGE=${DFS_IMAGE}${suffix} - cd $(dirname $0)/.. . scripts/build-common @@ -41,7 +36,7 @@ cp assets/selinux/seusers ${INITRD_DIR}/usr/etc/selinux/ros/ cp assets/selinux/lxc_contexts ${INITRD_DIR}/usr/etc/selinux/ros/contexts/ cp assets/selinux/failsafe_context ${INITRD_DIR}/usr/etc/selinux/ros/contexts/ -DFS_ARCH=$(docker create ${DFS_ARCH_IMAGE}) +DFS_ARCH=$(docker create ${DFS_IMAGE}${SUFFIX}) trap "docker rm -fv ${DFS_ARCH}" EXIT docker export ${DFS_ARCH} | tar xvf - -C ${INITRD_DIR} --exclude=usr/bin/dockerlaunch \ @@ -53,7 +48,7 @@ docker export ${DFS_ARCH} | tar xvf - -C ${INITRD_DIR} --exclude=usr/bin/dockerl usr if [ "$IS_ROOTFS" == "1" ]; then - DFS=$(docker run -d --privileged -v /lib/modules/$(uname -r):/lib/modules/$(uname -r) ${DFS_ARCH_IMAGE}) + DFS=$(docker run -d --privileged -v /lib/modules/$(uname -r):/lib/modules/$(uname -r) ${DFS_IMAGE}) trap "docker rm -fv ${DFS_ARCH} ${DFS}" EXIT docker exec -i ${DFS} docker load < ${BUILD}/images.tar docker stop ${DFS} diff --git a/scripts/mk-ros.sh b/scripts/mk-ros.sh index 6f32d6af..59034235 100755 --- a/scripts/mk-ros.sh +++ b/scripts/mk-ros.sh @@ -8,6 +8,12 @@ VERSION=${VERSION:?"VERSION not set"} cd $(dirname $0)/.. +strip_bin=$(which strip) [ "${ARCH}" == "arm" ] && export GOARM=6 +if [ "${TOOLCHAIN}" != "" ]; then + export CC=/usr/bin/${TOOLCHAIN}-gcc + export CGO_ENABLED=1 + strip_bin=/usr/${TOOLCHAIN}/bin/strip +fi GOARCH=${ARCH} go build -tags netgo -installsuffix netgo -ldflags "-X github.com/rancher/os/config.VERSION=${VERSION} -linkmode external -extldflags -static" -o ${ros} -strip --strip-all ${ros} +${strip_bin} --strip-all ${ros}