From c2b6a42855818df22ec8364dafa3a0f7c5baf4b9 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Sun, 24 Jan 2016 11:52:16 +0100 Subject: [PATCH] validate scripts in container Signed-off-by: Antonio Murdaca --- .travis.yml | 8 +-- Makefile | 5 +- hack/make.sh | 100 +++++++++++++++++++++++++++++ hack/{ => make}/.validate | 0 hack/make/test-integration | 15 +++++ hack/{ => make}/validate-git-marks | 0 hack/{ => make}/validate-gofmt | 0 hack/{ => make}/validate-lint | 0 hack/{ => make}/validate-vet | 0 integration/test.sh | 18 ------ 10 files changed, 123 insertions(+), 23 deletions(-) create mode 100755 hack/make.sh rename hack/{ => make}/.validate (100%) create mode 100755 hack/make/test-integration rename hack/{ => make}/validate-git-marks (100%) rename hack/{ => make}/validate-gofmt (100%) rename hack/{ => make}/validate-lint (100%) rename hack/{ => make}/validate-vet (100%) delete mode 100755 integration/test.sh diff --git a/.travis.yml b/.travis.yml index dc3d23f5..f4a224d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,9 +12,9 @@ install: - go get github.com/golang/lint/golint script: - - hack/validate-vet - - hack/validate-lint - - hack/validate-gofmt - - hack/validate-git-marks + - hack/make/validate-vet + - hack/make/validate-lint + - hack/make/validate-gofmt + - hack/make/validate-git-marks - go build -o skopeo . - go test -v . diff --git a/Makefile b/Makefile index be53d8ff..3aaa4e0f 100644 --- a/Makefile +++ b/Makefile @@ -44,4 +44,7 @@ shell: build-container $(DOCKER_RUN_DOCKER) bash test-integration: build-container - $(DOCKER_RUN_DOCKER) integration/test.sh + $(DOCKER_RUN_DOCKER) hack/make.sh test-integration + +validate: build-container + $(DOCKER_RUN_DOCKER) hack/make.sh validate-git-marks validate-gofmt validate-lint validate-vet diff --git a/hack/make.sh b/hack/make.sh new file mode 100755 index 00000000..a81f1cd7 --- /dev/null +++ b/hack/make.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env bash +set -e + +# This script builds various binary from a checkout of the skopeo +# source code. +# +# Requirements: +# - The current directory should be a checkout of the skopeo source code +# (https://github.com/runcom/skopeo). Whatever version is checked out +# will be built. +# - The script is intended to be run inside the docker container specified +# in the Dockerfile at the root of the source. In other words: +# DO NOT CALL THIS SCRIPT DIRECTLY. +# - The right way to call this script is to invoke "make" from +# your checkout of the skopeo repository. +# the Makefile will do a "docker build -t skopeo ." and then +# "docker run hack/make.sh" in the resulting image. +# + +set -o pipefail + +export SKOPEO_PKG='github.com/runcom/skopeo' +export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +export MAKEDIR="$SCRIPTDIR/make" + +# We're a nice, sexy, little shell script, and people might try to run us; +# but really, they shouldn't. We want to be in a container! +inContainer="AssumeSoInitially" +if [ "$PWD" != "/go/src/$SKOPEO_PKG" ]; then + unset inContainer +fi + +if [ -z "$inContainer" ]; then + { + echo "# WARNING! I don't seem to be running in a Docker container." + echo "# The result of this command might be an incorrect build, and will not be" + echo "# officially supported." + echo "#" + echo "# Try this instead: make all" + echo "#" + } >&2 +fi + +echo + +# List of bundles to create when no argument is passed +# TODO(runcom): these are the one left from Docker...for now +# test-unit +# validate-dco +# cover +DEFAULT_BUNDLES=( + validate-gofmt + validate-lint + validate-vet + validate-git-marks + + test-integration +) + +TESTFLAGS+=" -test.timeout=10m" + +# If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'. +# You can use this to select certain tests to run, eg. +# +# TESTFLAGS='-test.run ^TestBuild$' ./hack/make.sh test-unit +# +# For integration-cli test, we use [gocheck](https://labix.org/gocheck), if you want +# to run certain tests on your local host, you should run with command: +# +# TESTFLAGS='-check.f DockerSuite.TestBuild*' ./hack/make.sh binary test-integration-cli +# +go_test_dir() { + dir=$1 + ( + echo '+ go test' $TESTFLAGS "${SKOPEO_PKG}${dir#.}" + cd "$dir" + export DEST="$ABS_DEST" # we're in a subshell, so this is safe -- our integration-cli tests need DEST, and "cd" screws it up + go test $TESTFLAGS + ) +} + +bundle() { + local bundle="$1"; shift + echo "---> Making bundle: $(basename "$bundle")" + source "$SCRIPTDIR/make/$bundle" "$@" +} + +main() { + if [ $# -lt 1 ]; then + bundles=(${DEFAULT_BUNDLES[@]}) + else + bundles=($@) + fi + for bundle in ${bundles[@]}; do + bundle "$bundle" + echo + done +} + +main "$@" diff --git a/hack/.validate b/hack/make/.validate similarity index 100% rename from hack/.validate rename to hack/make/.validate diff --git a/hack/make/test-integration b/hack/make/test-integration new file mode 100755 index 00000000..cb3b6c71 --- /dev/null +++ b/hack/make/test-integration @@ -0,0 +1,15 @@ +#!/bin/bash +set -e + +bundle_test_integration() { + TESTFLAGS="$TESTFLAGS -check.v" + go_test_dir ./integration +} + +# subshell so that we can export PATH without breaking other things +( + make binary + make install-binary + export GO15VENDOREXPERIMENT=1 + bundle_test_integration +) 2>&1 diff --git a/hack/validate-git-marks b/hack/make/validate-git-marks similarity index 100% rename from hack/validate-git-marks rename to hack/make/validate-git-marks diff --git a/hack/validate-gofmt b/hack/make/validate-gofmt similarity index 100% rename from hack/validate-gofmt rename to hack/make/validate-gofmt diff --git a/hack/validate-lint b/hack/make/validate-lint similarity index 100% rename from hack/validate-lint rename to hack/make/validate-lint diff --git a/hack/validate-vet b/hack/make/validate-vet similarity index 100% rename from hack/validate-vet rename to hack/make/validate-vet diff --git a/integration/test.sh b/integration/test.sh deleted file mode 100755 index a60a88b1..00000000 --- a/integration/test.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -# TODO(runcom): we need docker somehow in container to push/pull to registries -#command -v docker >/dev/null 2>&1 || { echo >&2 "Docker is required but it's not installed. Aborting."; exit 1; } - -# TODO(runcom): this can be done also with ensure-frozen-images - see docker/docker -#docker pull busybox:latest >/dev/null 2>&1 || { echo >&2 "docker pull busybox:latest failed. Aborting." exit 1; } - -make binary -make install-binary -export GO15VENDOREXPERIMENT=1 - -echo "" -echo "" -echo "Testing..." -echo "" - -cd integration/ && go test -test.timeout=10m -check.v