From 5bf4d2c117c842a45995ec0a3c17d3b7f148e5d5 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Tue, 31 May 2016 21:11:03 -0700 Subject: [PATCH] More build script changes --- .dockerignore | 3 +++ .gitignore | 3 ++- Dockerfile.dapper | 13 +++++++++---- Makefile | 3 +++ scripts/build-target | 3 ++- scripts/hash-initrd | 5 +++++ scripts/layout | 23 ++++++++++++++--------- scripts/run | 1 + scripts/test | 5 ++++- 9 files changed, 43 insertions(+), 16 deletions(-) create mode 100755 scripts/hash-initrd diff --git a/.dockerignore b/.dockerignore index b48c7fd1..f0bbe46d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -10,3 +10,6 @@ tests/integration/.venv* tests/integration/.tox */*/*/*.pyc */*/*/__pycache__ +.trash-cache +.dapper +vendor/*/*/*/.git diff --git a/.gitignore b/.gitignore index 5709f3cb..b8d58c6e 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ /tests/integration/.idea *.pyc __pycache__ -.dapper +/.dapper +/.trash-cache diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 85416c72..3314dfe6 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -1,4 +1,5 @@ FROM ubuntu:16.04 +# FROM arm64=aarch64/ubuntu:16.04 arm=armhf/ubuntu:16.04 RUN apt-get update && \ apt-get install -y \ @@ -33,6 +34,7 @@ ENV DAPPER_DOCKER_SOCKET true ENV DAPPER_SOURCE /go/src/github.com/rancher/os ENV DAPPER_OUTPUT ./bin ./dist ./build/initrd ENV DAPPER_RUN_ARGS --privileged +ENV TRASH_CACHE ${DAPPER_SOURCE}/.trash-cache ENV SHELL /bin/bash WORKDIR ${DAPPER_SOURCE} @@ -73,6 +75,7 @@ ARG OS_BASE_URL_arm=https://github.com/rancher/os-base/releases/download/v2016.0 ###################################################### # Set up environment +ENV GOARCH $ARCH ENV DOCKER_URL DOCKER_URL_${ARCH} ENV KERNEL_URL KERNEL_URL_${ARCH} ENV OS_BASE_URL OS_BASE_URL_${ARCH} @@ -120,6 +123,12 @@ RUN URL=DOCKER_URL_${HOST_ARCH} && \ # Install Docker RUN curl -fL ${!DOCKER_URL} > ${DOWNLOADS}/docker && \ chmod +x ${DOWNLOADS}/docker +# Install Trash +RUN go get github.com/rancher/trash + +# Install dapper +RUN curl -sL https://releases.rancher.com/dapper/latest/dapper-`uname -s`-`uname -m` > /usr/bin/dapper && \ + chmod +x /usr/bin/dapper # Install toolchain RUN TOOLCHAIN=TOOLCHAIN_${ARCH} && \ @@ -168,10 +177,6 @@ RUN source /usr/src/toolchain-env; if [ "${TOOLCHAIN}" != "" ]; then \ make install \ ;fi -ENV GOARCH $ARCH - -RUN curl -sL https://releases.rancher.com/dapper/latest/dapper-`uname -s`-`uname -m` > /usr/bin/dapper && \ - chmod +x /usr/bin/dapper RUN mkdir -p images/00-rootfs/build && \ curl -pfL ${!OS_BASE_URL} | tar xvJf - -C images/00-rootfs/build diff --git a/Makefile b/Makefile index 77bc9b70..c085ff61 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,9 @@ run: build/initrd/.id dapper -m bind build-target ./scripts/run +shell-bind: + dapper -m bind -s + clean: @./scripts/clean diff --git a/scripts/build-target b/scripts/build-target index abe0f2cf..9b96c9c7 100755 --- a/scripts/build-target +++ b/scripts/build-target @@ -14,4 +14,5 @@ fi OUTPUT=${OUTPUT:-bin/ros} echo Building $OUTPUT -go build -tags netgo -installsuffix netgo -ldflags "-X github.com/rancher/os/config.VERSION=${VERSION} -linkmode external -extldflags -static" -o ${OUTPUT} +go build -tags "selinux cgo daemon netgo" -installsuffix netgo -ldflags "-X github.com/rancher/os/config.VERSION=${VERSION} -linkmode external -extldflags -static" -o ${OUTPUT} +strip --strip-all ${OUTPUT} diff --git a/scripts/hash-initrd b/scripts/hash-initrd new file mode 100755 index 00000000..15576562 --- /dev/null +++ b/scripts/hash-initrd @@ -0,0 +1,5 @@ +#!/bin/bash + +cd $(dirname $0)/../build/initrd + +md5sum $(find -type f | sort -u ) | md5sum - | awk '{print $1}' > .id diff --git a/scripts/layout b/scripts/layout index 2e92d3be..9cbebccf 100755 --- a/scripts/layout +++ b/scripts/layout @@ -24,7 +24,19 @@ ln -s usr/sbin ${INITRD_DIR}/sbin if [ -e ${DOWNLOADS}/kernel.tar.gz ]; then - tar xf ${DOWNLOADS}/kernel.tar.gz -C ${INITRD_DIR}/usr/ lib/ + mkdir -p ${BUILD}/kernel + tar xf ${DOWNLOADS}/kernel.tar.gz -C ${BUILD}/kernel + + if [ -e ${BUILD}/kernel/boot/vmlinuz-* ]; then + mkdir -p dist/artifacts + cp ${BUILD}/kernel/boot/vmlinuz-* dist/artifacts/vmlinuz + fi + + 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/*) + fi fi if [ -e ${DOWNLOADS}/policy.29 ]; then @@ -43,11 +55,4 @@ docker export ${DFS_ARCH} | tar xf - -C ${INITRD_DIR} --exclude=usr/bin/dockerla --exclude=usr/libexec/git-core \ usr -tar xf ${DOWNLOADS}/kernel.tar.gz -C ${BUILD} boot/ - -if [ -e ${BUILD}/boot/vmlinuz-* ]; then - mkdir -p dist/artifacts - cp ${BUILD}/boot/vmlinuz-* dist/artifacts/vmlinuz -fi - -cat /proc/sys/kernel/random/uuid > ${INITRD_DIR}/.id +./scripts/hash-initrd diff --git a/scripts/run b/scripts/run index ab34044c..01086b41 100755 --- a/scripts/run +++ b/scripts/run @@ -111,6 +111,7 @@ fi if [ "$REBUILD" == "1" ] || [ ! -e ${INITRD} ]; then cp bin/ros ${INITRD_SRC}/usr/bin/ros + ./scripts/hash-initrd pushd ${INITRD_SRC} >/dev/null find . | cpio -H newc -o | gzip -1 > ${INITRD} popd >/dev/null diff --git a/scripts/test b/scripts/test index 5af23658..e188270f 100755 --- a/scripts/test +++ b/scripts/test @@ -8,4 +8,7 @@ echo Running tests PACKAGES=". $(find -name '*.go' | xargs -I{} dirname {} | cut -f2 -d/ | sort -u | grep -Ev '(^\.$|.git|.trash-cache|vendor|bin)' | sed -e 's!^!./!' -e 's!$!/...!')" -go test -race -cover -tags=test ${PACKAGES} +if [ "$ARCH" = "amd64" ]; then + RACE="-race" +fi +go test $RACE -cover -tags=test ${PACKAGES}