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

Commit

Permalink
Merge pull request #28 from hypriot/update-build
Browse files Browse the repository at this point in the history
Update the build steps and installed versions
  • Loading branch information
StefanScherer committed Mar 8, 2017
2 parents c6497b5 + ed04689 commit 87698b4
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 110 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.img
*.img.zip
*.img.zip.sha256
*.tar.gz
.vagrant/
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ branches:
- /^v\d.*$/
deploy:
provider: releases
api_key:
secure: ZxbGrH2fjRBSFrCy3Q7kqOBZs/qeZ8QYXz3ZrbGBaoZlZuz9lZbrpBxwcaUbruyKvxx/J7iNeVBuSobz36K+qWQCe5OxOKkg14KzY0EOE6dLeIXWkTYX2ywYGgvlpzEhooly5KC6eJu5i3jyWjpUCBYOndZrAj4Zokx5v8hBQoLwf0LZB/KRQx7YAuz3f8jOkI881e+ic2rV+SNGPbocyNpcUZEBxeH2tsM+tBui7dThtSXzdc4QsJXnrsMrd+UAlrWqG+DTM+f+o9MWQbIOvY28pwHg2cdaIpd6+Y8tt1v+oT1nWThsaKQRYrk8wzi3SjoHTanaVuBa9jGaW4zzzl7zjGn385WN5FCwPoO3FTi+xOOzpWwucASXjs5LtQkgYfObk4Eo0LRdrjpfQZTlIzmoXElYSWWhhvQQh1gpagG/mCHGv/Vk09DDNHExk+U3KCR7BZISHiJ5F8Km3/1Gm27ewsO5cA8aGL6C6AwzynB7hkQgGvbnYr8MoeI2cfxKAKE1cH3zebdimas1gs/zsTDFIjrmu4bruZYf5V/I4MGsG3B/pwWsdWmRKRdOpylNNM/R791w3Ln/36oDqwQhHj5v7tlrNOqDa6hNg9YuKpOOBZMMHElxmqID0SepJzOZPv2EjFVOV5p7cpPL8z5NTy6mL9ZXpw4pj5s/6UjYzmk=
skip_cleanup: true
api_key: ${GITHUB_TOKEN}
file:
- sd-card-odroid-c1-${TRAVIS_TAG}.img.zip
- hypriotos-odroid-c1-${TRAVIS_TAG}.img.zip
- hypriotos-odroid-c1-${TRAVIS_TAG}.img.zip.sha256
on:
tags: true
repo: hypriot/image-builder-odroid-c1
26 changes: 3 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
FROM debian:jessie
FROM hypriot/image-builder:latest

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
python-pip \
build-essential \
libguestfs-tools \
libncurses5-dev \
tree \
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
binfmt-support \
qemu \
qemu-user-static \
debootstrap \
kpartx \
lvm2 \
dosfstools \
zip \
unzip \
pigz \
awscli \
ruby \
ruby-dev \
shellcheck \
--no-install-recommends && \
rm -rf /var/lib/apt/lists/*

RUN gem update --system && \
gem install --no-document serverspec && \
gem install --no-document pry-byebug && \
gem install --no-document bundler

COPY builder/ /builder/

# build sd card image
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ testshell: build
docker run -ti --privileged -v $(shell pwd)/builder:/builder -v $(shell pwd):/workspace -v /boot:/boot -v /lib/modules:/lib/modules image-builder-odroid-c1 bash

test:
VERSION=dirty docker run --rm -ti --privileged -v $(shell pwd):/workspace -v /boot:/boot -v /lib/modules:/lib/modules -e VERSION image-builder-odroid-c1 bash -c "unzip /workspace/sd-card-odroid-c1-dirty.img.zip && rspec --format documentation --color /workspace/builder/test/*_spec.rb"
VERSION=dirty docker run --rm -ti --privileged -v $(shell pwd):/workspace -v /boot:/boot -v /lib/modules:/lib/modules -e VERSION image-builder-odroid-c1 bash -c "unzip /workspace/hypriotos-odroid-c1-dirty.img.zip && rspec --format documentation --color /workspace/builder/test/*_spec.rb"

shellcheck: build
VERSION=dirty docker run --rm -ti -v $(shell pwd):/workspace image-builder-odroid-c1 bash -c 'shellcheck /workspace/builder/*.sh /workspace/builder/files/etc/firstboot.d/*'
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ eval $(docker-machine env image-builder-odroid-c1)

### Build the SD card image

From here you can just make the SD card image. The output will be written and compressed to `sd-card-odroid-c1-dirty.img.zip`.
From here you can just make the SD card image. The output will be written and compressed to `hypriotos-odroid-c1-dirty.img.zip`.

```bash
make sd-image
Expand All @@ -55,7 +55,7 @@ make test
Now flash the SD card image and boot up a ODROID C1. Run the [Serverspec](http://serverspec.org) integration tests in `builder/test-integration/` folder against your ODROID C1. Set the environment variable `BOARD` to the IP address or host name of your running ODROID C1.

```bash
flash sd-card-odroid-c1-dirty.img.zip
flash hypriotos-odroid-c1-dirty.img.zip
BOARD=black-pearl.local make test-integration
```

Expand Down
74 changes: 42 additions & 32 deletions builder/build.sh
Original file line number Diff line number Diff line change
@@ -1,77 +1,86 @@
#!/bin/bash
set -ex
# This script should be run only inside of a Docker container
if [ ! -f /.dockerinit ]; then
if [ ! -f /.dockerenv ]; then
echo "ERROR: script works only in a Docker container!"
exit 1
fi

# get versions for software that needs to be installed
source /workspace/versions.config

### setting up some important variables to control the build process

# where to store our created sd-image file
BUILD_RESULT_PATH="/workspace"

# place to build our sd-image
BUILD_PATH="/build"

# where to store our base file system
HYPRIOT_OS_VERSION="v0.7.2"
ROOTFS_TAR="rootfs-armhf-${HYPRIOT_OS_VERSION}.tar.gz"
ROOTFS_TAR="rootfs-armhf-debian-${HYPRIOT_OS_VERSION}.tar.gz"
ROOTFS_TAR_PATH="$BUILD_RESULT_PATH/$ROOTFS_TAR"

# Show TRAVSI_TAG in travis builds
echo TRAVIS_TAG="${TRAVIS_TAG}"

# size of root and boot partion
ROOT_PARTITION_SIZE="800M"

# device specific settings
HYPRIOT_IMAGE_VERSION=${VERSION:="dirty"}
HYPRIOT_IMAGE_NAME="sd-card-odroid-c1-${HYPRIOT_IMAGE_VERSION}.img"
HYPRIOT_IMAGE_NAME="hypriotos-odroid-c1-${HYPRIOT_IMAGE_VERSION}.img"
IMAGE_ROOTFS_PATH="/image-rootfs.tar.gz"
QEMU_ARCH="arm"
export HYPRIOT_IMAGE_VERSION

# specific versions of kernel/firmware and docker tools
export KERNEL_VERSION="142-1"
export DOCKER_ENGINE_VERSION="1.10.1-1"
export DOCKER_COMPOSE_VERSION="1.6.0-27"
export DOCKER_MACHINE_VERSION="0.4.1-72"

# create build directory for assembling our image filesystem
rm -rf $BUILD_PATH
mkdir -p $BUILD_PATH
rm -rf ${BUILD_PATH}
mkdir ${BUILD_PATH}

# download our base root file system
if [ ! -f $ROOTFS_TAR_PATH ]; then
wget -q -O $ROOTFS_TAR_PATH https://github.com/hypriot/os-rootfs/releases/download/$HYPRIOT_OS_VERSION/$ROOTFS_TAR
if [ ! -f "${ROOTFS_TAR_PATH}" ]; then
wget -q -O "${ROOTFS_TAR_PATH}" "https://github.com/hypriot/os-rootfs/releases/download/${HYPRIOT_OS_VERSION}/${ROOTFS_TAR}"
fi

# verify checksum of our root filesystem
echo "${ROOTFS_TAR_CHECKSUM} ${ROOTFS_TAR_PATH}" | sha256sum -c -

# extract root file system
tar -xzf $ROOTFS_TAR_PATH -C $BUILD_PATH
tar xf "${ROOTFS_TAR_PATH}" -C "${BUILD_PATH}"

# register qemu-arm with binfmt
update-binfmts --enable qemu-$QEMU_ARCH

# set up mount points for pseudo filesystems
mkdir -p $BUILD_PATH/{proc,sys,dev/pts}
# set up mount points for the pseudo filesystems
mkdir -p ${BUILD_PATH}/{proc,sys,dev/pts}

mount -o bind /dev $BUILD_PATH/dev
mount -o bind /dev/pts $BUILD_PATH/dev/pts
mount -t proc none $BUILD_PATH/proc
mount -t sysfs none $BUILD_PATH/sys
mount -o bind /dev ${BUILD_PATH}/dev
mount -o bind /dev/pts ${BUILD_PATH}/dev/pts
mount -t proc none ${BUILD_PATH}/proc
mount -t sysfs none ${BUILD_PATH}/sys

#---modify image---
# modify/add image files directly
cp -R /builder/files/* $BUILD_PATH/
# e.g. root partition resize script
cp -R /builder/files/* ${BUILD_PATH}/

# modify image in chroot environment
chroot $BUILD_PATH /bin/bash </builder/chroot-script.sh
#---modify image---
# make our build directory the current root
# and install the kernel packages, docker tools
# and some customizations for Odroid C2.
chroot $BUILD_PATH /bin/bash < /builder/chroot-script.sh

umount -l $BUILD_PATH/sys || true
umount -l $BUILD_PATH/proc || true
umount -l $BUILD_PATH/dev/pts || true
umount -l $BUILD_PATH/dev || true
# unmount pseudo filesystems
umount -l $BUILD_PATH/sys
umount -l $BUILD_PATH/proc
umount -l $BUILD_PATH/dev/pts
umount -l $BUILD_PATH/dev

# package image rootfs
tar -czf $IMAGE_ROOTFS_PATH -C $BUILD_PATH .

# package image filesytem into two tarballs - one for bootfs and one for rootfs
# ensure that there are no leftover artifacts in the pseudo filesystems
rm -rf ${BUILD_PATH}/{dev,sys,proc}/*

# create the image and add a single ext4 filesystem
# --- important settings for ODROID SD card
# - initialise the partion with MBR
Expand Down Expand Up @@ -117,7 +126,8 @@ fdisk -l "/$HYPRIOT_IMAGE_NAME"
umask 0000

# compress image
pigz --zip -c "$HYPRIOT_IMAGE_NAME" > "$BUILD_RESULT_PATH/$HYPRIOT_IMAGE_NAME.zip"
zip "${BUILD_RESULT_PATH}/${HYPRIOT_IMAGE_NAME}.zip" "${HYPRIOT_IMAGE_NAME}"
cd ${BUILD_RESULT_PATH} && sha256sum "${HYPRIOT_IMAGE_NAME}.zip" > "${HYPRIOT_IMAGE_NAME}.zip.sha256" && cd -

# test sd-image that we have built
VERSION=${HYPRIOT_IMAGE_VERSION} rspec --format documentation --color /builder/test
23 changes: 8 additions & 15 deletions builder/chroot-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,25 @@ apt-get update

# install Hypriot packages for using Docker
apt-get install -y \
"docker-hypriot=${DOCKER_ENGINE_VERSION}" \
"docker-compose=${DOCKER_COMPOSE_VERSION}" \
"docker-machine=${DOCKER_MACHINE_VERSION}"

#FIXME: should be handled in .deb package
# setup Docker default configuration for ODROID C1
rm -f /etc/init.d/docker # we're using a pure systemd init, remove sysvinit script
rm -f /etc/default/docker
# --get upstream config
wget -q -O /etc/default/docker https://github.com/docker/docker/raw/master/contrib/init/sysvinit-debian/docker.default
# --enable aufs by default
sed -i "/#DOCKER_OPTS/a \
DOCKER_OPTS=\"--storage-driver=aufs -D\"" /etc/default/docker

#FIXME: should be handled in .deb package
# enable Docker systemd service
systemctl enable docker

# install ODROID kernel

apt-get install -y u-boot-tools initramfs-tools

# set up Docker APT repository and install docker-engine package
#TODO: pin package version to ${DOCKER_ENGINE_VERSION}
curl -sSL https://get.docker.com | /bin/sh

# make the kernel package create a copy of the current kernel here
touch /boot/uImage
apt-get install -y "linux-image-c1=${KERNEL_VERSION}"

# cleanup APT cache and lists
apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# set device label and version number
echo "HYPRIOT_DEVICE=\"$HYPRIOT_DEVICE\"" >> /etc/os-release
echo "HYPRIOT_IMAGE_VERSION=\"$HYPRIOT_IMAGE_VERSION\"" >> /etc/os-release
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
it { should be_file }
it { should be_owned_by 'root' }
its(:content) { should match 'HYPRIOT_OS="HypriotOS/armhf"' }
its(:content) { should match 'HYPRIOT_OS_VERSION="v0.7.2"' }
its(:content) { should match 'HYPRIOT_OS_VERSION="v1.1.1"' }
its(:content) { should match 'HYPRIOT_DEVICE="ODROID C1/C1\+"' }
its(:content) { should match 'HYPRIOT_IMAGE_VERSION=' }
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

describe command('dpkg -l docker-compose') do
its(:stdout) { should match /ii docker-compose/ }
its(:stdout) { should match /1.6.0-27/ }
its(:stdout) { should match /1.9.0-23/ }
its(:exit_status) { should eq 0 }
end

Expand All @@ -17,6 +17,6 @@
end

describe command('docker-compose --version') do
its(:stdout) { should match /1.6.0/m }
its(:stdout) { should match /1.9.0/m }
its(:exit_status) { should eq 0 }
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

describe command('dpkg -l docker-machine') do
its(:stdout) { should match /ii docker-machine/ }
its(:stdout) { should match /0.4.1-72/ }
its(:stdout) { should match /0.9.0-39/ }
its(:exit_status) { should eq 0 }
end

Expand All @@ -17,17 +17,6 @@
end

describe command('docker-machine --version') do
its(:stdout) { should match /0.4.1/m }
its(:stderr) { should match /^$/ }
its(:stdout) { should match /0.9.0/m }
its(:exit_status) { should eq 0 }
end

describe command('docker-machine create --help') do
its(:stdout) { should match /Available drivers:.*hypriot/ }
its(:stdout) { should match /--hypriot-ip-address/ }
its(:stdout) { should match /--hypriot-ssh-key/ }
its(:stdout) { should match /--hypriot-ssh-port/ }
its(:stdout) { should match /--hypriot-ssh-user/ }
its(:stderr) { should match /^$/ }
its(:exit_status) { should eq 0 }
end
Loading

0 comments on commit 87698b4

Please sign in to comment.