1
0
mirror of https://github.com/rancher/os.git synced 2025-08-31 14:23:11 +00:00

Multi-arch build

Currently, for amd64 (the default) and arm.
Run `dapper make ARCH=arm rootfs` to build rootfs.tar.gz for arm.
This commit is contained in:
Ivan Mikushin
2016-01-15 18:18:30 +05:00
parent 3a0aebe738
commit 2f27271a2c
18 changed files with 531 additions and 73 deletions

View File

@@ -1,13 +1,15 @@
#!/bin/bash
set -ex
suffix=""
[ "$ARCH" == "amd64" ] || suffix="_${ARCH}"
cd $(dirname $0)/..
. scripts/build-common
ln -sf bin/rancheros ./ros
for i in `./ros c images -i os-config.yml`; do
images="$(build/host_ros c images -i os-config${suffix}.yml)"
for i in ${images}; do
[ "${FORCE_PULL}" != "1" ] && docker inspect $i >/dev/null 2>&1 || docker pull $i;
done
docker save `./ros c images -i os-config.yml` > ${BUILD}/images.tar
docker save ${images} > ${BUILD}/images.tar

View File

@@ -1,6 +1,17 @@
#!/bin/bash
set -ex
TARGET=${1}
ARCH=${ARCH:-"amd64"}
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
@@ -8,29 +19,48 @@ INITRD_DIR=${BUILD}/initrd
rm -rf ${INITRD_DIR}/{usr,init}
mkdir -p ${INITRD_DIR}/usr/{bin,share/ros}
mkdir -p ${INITRD_DIR}/var/lib/system-docker
cp -rf ${BUILD}/kernel/lib ${INITRD_DIR}/usr
if [ "$IS_ROOTFS" == "0" ]; then
cp -rf ${BUILD}/kernel/lib ${INITRD_DIR}/usr/
fi
cp assets/docker ${INITRD_DIR}/usr/bin/docker
cp ${BUILD}/images.tar ${INITRD_DIR}/usr/share/ros
cp os-config.yml ${INITRD_DIR}/usr/share/ros/
cp bin/rancheros ${INITRD_DIR}/usr/bin/ros
if [ "$IS_ROOTFS" == "0" ]; then
cp ${BUILD}/images.tar ${INITRD_DIR}/usr/share/ros/
fi
cp os-config${suffix}.yml ${INITRD_DIR}/usr/share/ros/os-config.yml
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
DFS=$(docker create ${DFS_IMAGE})
trap "docker rm -fv ${DFS}" EXIT
docker export ${DFS} | tar xvf - -C ${INITRD_DIR} --exclude=usr/bin/dockerlaunch \
--exclude=usr/bin/docker \
--exclude=usr/share/git-core \
--exclude=usr/bin/git \
--exclude=usr/bin/ssh \
--exclude=usr/libexec/git-core \
usr
DFS_ARCH=$(docker create ${DFS_ARCH_IMAGE})
trap "docker rm -fv ${DFS_ARCH}" EXIT
if [ "$DEV_BUILD" == "1" ]; then
COMPRESS="gzip -1"
docker export ${DFS_ARCH} | tar xvf - -C ${INITRD_DIR} --exclude=usr/bin/dockerlaunch \
--exclude=usr/bin/docker \
--exclude=usr/share/git-core \
--exclude=usr/bin/git \
--exclude=usr/bin/ssh \
--exclude=usr/libexec/git-core \
usr
if [ "$IS_ROOTFS" == "1" ]; then
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}
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
cd ${INITRD_DIR}
tar -czf ${TARGET} .
else
COMPRESS=lzma
fi
COMPRESS=lzma
[ "$DEV_BUILD" == "1" ] && COMPRESS="gzip -1"
cd ${INITRD_DIR} && find | cpio -H newc -o | ${COMPRESS} > ${DIST}/artifacts/initrd
cd ${INITRD_DIR}
find | cpio -H newc -o | ${COMPRESS} > ${TARGET}
fi

19
scripts/mk-ros.sh Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
set -ex
ros="$1"
ARCH=${ARCH:?"ARCH not set"}
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
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}

View File

@@ -101,8 +101,8 @@ if [ "$REBUILD" == "1" ]; then
ln -s ${INITRD_TMP} ${INITRD_CURRENT}
mkdir -p ${INITRD_TMP}/usr/{bin,share/ros}
cp bin/rancheros ${INITRD_TMP}/usr/bin/ros
cp -f os-config.yml ${INITRD_TMP}/usr/share/ros
cp bin/ros ${INITRD_TMP}/usr/bin/
cp -f os-config.yml ${INITRD_TMP}/usr/share/ros/
pushd ${INITRD_TMP}
find . | cpio -H newc -o | gzip > ${INITRD_TEST}