diff --git a/.travis.yml b/.travis.yml index 2da35eea..342f0b93 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,21 @@ +# we need trusty because test-cmd depends on jq version >= 1.5 +dist : trusty sudo: required + language: go go: - 1.6 -branches: - only: - - master - install: -- go get github.com/mitchellh/gox -- go get github.com/tools/godep -- ./script/godep-restore.sh + - true script: -- make binary + - make binary + # $GOPATH/bin is in $PATH + - mkdir -p $GOPATH/bin + - cp kompose $GOPATH/bin/ + + - make test-unit + - make test-cmd diff --git a/Makefile b/Makefile index c78611d1..2f431c5e 100644 --- a/Makefile +++ b/Makefile @@ -16,3 +16,15 @@ all: binary: CGO_ENABLED=0 ./script/make.sh binary + +binary-cross: + CGO_ENABLED=0 ./script/make.sh binary-cross + +clean: + ./script/make.sh clean + +test-unit: + ./script/make.sh test-unit + +test-cmd: + ./script/make.sh test-cmd diff --git a/README.md b/README.md index 1511af55..cddc6a74 100755 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ file "redis-deployment.json" created The default `kompose` transformation will generate Kubernetes [Deployments](http://kubernetes.io/docs/user-guide/deployments/) and [Services](http://kubernetes.io/docs/user-guide/services/), in json format. You have alternative option to generate yaml with `-y`. Also, you can alternatively generate [Replication Controllers](http://kubernetes.io/docs/user-guide/replication-controller/) objects, [Deamon Sets](http://kubernetes.io/docs/admin/daemons/), or [Helm](https://github.com/helm/helm) charts. ```console -$ kompose convert +$ kompose convert file "redis-svc.json" created file "web-svc.json" created file "redis-deployment.json" created @@ -180,7 +180,7 @@ You need `-tags experimental` because the current `bundlefile` package of docker - You need `make` ```console -$ make binary +$ make binary-cross ``` ## Contributing and Issues diff --git a/script/.build b/script/.build new file mode 100644 index 00000000..bd647b6b --- /dev/null +++ b/script/.build @@ -0,0 +1,5 @@ +#!/bin/bash + +GITCOMMIT=$(git rev-parse --short HEAD) + +BUILD_FLAGS=(-tags experimental -ldflags="-w -X github.com/skippbox/kompose/version.GITCOMMIT=${GITCOMMIT}") diff --git a/script/binary b/script/binary index 9fabf1af..ee1c21a3 100755 --- a/script/binary +++ b/script/binary @@ -1,26 +1,21 @@ #!/bin/bash set -e -if [ -z "$1" ]; then - OS_PLATFORM_ARG=(-os="darwin linux windows") -else - OS_PLATFORM_ARG=($1) -fi +source "$(dirname "$BASH_SOURCE")/.build" -if [ -z "$2" ]; then - OS_ARCH_ARG=(-arch="386 amd64") -else - OS_ARCH_ARG=($2) -fi +OUT_FILE="./kompose" -GITCOMMIT=$(git rev-parse --short HEAD) +# Get rid of existing binary +rm -f $OUT_FILE -# Get rid of existing binaries -rm -f kompose* - -# Build binaries -gox "${OS_PLATFORM_ARG[@]}" "${OS_ARCH_ARG[@]}" \ - -output="bundles/kompose_{{.OS}}-{{.Arch}}/kompose" \ - -tags experimental \ - -ldflags="-w -X github.com/skippbox/kompose/version.GITCOMMIT=${GITCOMMIT}" \ +# Build binary +go build \ + "${BUILD_FLAGS[@]}" \ + -o $OUT_FILE \ ./cli/main + +if [ $? -eq 0 ]; then + echo "Build successful. Program saved as ${OUT_FILE}" +else + echo "Build failed." +fi diff --git a/script/binary-cross b/script/binary-cross new file mode 100644 index 00000000..ee3d11ae --- /dev/null +++ b/script/binary-cross @@ -0,0 +1,27 @@ +#!/bin/bash +set -e + +source "$(dirname "$BASH_SOURCE")/.build" + +if [ -z "$1" ]; then + OS_PLATFORM_ARG=(-os="darwin linux windows") +else + OS_PLATFORM_ARG=($1) +fi + +if [ -z "$2" ]; then + OS_ARCH_ARG=(-arch="386 amd64") +else + OS_ARCH_ARG=($2) +fi + +GITCOMMIT=$(git rev-parse --short HEAD) + +# Get rid of existing binaries +rm -f kompose* + +# Build binaries +gox "${OS_PLATFORM_ARG[@]}" "${OS_ARCH_ARG[@]}" \ + -output="bundles/kompose_{{.OS}}-{{.Arch}}/kompose" \ + "${BUILD_FLAGS[@]}" \ + ./cli/main diff --git a/script/test-cmd b/script/test-cmd new file mode 100755 index 00000000..a04691ef --- /dev/null +++ b/script/test-cmd @@ -0,0 +1,3 @@ +#!/bin/bash + +./script/test/cmd/tests.sh diff --git a/script/test-unit b/script/test-unit new file mode 100755 index 00000000..3b4269ef --- /dev/null +++ b/script/test-unit @@ -0,0 +1,26 @@ +#!/bin/bash +set -e + +source "$(dirname "$BASH_SOURCE")/.build" + +find_dirs() { + ( + find . -not \( \ + \( \ + -path './vendor/*' \ + \) -prune \ + \) -name '*_test.go' -print0 | xargs -0n1 dirname | sed 's|^\./||' | sort -u + ) +} + +TEST_FLAGS=("${BUILD_FLAGS[@]}" -cover -coverprofile=cover.out) + +if [ -z "$TEST_DIRS" ]; then + TEST_DIRS=$(find_dirs '*_test.go') +fi + +TESTS_FAILED=() + +for dir in $TEST_DIRS; do + go test "${TEST_FLAGS[@]}" "./${dir}" +done