Makefile 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. .PHONY: all all-local build build-local clean cross cross-local check check-code check-format run-tests integration-tests check-local coveralls circle-ci-cross circle-ci-build circle-ci-check circle-ci
  2. SHELL=/bin/bash
  3. build_image=libnetworkbuild
  4. dockerargs = --privileged -v $(shell pwd):/go/src/github.com/docker/libnetwork -w /go/src/github.com/docker/libnetwork
  5. container_env = -e "INSIDECONTAINER=-incontainer=true"
  6. docker = docker run --rm -it ${dockerargs} $$EXTRA_ARGS ${container_env} ${build_image}
  7. ciargs = -e CIRCLECI -e "COVERALLS_TOKEN=$$COVERALLS_TOKEN" -e "INSIDECONTAINER=-incontainer=true"
  8. cidocker = docker run ${dockerargs} ${ciargs} ${container_env} ${build_image}
  9. CROSS_PLATFORMS = linux/amd64 linux/386 linux/arm windows/amd64 windows/386
  10. all: ${build_image}.created build check integration-tests clean
  11. all-local: build-local check-local integration-tests-local clean
  12. ${build_image}.created:
  13. docker build -f Dockerfile.build -t ${build_image} .
  14. touch ${build_image}.created
  15. build: ${build_image}.created
  16. @echo "Building code... "
  17. @${docker} ./wrapmake.sh build-local
  18. @echo "Done building code"
  19. build-local:
  20. @mkdir -p "bin"
  21. $(shell which godep) go build -o "bin/dnet" ./cmd/dnet
  22. clean:
  23. @if [ -d bin ]; then \
  24. echo "Removing dnet binaries"; \
  25. rm -rf bin; \
  26. fi
  27. cross: ${build_image}.created
  28. @mkdir -p "bin"
  29. @for platform in ${CROSS_PLATFORMS}; do \
  30. EXTRA_ARGS="-e GOOS=$${platform%/*} -e GOARCH=$${platform##*/}" ; \
  31. echo "$${platform}..." ; \
  32. ${docker} make cross-local ; \
  33. done
  34. cross-local:
  35. $(shell which godep) go build -o "bin/dnet-$$GOOS-$$GOARCH" ./cmd/dnet
  36. check: ${build_image}.created
  37. @${docker} ./wrapmake.sh check-local
  38. check-code:
  39. @echo "Checking code... "
  40. test -z "$$(golint ./... | tee /dev/stderr)"
  41. go vet ./...
  42. @echo "Done checking code"
  43. check-format:
  44. @echo "Checking format... "
  45. test -z "$$(goimports -l . | grep -v Godeps/_workspace/src/ | tee /dev/stderr)"
  46. @echo "Done checking format"
  47. run-tests:
  48. @echo "Running tests... "
  49. @echo "mode: count" > coverage.coverprofile
  50. @for dir in $$(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -type d); do \
  51. if ls $$dir/*.go &> /dev/null; then \
  52. pushd . &> /dev/null ; \
  53. cd $$dir ; \
  54. $(shell which godep) go test ${INSIDECONTAINER} -test.parallel 3 -test.v -covermode=count -coverprofile=./profile.tmp ; \
  55. ret=$$? ;\
  56. if [ $$ret -ne 0 ]; then exit $$ret; fi ;\
  57. popd &> /dev/null; \
  58. if [ -f $$dir/profile.tmp ]; then \
  59. cat $$dir/profile.tmp | tail -n +2 >> coverage.coverprofile ; \
  60. rm $$dir/profile.tmp ; \
  61. fi ; \
  62. fi ; \
  63. done
  64. @echo "Done running tests"
  65. check-local: check-format check-code run-tests
  66. integration-tests: ./bin/dnet
  67. @./test/integration/dnet/run-integration-tests.sh
  68. ./bin/dnet:
  69. make build
  70. coveralls:
  71. -@goveralls -service circleci -coverprofile=coverage.coverprofile -repotoken $$COVERALLS_TOKEN
  72. # CircleCI's Docker fails when cleaning up using the --rm flag
  73. # The following targets are a workaround for this
  74. circle-ci-cross: ${build_image}.created
  75. @mkdir -p "bin"
  76. @for platform in ${CROSS_PLATFORMS}; do \
  77. EXTRA_ARGS="-e GOOS=$${platform%/*} -e GOARCH=$${platform##*/}" ; \
  78. echo "$${platform}..." ; \
  79. ${cidocker} make cross-local ; \
  80. done
  81. circle-ci-check: ${build_image}.created
  82. @${cidocker} make check-local coveralls
  83. circle-ci-build: ${build_image}.created
  84. @${cidocker} make build-local
  85. circle-ci: circle-ci-check circle-ci-build integration-tests