Prepare build for plugins PR

Signed-off-by: Olivier Gambier <olivier@docker.com>
This commit is contained in:
Olivier Gambier 2015-10-07 13:38:55 -07:00
parent 870d5c9340
commit 56160e0058
14 changed files with 81 additions and 110 deletions

View File

@ -18,21 +18,25 @@ guidelines](https://github.com/docker/docker/blob/master/CONTRIBUTING.md).
The requirements to build Machine are: The requirements to build Machine are:
1. A running instance of Docker (or alternatively a golang 1.5 development environment) 1. A running instance of Docker
2. The `bash` shell 2. The `bash` shell
3. [Make](https://www.gnu.org/software/make/) 3. [Make](https://www.gnu.org/software/make/)
Call `export USE_CONTAINER=true` to instruct the build system to use containers to build. Call `export USE_CONTAINER=true` to instruct the build system to use containers to build.
If you want to build natively using golang instead, don't set this variable.
# Alternative: build using go only
Alternatively, you can build without docker, using only golang.
[Install and setup go](https://golang.org/doc/install), then clone the machine repository inside your gopath.
## Building ## Building
To build the docker-machine binary, simply run: To build the docker-machine binary, simply run:
$ make $ make build
From the Machine repository's root. You will now find a `bin/docker-machine` From the Machine repository's root. You will now have a `bin/docker-machine`.
binary at the root of the project.
You may call: You may call:
@ -61,6 +65,8 @@ To generate an html code coverage report of the Machine codebase, run:
And navigate to http://localhost:8000 (hit `CTRL+C` to stop the server). And navigate to http://localhost:8000 (hit `CTRL+C` to stop the server).
### Native build
Alternatively, if you are building natively, you can simply run: Alternatively, if you are building natively, you can simply run:
make coverage-html make coverage-html
@ -80,9 +86,9 @@ This will generate and open the report file:
### Build targets ### Build targets
Build a single, native machine binary: Just build the machine binary itself:
make build-simple make `pwd`/bin/docker-machine
Build for all supported oses and architectures (binaries will be in the `bin` project subfolder): Build for all supported oses and architectures (binaries will be in the `bin` project subfolder):
@ -97,8 +103,7 @@ You can further control build options through the following environment variable
DEBUG=true # enable debug build DEBUG=true # enable debug build
STATIC=true # build static (note: when cross-compiling, the build is always static) STATIC=true # build static (note: when cross-compiling, the build is always static)
VERBOSE=true # verbose output VERBOSE=true # verbose output
PARALLEL=X # lets you control build parallelism when cross-compiling multiple builds PREFIX=folder # put binaries in another folder (not the default `./bin`)
PREFIX=folder
Scrub build results: Scrub build results:
@ -134,16 +139,12 @@ first make sure to [install it](https://github.com/sstephenson/bats#installing-b
### Basic Usage ### Basic Usage
Integration tests can be invoked calling `make test-integration`. You first need to build, calling `make build`.
:warn: you cannot run integration test inside a container for now. You can then invoke integration tests calling `DRIVER=foo make test-integration TESTSUITE`, where `TESTSUITE` is
Be sure to unset the `USE_CONTAINER` env variable if you set it earlier, or alternatively one of the `test/integration` subfolder, and `foo` is the specific driver you want to test.
call directly `./test/integration/run-bats.sh` instead of `make test-integration`.
You can invoke a test or subset of tests for a particular driver. Examples:
To set the driver, use the `DRIVER` environment variable.
To invoke just one test:
```console ```console
$ DRIVER=virtualbox make test-integration test/integration/core/core-commands.bats $ DRIVER=virtualbox make test-integration test/integration/core/core-commands.bats
@ -170,13 +171,6 @@ Cleaning up machines...
Successfully removed bats-virtualbox-test Successfully removed bats-virtualbox-test
``` ```
To invoke a shared test with a different driver:
```console
$ DRIVER=digitalocean make test-integration test/integration/core/core-commands.bats
...
```
To invoke a directory of tests recursively: To invoke a directory of tests recursively:
```console ```console

View File

@ -1,7 +1,6 @@
FROM golang:1.5 FROM golang:1.5
RUN go get github.com/mitchellh/gox \ RUN go get github.com/golang/lint/golint \
github.com/golang/lint/golint \
github.com/mattn/goveralls \ github.com/mattn/goveralls \
golang.org/x/tools/cover \ golang.org/x/tools/cover \
github.com/tools/godep \ github.com/tools/godep \

View File

@ -1,5 +1,8 @@
# Plain make targets if not requested inside a container # # Plain make targets if not requested inside a container
ifeq ($(USE_CONTAINER),) ifneq (,$(findstring test-integration,$(MAKECMDGOALS)))
include Makefile.inc
include mk/main.mk
else ifeq ($(USE_CONTAINER),)
include Makefile.inc include Makefile.inc
include mk/main.mk include mk/main.mk
else else
@ -7,6 +10,8 @@ else
DOCKER_IMAGE_NAME := "docker-machine-build" DOCKER_IMAGE_NAME := "docker-machine-build"
DOCKER_CONTAINER_NAME := "docker-machine-build-container" DOCKER_CONTAINER_NAME := "docker-machine-build-container"
test: FORCE
%: %:
@docker build -t $(DOCKER_IMAGE_NAME) . @docker build -t $(DOCKER_IMAGE_NAME) .

View File

@ -11,7 +11,7 @@ STATIC ?=
VERBOSE ?= VERBOSE ?=
# Build tags # Build tags
BUILDTAGS ?= BUILDTAGS ?=
# Adjust parallelism for gox # Adjust number of parallel builds (XXX not used)
PARALLEL ?= -1 PARALLEL ?= -1
# Coverage default directory # Coverage default directory
COVERAGE_DIR ?= cover COVERAGE_DIR ?= cover
@ -20,20 +20,14 @@ USE_CONTAINER ?=
# List of cross compilation targets # List of cross compilation targets
ifeq ($(TARGET_OS),) ifeq ($(TARGET_OS),)
TARGET_OS := darwin freebsd linux windows TARGET_OS := darwin linux windows
endif endif
ifeq ($(TARGET_ARCH),) ifeq ($(TARGET_ARCH),)
TARGET_ARCH := amd64 arm 386 TARGET_ARCH := amd64 386
endif endif
# Output prefix, defaults to local directory if not specified # Output prefix, defaults to local directory if not specified
ifeq ($(PREFIX),) ifeq ($(PREFIX),)
PREFIX := $(shell pwd) PREFIX := $(shell pwd)
endif endif
default: build
clean: coverage-clean build-clean
build: build-simple
test: dco fmt vet test-short
validate: dco fmt vet lint test-short test-long

View File

@ -9,7 +9,6 @@ machine:
post: post:
- gvm install go1.5 -B --name=stable - gvm install go1.5 -B --name=stable
- gvm use stable && go get github.com/mitchellh/gox
environment: environment:
# Convenient shortcuts to "common" locations # Convenient shortcuts to "common" locations
@ -30,7 +29,7 @@ dependencies:
test: test:
pre: pre:
- gvm use stable && go version - gvm use stable && go version
- gvm use stable && TARGET_ARCH=amd64 TARGET_OS=linux make build-x: - gvm use stable && make build-simple:
pwd: $BASE_STABLE pwd: $BASE_STABLE
override: override:

4
doc.go Normal file
View File

@ -0,0 +1,4 @@
// Machine defines interfaces to manage a variety of docker instances
// deployed on different backends (VMs, baremetal).
// The goal is to allow users get from zero to docker as fast as possible.
package machine

View File

@ -1,33 +1,23 @@
build-clean: build-clean:
@rm -f $(PREFIX)/bin/* @rm -f $(PREFIX)/bin/*
# Simple build # Cross builder helper
build-simple: $(PREFIX)/bin/$(PKG_NAME) define gocross
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build -o $(PREFIX)/bin/$(1)-$(2)/docker-$(patsubst cmd/%.go,%,$3) \
-a $(VERBOSE_GO) -tags "static_build netgo $(BUILDTAGS)" -installsuffix netgo -ldflags "$(GO_LDFLAGS) \
-extldflags -static" $(GO_GCFLAGS) $(3);
endef
# XXX building with -a fails in debug (with -N -l) ???? # XXX building with -a fails in debug (with -N -l) ????
$(PREFIX)/bin/$(PKG_NAME): $(shell find . -type f -name '*.go') $(PREFIX)/bin/docker-%: ./cmd/%.go $(shell find . -type f -name '*.go')
@go build -o $@ $(VERBOSE_GO) -tags "$(BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" $(GO_GCFLAGS) ./main.go $(GO) build -o $@ $(VERBOSE_GO) -tags "$(BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" $(GO_GCFLAGS) $<
# Cross-build: careful, does always rebuild! # Native build
build-x: clean build-simple: $(patsubst ./cmd/%.go,$(PREFIX)/bin/docker-%,$(wildcard ./cmd/*.go))
$(if $(GOX), , \
$(error Please install gox: go get -u github.com/mitchellh/gox))
@$(GOX) \
-os "$(TARGET_OS)" \
-arch "$(TARGET_ARCH)" \
-output="$(PREFIX)/bin/docker-machine_{{.OS}}-{{.Arch}}" \
-ldflags="$(GO_LDFLAGS)" \
-tags="$(BUILDTAGS)" \
-gcflags="$(GO_GCFLAGS)" \
-parallel=$(PARALLEL) \
-rebuild $(VERBOSE_GOX)
# Cross builder helper # Cross compilation targets
# define gocross build-x-%: ./cmd/%.go $(shell find . -type f -name '*.go')
# GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build -o $(PREFIX)/$(PKG_NAME)_$(1)-$(2) \ @$(foreach GOARCH,$(TARGET_ARCH),$(foreach GOOS,$(TARGET_OS),$(call gocross,$(GOOS),$(GOARCH),$<)))
# -a $(VERBOSE_GO) -tags "static_build netgo $(BUILDTAGS)" -installsuffix netgo -ldflags "$(GO_LDFLAGS) -extldflags -static" $(GO_GCFLAGS) ./main.go;
# endef
# Native build-x (no gox) # Cross-build
# build-x: $(shell find . -type f -name '*.go') build-x: $(patsubst ./cmd/%.go,build-x-%,$(wildcard ./cmd/*.go))
# @$(foreach GOARCH,$(TARGET_ARCH),$(foreach GOOS,$(TARGET_OS),$(call gocross,$(GS),$(GA))))

View File

@ -37,9 +37,9 @@ coverage-clean:
$(COVERAGE_PROFILE): $(shell find . -type f -name '*.go') $(COVERAGE_PROFILE): $(shell find . -type f -name '*.go')
@mkdir -p "$(COVERAGE_OUTPUT)/coverage" @mkdir -p "$(COVERAGE_OUTPUT)/coverage"
@$(foreach PKG,$(PKGS), go test $(VERBOSE) -tags "$(BUILDTAGS)" -covermode=$(COVERAGE_MODE) -coverprofile="$(COVERAGE_OUTPUT)/coverage/`echo $(PKG) | tr "/" "-"`.cover" "$(PKG)";) @$(foreach PKG,$(PKGS), go test $(VERBOSE_GO) -tags "$(BUILDTAGS)" -covermode=$(COVERAGE_MODE) -coverprofile="$(COVERAGE_OUTPUT)/coverage/`echo $(PKG) | tr "/" "-"`.cover" "$(PKG)";)
@echo "mode: $(COVERAGE_MODE)" > "$(COVERAGE_PROFILE)" @echo "mode: $(COVERAGE_MODE)" > "$(COVERAGE_PROFILE)"
@grep -h -v "^mode:" "$(COVERAGE_OUTPUT)/coverage"/*.cover >> "$(COVERAGE_PROFILE)" @grep -h -v "^mode:" "$(COVERAGE_OUTPUT)/coverage"/*.cover >> "$(COVERAGE_PROFILE)"
$(COVERAGE_HTML): $(COVERAGE_PROFILE) $(COVERAGE_HTML): $(COVERAGE_PROFILE)
@go tool cover -html="$(COVERAGE_PROFILE)" -o "$(COVERAGE_HTML)" $(GO) tool cover -html="$(COVERAGE_PROFILE)" -o "$(COVERAGE_HTML)"

View File

@ -32,10 +32,10 @@ endif
# Honor verbose # Honor verbose
VERBOSE_GO := VERBOSE_GO :=
VERBOSE_GOX := GO := @go
ifeq ($(VERBOSE),true) ifeq ($(VERBOSE),true)
VERBOSE_GO := -v VERBOSE_GO := -v
VERBOSE_GOX := -verbose GO := go
endif endif
include mk/build.mk include mk/build.mk
@ -50,4 +50,10 @@ include mk/validate.mk
.all_test: test-short test-long test-integration .all_test: test-short test-long test-integration
.all_validate: dco fmt vet lint .all_validate: dco fmt vet lint
.PHONY: .all_build .all_coverage .all_release .all_test .all_validate default: build
clean: coverage-clean build-clean
build: build-simple
test: dco fmt vet test-short
validate: dco fmt vet lint test-short test-long
.PHONY: .all_build .all_coverage .all_release .all_test .all_validate test build validate clean

View File

@ -1,12 +1,14 @@
# XXX FIXME: suboptimal, as it will sign signatures files if they are there
release-checksum: release-checksum:
$(foreach MACHINE_FILE, $(wildcard $(PREFIX)/bin/*), \ $(foreach MACHINE_FILE, $(wildcard $(PREFIX)/bin/*.zip), \
$(shell openssl dgst -sha256 < "$(MACHINE_FILE)" > "$(MACHINE_FILE).sha256" && \ $(shell openssl dgst -sha256 < "$(MACHINE_FILE)" > "$(MACHINE_FILE).sha256" && \
openssl dgst -md5 < "$(MACHINE_FILE)" > "$(MACHINE_FILE).md5" \ openssl dgst -md5 < "$(MACHINE_FILE)" > "$(MACHINE_FILE).md5" \
)) ))
@: @:
release: clean dco fmt test test-long build-x release-checksum release-pack:
find ./bin -type d -mindepth 1 -exec zip -r -j {}.zip {} \;
release: clean dco fmt test test-long build-x release-pack release-checksum
$(if $(GITHUB_TOKEN), , \ $(if $(GITHUB_TOKEN), , \
$(error GITHUB_TOKEN must be set for github-release)) $(error GITHUB_TOKEN must be set for github-release))
@ -28,7 +30,7 @@ release: clean dco fmt test test-long build-x release-checksum
--description "" \ --description "" \
--pre-release --pre-release
$(foreach MACHINE_FILE, $(wildcard $(PREFIX)/bin/*), \ $(foreach MACHINE_FILE, $(wildcard $(PREFIX)/bin/*.zip), \
$(shell github-release upload \ $(shell github-release upload \
--user $(GH_USER) \ --user $(GH_USER) \
--repo $(GH_REPO) \ --repo $(GH_REPO) \

View File

@ -1,12 +1,12 @@
# Quick test. You can bypass long tests using: `if testing.Short() { t.Skip("Skipping in short mode.") }` # Quick test. You can bypass long tests using: `if testing.Short() { t.Skip("Skipping in short mode.") }`
test-short: test-short:
@go test $(VERBOSE_GO) -test.short -tags "$(BUILDTAGS)" $(PKGS) $(GO) test $(VERBOSE_GO) -test.short -tags "$(BUILDTAGS)" $(PKGS)
# Runs long tests also, plus race detection # Runs long tests also, plus race detection
test-long: test-long:
@go test $(VERBOSE_GO) -race -tags "$(BUILDTAGS)" $(PKGS) $(GO) test $(VERBOSE_GO) -race -tags "$(BUILDTAGS)" $(PKGS)
test-integration: build test-integration:
$(eval TESTSUITE=$(filter-out $@,$(MAKECMDGOALS))) $(eval TESTSUITE=$(filter-out $@,$(MAKECMDGOALS)))
test/integration/run-bats.sh $(TESTSUITE) test/integration/run-bats.sh $(TESTSUITE)

View File

@ -1,6 +1,12 @@
# Validate DCO on all history # Validate DCO on all history
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
current_dir := $(notdir $(patsubst %/,%,$(dir $(mkfile_path))))
# XXX vendorized script miss exec bit, hence the gymnastic
# plus the path resolution...
# TODO migrate away from the shell script and have a make equivalent instead
dco: dco:
@script/validate-dco @echo `bash $(current_dir)/../script/validate-dco`
# Fmt # Fmt
fmt: fmt:
@ -15,4 +21,3 @@ lint:
$(if $(GOLINT), , \ $(if $(GOLINT), , \
$(error Please install golint: go get -u github.com/golang/lint/golint)) $(error Please install golint: go get -u github.com/golang/lint/golint))
@test -z "$$($(GOLINT) ./... 2>&1 | grep -v vendor/ | grep -v Godeps/ | tee /dev/stderr)" @test -z "$$($(GOLINT) ./... 2>&1 | grep -v vendor/ | grep -v Godeps/ | tee /dev/stderr)"

View File

@ -5,12 +5,6 @@ set -e
# Wrapper script to run bats tests for various drivers. # Wrapper script to run bats tests for various drivers.
# Usage: DRIVER=[driver] ./run-bats.sh [subtest] # Usage: DRIVER=[driver] ./run-bats.sh [subtest]
function build_machine() {
cd ${MACHINE_ROOT}
make build-x
cd -
}
function quiet_run () { function quiet_run () {
if [[ "$VERBOSE" == "1" ]]; then if [[ "$VERBOSE" == "1" ]]; then
"$@" "$@"
@ -27,6 +21,7 @@ function cleanup_machines() {
} }
function machine() { function machine() {
export PATH="$MACHINE_ROOT"/bin:$PATH
"$MACHINE_ROOT"/bin/"$MACHINE_BIN_NAME" "$@" "$MACHINE_ROOT"/bin/"$MACHINE_BIN_NAME" "$@"
} }
@ -46,32 +41,10 @@ function run_bats() {
done done
} }
# Platform and architecture information is used to correctly identify the
# binary we want to test.
PLATFORM=`uname -s | tr '[:upper:]' '[:lower:]'`
case "$(uname -m)" in
arm*)
ARCH="arm"
;;
x86_64)
ARCH="amd64"
;;
i*86)
ARCH="386"
;;
*)
ARCH="$(uname -m)"
esac
# Set this ourselves in case bats call fails # Set this ourselves in case bats call fails
EXIT_STATUS=0 EXIT_STATUS=0
export BATS_FILE="$1" export BATS_FILE="$1"
# build machine binary if needed
if [ ! -e "$MACHINE_ROOT"/bin/"$MACHINE_BIN_NAME" ]; then
build_machine
fi
if [[ -z "$DRIVER" ]]; then if [[ -z "$DRIVER" ]]; then
echo "You must specify the DRIVER environment variable." echo "You must specify the DRIVER environment variable."
exit 1 exit 1
@ -92,7 +65,7 @@ export BASE_TEST_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
export MACHINE_ROOT="$BASE_TEST_DIR/../.." export MACHINE_ROOT="$BASE_TEST_DIR/../.."
export NAME="bats-$DRIVER-test" export NAME="bats-$DRIVER-test"
export MACHINE_STORAGE_PATH="/tmp/machine-bats-test-$DRIVER" export MACHINE_STORAGE_PATH="/tmp/machine-bats-test-$DRIVER"
export MACHINE_BIN_NAME=docker-machine_$PLATFORM-$ARCH export MACHINE_BIN_NAME=docker-machine
export BATS_LOG="$MACHINE_ROOT/bats.log" export BATS_LOG="$MACHINE_ROOT/bats.log"
# This function gets used in the integration tests, so export it. # This function gets used in the integration tests, so export it.