From 3dd76893649f7a44294e3af4ce3949f229f74d2a Mon Sep 17 00:00:00 2001 From: Tomas Kral Date: Tue, 9 Aug 2016 13:35:48 +0200 Subject: [PATCH 1/7] Move binary target to binary-cross use binary target only for building for current platform --- Makefile | 6 ++++++ script/binary | 24 +++++------------------- script/binary-cross | 26 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 script/binary-cross diff --git a/Makefile b/Makefile index c78611d1e..7db776ab2 100644 --- a/Makefile +++ b/Makefile @@ -16,3 +16,9 @@ all: binary: CGO_ENABLED=0 ./script/make.sh binary + +binary-cross: + CGO_ENABLED=0 ./script/make.sh binary-cross + +clean: + ./script/make.sh clean diff --git a/script/binary b/script/binary index 9fabf1af7..74f31cefd 100755 --- a/script/binary +++ b/script/binary @@ -1,26 +1,12 @@ #!/bin/bash set -e -if [ -z "$1" ]; then - OS_PLATFORM_ARG=(-os="darwin linux windows") -else - OS_PLATFORM_ARG=($1) -fi +# Get rid of existing binary +rm -f kompose -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 binary +go build \ -tags experimental \ + -o kompose \ -ldflags="-w -X github.com/skippbox/kompose/version.GITCOMMIT=${GITCOMMIT}" \ ./cli/main diff --git a/script/binary-cross b/script/binary-cross new file mode 100644 index 000000000..9fabf1af7 --- /dev/null +++ b/script/binary-cross @@ -0,0 +1,26 @@ +#!/bin/bash +set -e + +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" \ + -tags experimental \ + -ldflags="-w -X github.com/skippbox/kompose/version.GITCOMMIT=${GITCOMMIT}" \ + ./cli/main From 609942836459f866aafa8c936a575ce5d96726d9 Mon Sep 17 00:00:00 2001 From: Tomas Kral Date: Tue, 9 Aug 2016 13:48:30 +0200 Subject: [PATCH 2/7] add test targets to Makefile --- Makefile | 6 ++++++ script/test-cmd | 3 +++ script/test-unit | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100755 script/test-cmd create mode 100755 script/test-unit diff --git a/Makefile b/Makefile index 7db776ab2..2f431c5e0 100644 --- a/Makefile +++ b/Makefile @@ -22,3 +22,9 @@ binary-cross: clean: ./script/make.sh clean + +test-unit: + ./script/make.sh test-unit + +test-cmd: + ./script/make.sh test-cmd diff --git a/script/test-cmd b/script/test-cmd new file mode 100755 index 000000000..a04691ef8 --- /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 000000000..8189ce309 --- /dev/null +++ b/script/test-unit @@ -0,0 +1,25 @@ +#!/bin/bash +set -e + +find_dirs() { + ( + find . -not \( \ + \( \ + -path './vendor/*' \ + \) -prune \ + \) -name '*_test.go' -print0 | xargs -0n1 dirname | sed 's|^\./||' | sort -u + ) +} + +TEST_FLAGS="-tags experimental -cover -coverprofile=cover.out" + +if [ -z "$TEST_DIRS" ]; then + TEST_DIRS=$(find_dirs '*_test.go') +fi + +TESTS_FAILED=() + +set +e +for dir in $TEST_DIRS; do + go test ${TEST_FLAGS} "./${dir}" +done From 575d7e41622c528c1b4c51d445ed0b1a87e682e1 Mon Sep 17 00:00:00 2001 From: Tomas Kral Date: Tue, 9 Aug 2016 13:48:52 +0200 Subject: [PATCH 3/7] update travis.yml to run tests and build only for current platform --- .travis.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2da35eea1..7fd94da10 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 $GOPATH/bin + - cp kompose $GOPATH/bin/ + + - make test-unit + - make test-cmd From a15a8f36ca36d596d93bcac0fef5b90f5e15622b Mon Sep 17 00:00:00 2001 From: Tomas Kral Date: Wed, 10 Aug 2016 11:19:04 +0200 Subject: [PATCH 4/7] Fix Makefile. Print info when building binary. --- script/binary | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/script/binary b/script/binary index 74f31cefd..017b8915b 100755 --- a/script/binary +++ b/script/binary @@ -10,3 +10,9 @@ go build \ -o kompose \ -ldflags="-w -X github.com/skippbox/kompose/version.GITCOMMIT=${GITCOMMIT}" \ ./cli/main + +if [ $? -eq 0 ]; then + echo "Build successful. Program saved as ${OUT_FILE}" +else + echo "Build failed." +fi From e64f1c1215177c4880947c381fb14a2f298dbbc8 Mon Sep 17 00:00:00 2001 From: Tomas Kral Date: Wed, 10 Aug 2016 11:23:09 +0200 Subject: [PATCH 5/7] Add script/.build to keep BUILD_FLAGS in one place --- script/.build | 5 +++++ script/binary | 11 +++++++---- script/binary-cross | 5 +++-- script/test-unit | 7 ++++--- 4 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 script/.build diff --git a/script/.build b/script/.build new file mode 100644 index 000000000..bd647b6b2 --- /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 017b8915b..ee1c21a36 100755 --- a/script/binary +++ b/script/binary @@ -1,14 +1,17 @@ #!/bin/bash set -e +source "$(dirname "$BASH_SOURCE")/.build" + +OUT_FILE="./kompose" + # Get rid of existing binary -rm -f kompose +rm -f $OUT_FILE # Build binary go build \ - -tags experimental \ - -o kompose \ - -ldflags="-w -X github.com/skippbox/kompose/version.GITCOMMIT=${GITCOMMIT}" \ + "${BUILD_FLAGS[@]}" \ + -o $OUT_FILE \ ./cli/main if [ $? -eq 0 ]; then diff --git a/script/binary-cross b/script/binary-cross index 9fabf1af7..ee3d11ae6 100644 --- a/script/binary-cross +++ b/script/binary-cross @@ -1,6 +1,8 @@ #!/bin/bash set -e +source "$(dirname "$BASH_SOURCE")/.build" + if [ -z "$1" ]; then OS_PLATFORM_ARG=(-os="darwin linux windows") else @@ -21,6 +23,5 @@ 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_FLAGS[@]}" \ ./cli/main diff --git a/script/test-unit b/script/test-unit index 8189ce309..3b4269efc 100755 --- a/script/test-unit +++ b/script/test-unit @@ -1,6 +1,8 @@ #!/bin/bash set -e +source "$(dirname "$BASH_SOURCE")/.build" + find_dirs() { ( find . -not \( \ @@ -11,7 +13,7 @@ find_dirs() { ) } -TEST_FLAGS="-tags experimental -cover -coverprofile=cover.out" +TEST_FLAGS=("${BUILD_FLAGS[@]}" -cover -coverprofile=cover.out) if [ -z "$TEST_DIRS" ]; then TEST_DIRS=$(find_dirs '*_test.go') @@ -19,7 +21,6 @@ fi TESTS_FAILED=() -set +e for dir in $TEST_DIRS; do - go test ${TEST_FLAGS} "./${dir}" + go test "${TEST_FLAGS[@]}" "./${dir}" done From bae3feb10c38e09be818fd13f1bfb6e00c162bfd Mon Sep 17 00:00:00 2001 From: Tomas Kral Date: Wed, 10 Aug 2016 11:29:12 +0200 Subject: [PATCH 6/7] Update README. Renaming `binary` to `binary-cross` --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1511af559..cddc6a74b 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 From ef1f92ead830ee4c1addd9235b01b50b987650c0 Mon Sep 17 00:00:00 2001 From: Tomas Kral Date: Wed, 10 Aug 2016 12:23:54 +0200 Subject: [PATCH 7/7] fix .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7fd94da10..342f0b932 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ install: script: - make binary # $GOPATH/bin is in $PATH - - mkdir $GOPATH/bin + - mkdir -p $GOPATH/bin - cp kompose $GOPATH/bin/ - make test-unit