diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5d5d7f8f72..49a323ba21 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,6 +42,15 @@ run: If you have any questions we're in #docker-machine on Freenode. +## Remote Build + +You can use Machine to build Machine: + + $ GOOS=darwin GOARCH=amd64 make remote + +The difference is this works even if you don't have local docker daemon, but +instead a docker host that you [set up using Machine](https://github.com/docker/machine). + ## Unit Tests To run the unit tests for the whole project, using the following script: diff --git a/Makefile b/Makefile index 19e84e74df..4f4d249c8f 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,8 @@ default: build +remote: build-remote + test: script/test @@ -16,6 +18,9 @@ validate: validate-dco validate-gofmt test build: clean script/build +build-remote: clean + script/build-remote + clean: rm -f docker-machine_* rm -rf Godeps/_workspace/pkg diff --git a/script/build-remote b/script/build-remote new file mode 100755 index 0000000000..c1da55b5dd --- /dev/null +++ b/script/build-remote @@ -0,0 +1,38 @@ +#!/bin/bash +set -e + +BUILD_IMAGE_NAME="docker-machine-build" +GOOS=${GOOS:-"darwin linux windows"} +GOARCH=${GOARCH:-"386 amd64 arm"} + +docker build -t ${BUILD_IMAGE_NAME} . + +BUILD_CONTAINER=$(docker run -d \ + ${BUILD_IMAGE_NAME} \ + gox \ + -os "$GOOS" \ + -arch "$GOARCH" \ + -output="docker-machine_{{.OS}}-{{.Arch}}" \ + -ldflags="-w -X github.com/docker/machine/version.GitCommit `git rev-parse --short HEAD`") +cleanup_container() { + docker rm -v ${BUILD_CONTAINER} +} +trap cleanup_container EXIT + +docker logs -f ${BUILD_CONTAINER} & +BUILD_STATUS=$(docker wait ${BUILD_CONTAINER}) +if [[ ${BUILD_STATUS} != 0 ]]; then exit ${BUILD_STATUS}; fi + +BUILT_IMAGE=$(docker commit ${BUILD_CONTAINER}) +cleanup_image() { + cleanup_container + docker rmi ${BUILT_IMAGE} +} +trap cleanup_image EXIT + +echo "Copying built binaries:" +for f in $(docker run --rm ${BUILT_IMAGE} sh -c 'echo docker-machine_*'); do + echo " "${f} + docker cp ${BUILD_CONTAINER}:/go/src/github.com/docker/machine/${f} ./ +done +echo Done