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 #19 from hypriot/update-rootfs-0.7.0
Browse files Browse the repository at this point in the history
Update rootfs v0.7.0
  • Loading branch information
StefanScherer committed Feb 12, 2016
2 parents c6110ed + 5d5d177 commit 97e93df
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 56 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ services:
- docker
language: bash
script:
- make sd-image
- make shellcheck
- VERSION=${TRAVIS_TAG} make sd-image
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=
file:
- sd-card-odroid-c1.img.zip
file:
- sd-card-odroid-c1-${TRAVIS_TAG}.img.zip
on:
tags: true
repo: hypriot/image-builder-odroid-c1
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
kpartx \
lvm2 \
dosfstools \
zip \
unzip \
pigz \
awscli \
ruby \
ruby-dev \
shellcheck \
--no-install-recommends && \
rm -rf /var/lib/apt/lists/*

Expand Down
29 changes: 27 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,39 @@ build:
docker build -t image-builder-odroid-c1 .

sd-image: build
docker run --rm --privileged -v $(shell pwd):/workspace -v /boot:/boot -v /lib/modules:/lib/modules image-builder-odroid-c1
docker run --rm --privileged -v $(shell pwd):/workspace -v /boot:/boot -v /lib/modules:/lib/modules -e VERSION image-builder-odroid-c1

shell: build
docker run -ti --privileged -v $(shell pwd):/workspace -v /boot:/boot -v /lib/modules:/lib/modules image-builder-odroid-c1 bash
docker run -ti --privileged -v $(shell pwd):/workspace -v /boot:/boot -v /lib/modules:/lib/modules -e VERSION image-builder-odroid-c1 bash

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"

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/*'

vagrant:
vagrant up

docker-machine: vagrant
docker-machine create -d generic \
--generic-ssh-user $(shell vagrant ssh-config | grep ' User ' | cut -d ' ' -f 4) \
--generic-ssh-key $(shell vagrant ssh-config | grep IdentityFile | cut -d ' ' -f 4) \
--generic-ip-address $(shell vagrant ssh-config | grep HostName | cut -d ' ' -f 4) \
--generic-ssh-port $(shell vagrant ssh-config | grep Port | cut -d ' ' -f 4) \
image-builder-odroid-c1

test-integration: test-integration-image test-integration-docker

test-integration-image:
docker run --rm -ti -v $(shell pwd)/builder/test-integration:/serverspec:ro -e BOARD uzyexe/serverspec:2.24.3 bash -c "rspec --format documentation --color spec/hypriotos-image"

test-integration-docker:
docker run --rm -ti -v $(shell pwd)/builder/test-integration:/serverspec:ro -e BOARD uzyexe/serverspec:2.24.3 bash -c "rspec --format documentation --color spec/hypriotos-docker"

tag:
git tag ${TAG}
git push origin ${TAG}
58 changes: 45 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,30 @@
[![Build Status](https://travis-ci.org/hypriot/image-builder-odroid-c1.svg)](https://travis-ci.org/hypriot/image-builder-odroid-c1)


This is work in progress and not yet finished.
**Disclaimer:** This is work in progress and not yet finished. But if you want to help us and give feedback for the upcoming HypriotOS please read on. You can find the latest SD-Card image in the [GitHub releases page](https://github.com/hypriot/image-builder-odroid-c1/releases).

# Setting up build environment
Make sure you have [vagrant](https://docs.vagrantup.com/v2/installation/) and [docker-machine](https://docs.docker.com/machine/install-machine/) installed.
This repo builds the SD card image with HypriotOS for the Raspberry Pi 2. To build this SD-Card image we have to

A `vagrant up` in the root folder of this repository sets up a Ubuntu Trusty VM with the latest Docker installed.
* take the files for the root filesystem from [`os-rootfs`](https://github.com/hypriot/os-rootfs)
* add Hypriot's Debian repos
* install the ODROID kernel
* install Docker tools Docker Engine, Docker Compose and Docker Machine

To use this Docker instance from your host one can use `docker-machine`.
To set it up with your Vagrant VM execute the following command:
Here is an example how all the GitHub repos play together:

![Architecture](http://blog.hypriot.com/images/hypriotos-xxx/hypriotos_buildpipeline.jpg)

## Contributing

You can contribute to this repo by forking it and sending us pull requests. Feedback is always welcome!

You can build the SD-Card image locally with Vagrant.

### Setting up build environment
Make sure you have [vagrant](https://docs.vagrantup.com/v2/installation/) and [docker-machine](https://docs.docker.com/machine/install-machine/) installed. Then run the following command to create the Vagrant box and the Docker Machine connection. The Vagrant box is needed as a vanilla boot2docker VM is not able to run guestfish inside.

```bash
docker-machine create -d generic \
--generic-ssh-user $(vagrant ssh-config | grep ' User ' | awk '{print $2}') \
--generic-ssh-key $(vagrant ssh-config | grep IdentityFile | awk '{gsub(/"/, "", $2); print $2}') \
--generic-ip-address $(vagrant ssh-config | grep HostName | awk '{print $2}') \
--generic-ssh-port $(vagrant ssh-config | grep Port | awk '{print $2}') \
image-builder-odroid-c1
make docker-machine
```

Now set the Docker environments to this new docker machine:
Expand All @@ -28,8 +35,33 @@ Now set the Docker environments to this new docker machine:
eval $(docker-machine env image-builder-odroid-c1)
```

From here just use `make` to make a new SD-Card image:
### 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`.

```bash
make sd-image
```

### Run Serverspec tests

To test the compressed SD-Card image with [Serverspec](http://serverspec.org) just run the following command. It will expand the SD-Card image in a Docker container and run the Serverspec tests in `builder/test/` folder against it.

```bash
make test
```

### Run integration tests

Now flash the SD-Card image and boot up a Raspberry Pi. Run the [Serverspec](http://serverspec.org) integration tests in `builder/test-integration/` folder against your Raspberry Pi. Set the environment variable `BOARD` to the IP address or host name of your running Raspberry Pi.

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

This test works with any Docker Machine, so you do not need to create the Vagrant box.

## License

MIT - see the [LICENSE](./LICENSE) file for details.
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Vagrant.configure(2) do |config|
config.vm.box = "boxcutter/ubuntu1404"

config.vm.network "forwarded_port", guest: 2376, host: 2376
config.vm.network "forwarded_port", guest: 2376, host: 2376, auto_correct: true
config.vm.synced_folder ".", "#{`pwd`.chomp}"

config.vm.provider "vmware_fusion" do |v|
Expand Down
26 changes: 16 additions & 10 deletions builder/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,29 @@ fi

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

# device specific settings
IMAGE_NAME="sd-card-odroid-c1.img"
IMAGE_ROOTFS_PATH="/image-rootfs.tar.gz"
QEMU_ARCH="arm"

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

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

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

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

# specific versions of kernel/firmware and docker tools
export DOCKER_ENGINE_VERSION="1.9.1-1"
export DOCKER_COMPOSE_VERSION="1.5.2-80"
export DOCKER_MACHINE_VERSION="0.4.1-72"

# create build directory for assembling our image filesystem
rm -rf $BUILD_PATH
mkdir -p $BUILD_PATH
Expand Down Expand Up @@ -103,13 +109,13 @@ copy-file-to-device /boot/u-boot.bin /dev/sda destoffset:32768 sparse:true
EOF

# log image partioning
fdisk -l /$IMAGE_NAME
fdisk -l "/$IMAGE_NAME"

# ensure that the travis-ci user can access the sd-card image file
umask 0000

# compress image
pigz --zip -c $IMAGE_NAME > $BUILD_RESULT_PATH/$IMAGE_NAME.zip
pigz --zip -c "$IMAGE_NAME" > "$BUILD_RESULT_PATH/$IMAGE_NAME.zip"

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

# install Hypriot packages for using Docker
apt-get install -y \
docker-hypriot \
docker-compose \
docker-machine
"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
Expand All @@ -35,8 +35,8 @@ 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
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
Expand Down
15 changes: 9 additions & 6 deletions builder/files/etc/firstboot.d/10-resize-rootdisk
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/bin/bash
set -ex

# sd card device name for ODROID C1/C1+
SDCARD_DEVICE="/dev/mmcblk0"

# install parted, if its not there
if [ -z $(which parted) ]; then
if [ -z "$(which parted)" ]; then
apt-get update
apt-get install -y parted
fi
Expand All @@ -12,15 +15,15 @@ df -h

# get partition number
PART_NUM=$(parted $SDCARD_DEVICE -ms unit s p | tail -n 1 | cut -f 1 -d:)
echo $PART_NUM
echo "$PART_NUM"

# get partition start sector
PART_START=$(parted $SDCARD_DEVICE -ms unit s p | grep ^$PART_NUM | cut -f 2 -d:)
echo $PART_START
PART_START=$(parted $SDCARD_DEVICE -ms unit s p | grep "^$PART_NUM" | cut -f 2 -d:)
echo "$PART_START"

# remove trailing "s"
PART_START=${PART_START::-1}
echo $PART_START
echo "$PART_START"

# change partition table for resizing to maximum
set +e
Expand All @@ -40,7 +43,7 @@ set -e

# apply online resizing
partprobe
/sbin/resize2fs ${SDCARD_DEVICE}p${PART_NUM}
/sbin/resize2fs "${SDCARD_DEVICE}p${PART_NUM}"

# show disk usage after changes
df -h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
describe file('/etc/os-release') do
it { should be_file }
it { should be_owned_by 'root' }
its(:content) { should match 'HYPRIOT_OS=' }
its(:content) { should match 'HYPRIOT_TAG=' }
its(:content) { should match 'HYPRIOT_DEVICE=' }

its(:content) { should match 'HypriotOS/armhf' }
its(:content) { should match 'ODROID C1/C1+' }
its(:content) { should match 'HYPRIOT_OS="HypriotOS/armhf"' }
its(:content) { should match 'HYPRIOT_TAG="v0.7.0"' }
its(:content) { should match 'HYPRIOT_DEVICE="ODROID C1/C1+"' }
end
9 changes: 2 additions & 7 deletions builder/test/image_spec.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
require 'serverspec'
set :backend, :exec
require_relative 'spec_helper'

describe "SD-Card Image" do
let(:image_path) { return '/sd-card-odroid-c1.img' }

it "exists" do
image_file = file(image_path)

expect(image_file).to exist
end

context "Partition table" do
let(:stdout) { command("guestfish add #{image_path} : run : list-filesystems").stdout }
let(:stdout) { run("list-filesystems").stdout }

it "has one partition" do
partitions = stdout.split(/\r?\n/)

expect(partitions.size).to be 1
end

Expand Down
4 changes: 1 addition & 3 deletions builder/test/os-release_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
require 'serverspec'
set :backend, :exec
require_relative 'spec_helper'

describe "Root filesystem" do
let(:rootfs_path) { return '/build' }

it "exists" do
rootfs_dir = file(rootfs_path)

expect(rootfs_dir).to exist
end

Expand Down
14 changes: 14 additions & 0 deletions builder/test/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'serverspec'
set :backend, :exec

def image_path
return "sd-card-odroid-c1-#{ENV['VERSION']}.img"
end

def run( cmd )
return command("guestfish add #{image_path} : run : #{cmd}")
end

def run_mounted( cmd )
return run("mount /dev/sda2 / : #{cmd}")
end

0 comments on commit 97e93df

Please sign in to comment.