From 3dbbcae98d6d5ebd57fd6871c1aaf9660606baae Mon Sep 17 00:00:00 2001 From: David Gageot Date: Thu, 5 Jan 2017 09:51:33 +0100 Subject: [PATCH 1/2] Simplify Dockerfiles for build and run Signed-off-by: David Gageot --- dockerfiles/Dockerfile.build | 20 +++----------------- dockerfiles/Dockerfile.bundle | 9 ++------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/dockerfiles/Dockerfile.build b/dockerfiles/Dockerfile.build index 6a04c69c0..bad2b601c 100644 --- a/dockerfiles/Dockerfile.build +++ b/dockerfiles/Dockerfile.build @@ -1,25 +1,11 @@ FROM golang:1.7.4-alpine -# A container for building InfraKit - RUN apk add --update git make +RUN go get github.com/rancher/trash -ENV CGO_ENABLED=0 -ENV GOPATH=/go -ENV PATH=/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin - -# Development tools -RUN go get github.com/rancher/trash \ - github.com/golang/lint/golint \ - github.com/golang/mock/gomock \ - github.com/golang/mock/mockgen - -# The project sources -ADD ./ /go/src/github.com/docker/infrakit WORKDIR /go/src/github.com/docker/infrakit - VOLUME [ "/go/src/github.com/docker/infrakit/build" ] +CMD make build-binaries +COPY . ./ RUN trash # Force updating the vendored sources per spec; this slows the build but is most correct. - -CMD make build-binaries diff --git a/dockerfiles/Dockerfile.bundle b/dockerfiles/Dockerfile.bundle index 8a03a789c..95b3b2bbe 100644 --- a/dockerfiles/Dockerfile.bundle +++ b/dockerfiles/Dockerfile.bundle @@ -1,10 +1,5 @@ -FROM alpine:3.4 +FROM alpine:3.5 -# InfraKit bundle: a simple container for all of the default InfraKit executables - -MAINTAINER David Chung - -RUN apk add --update ca-certificates && rm -Rf /tmp/* /var/lib/cache/apk/* -RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 +RUN apk add --update ca-certificates ADD build/* /usr/local/bin/ From f7f265056e71d393d30b603bdb687d1e2ae0a6a6 Mon Sep 17 00:00:00 2001 From: David Chung Date: Thu, 5 Jan 2017 15:51:32 -0800 Subject: [PATCH 2/2] integration test to verify container images and binaries Signed-off-by: David Chung --- Makefile | 2 + scripts/container-test | 119 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100755 scripts/container-test diff --git a/Makefile b/Makefile index 51a5071c6..cfac3c9b8 100644 --- a/Makefile +++ b/Makefile @@ -50,6 +50,8 @@ build-docker: @docker build ${DOCKER_BUILD_FLAGS} \ -t ${DOCKER_IMAGE}:${DOCKER_TAG} \ -f ${CURDIR}/dockerfiles/Dockerfile.bundle . + @echo "Running tests -- scripts/container-test to verify the binaries" + @scripts/container-test ifeq (${DOCKER_PUSH},true) @docker push ${DOCKER_IMAGE}:${DOCKER_TAG} ifeq (${DOCKER_TAG_LATEST},true) diff --git a/scripts/container-test b/scripts/container-test new file mode 100755 index 000000000..b614b135b --- /dev/null +++ b/scripts/container-test @@ -0,0 +1,119 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset + +HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd "$HERE/.." + + +TEST_DIR=$(pwd)/container-test +DOCKER_IMAGE="${DOCKER_IMAGE:-infrakit/devbundle}" +DOCKER_TAG="${DOCKER_TAG:-dev}" + +cleanup() { + docker ps | grep devbundle | awk '{print $1}' | xargs docker stop + rm -rf $TEST_DIR +} +trap cleanup EXIT + +mkdir -p $TEST_DIR/plugins +mkdir -p $TEST_DIR/tutorial + +volumes="-v $TEST_DIR:/root -v $PWD/docs:/root/docs" + +# set the environment variable to use a shorter path so we don't have +# problems with Docker for Mac. See https://github.com/docker/docker/issues/23545 +envs="-e INFRAKIT_PLUGINS_DIR=/root" + +server() { + docker run -d --rm --name $1 $envs $volumes $DOCKER_IMAGE:$DOCKER_TAG $@ +} + +run() { + docker run --rm $envs $volumes $DOCKER_IMAGE:$DOCKER_TAG $@ +} + +server infrakit-instance-file --dir /root/tutorial/ +server infrakit-group-default --poll-interval 500ms +server infrakit-flavor-vanilla + +sleep 1 + +expect_exact_output() { + message=$1 + cmd=$2 + expected_output=$3 + + actual_output="$($2)" + echo -n "--> $message: " + if [ "$actual_output" = "$3" ] + then + echo 'PASS' + else + echo 'FAIL' + echo "Expected output: $expected_output" + echo "Actual output: $actual_output" + exit 1 + fi +} + +expect_output_lines() { + message=$1 + cmd=$2 + expected_lines=$3 + + actual_line_count=$($2 | wc -l) + echo -n "--> $message: " + if [ "$actual_line_count" -eq "$3" ] + then + echo 'PASS' + else + echo 'FAIL' + echo "Expected line count: $expected_lines" + echo "Actual line count: $actual_line_count" + exit 1 + fi +} + +expect_output_lines "3 plugins should be discoverable" "run infrakit plugin ls -q" "3" + +expect_output_lines "0 instances should exist" "run infrakit instance describe -q --name instance-file" "0" + +run infrakit group commit /root/docs/cattle.json + +echo 'Waiting for group to be provisioned' +sleep 2 + +expect_output_lines "5 instances should exist in group" "run infrakit group describe cattle -q" "5" +expect_output_lines "5 instances should exist" "run infrakit instance describe -q --name instance-file" "5" + +run infrakit group free cattle +run infrakit group commit /root/docs/cattle.json + +expect_exact_output "Should be watching one group" "run infrakit group ls -q" "cattle" + +expect_exact_output \ + "Update should roll 5 and scale group to 10" \ + "run infrakit group commit /root/docs/cattle2.json --pretend" \ + "Committing cattle would involve: Performing a rolling update on 5 instances, then adding 5 instances to increase the group size to 10" + +run infrakit group commit /root/docs/cattle2.json + +sleep 5 + +expect_output_lines "10 instances should exist in group" "run infrakit group describe cattle -q" "10" + +# Terminate 3 instances. +pushd $TEST_DIR/tutorial + rm $(ls | head -3) +popd + +sleep 5 + +expect_output_lines "10 instances should exist in group" "run infrakit group describe cattle -q" "10" + +run infrakit group destroy cattle +expect_output_lines "0 instances should exist" "run infrakit instance describe -q --name instance-file" "0" + +echo 'ALL TESTS PASSED'