Skip to content

Commit

Permalink
Prepare build for plugins PR
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Gambier <olivier@docker.com>
  • Loading branch information
Olivier Gambier committed Oct 8, 2015
1 parent 870d5c9 commit 56160e0
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 110 deletions.
42 changes: 18 additions & 24 deletions CONTRIBUTING.md
Expand Up @@ -18,21 +18,25 @@ guidelines](https://github.com/docker/docker/blob/master/CONTRIBUTING.md).

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
3. [Make](https://www.gnu.org/software/make/)

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

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`
binary at the root of the project.
From the Machine repository's root. You will now have a `bin/docker-machine`.

You may call:

Expand Down Expand Up @@ -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).

### Native build

Alternatively, if you are building natively, you can simply run:

make coverage-html
Expand All @@ -80,9 +86,9 @@ This will generate and open the report file:

### 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):

Expand All @@ -97,8 +103,7 @@ You can further control build options through the following environment variable
DEBUG=true # enable debug build
STATIC=true # build static (note: when cross-compiling, the build is always static)
VERBOSE=true # verbose output
PARALLEL=X # lets you control build parallelism when cross-compiling multiple builds
PREFIX=folder
PREFIX=folder # put binaries in another folder (not the default `./bin`)

Scrub build results:

Expand Down Expand Up @@ -134,16 +139,12 @@ first make sure to [install it](https://github.com/sstephenson/bats#installing-b

### Basic Usage

Integration tests can be invoked calling `make test-integration`.

:warn: you cannot run integration test inside a container for now.
Be sure to unset the `USE_CONTAINER` env variable if you set it earlier, or alternatively
call directly `./test/integration/run-bats.sh` instead of `make test-integration`.
You first need to build, calling `make build`.

You can invoke a test or subset of tests for a particular driver.
To set the driver, use the `DRIVER` environment variable.
You can then invoke integration tests calling `DRIVER=foo make test-integration TESTSUITE`, where `TESTSUITE` is
one of the `test/integration` subfolder, and `foo` is the specific driver you want to test.

To invoke just one test:
Examples:

```console
$ DRIVER=virtualbox make test-integration test/integration/core/core-commands.bats
Expand All @@ -170,13 +171,6 @@ Cleaning up machines...
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:

```console
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
@@ -1,7 +1,6 @@
FROM golang:1.5

RUN go get github.com/mitchellh/gox \
github.com/golang/lint/golint \
RUN go get github.com/golang/lint/golint \
github.com/mattn/goveralls \
golang.org/x/tools/cover \
github.com/tools/godep \
Expand Down
9 changes: 7 additions & 2 deletions Makefile
@@ -1,12 +1,17 @@
# Plain make targets if not requested inside a container
ifeq ($(USE_CONTAINER),)
# # Plain make targets if not requested inside a container
ifneq (,$(findstring test-integration,$(MAKECMDGOALS)))
include Makefile.inc
include mk/main.mk
else ifeq ($(USE_CONTAINER),)
include Makefile.inc
include mk/main.mk
else
# Otherwise, with docker, swallow all targets and forward into a container
DOCKER_IMAGE_NAME := "docker-machine-build"
DOCKER_CONTAINER_NAME := "docker-machine-build-container"

test: FORCE

%:
@docker build -t $(DOCKER_IMAGE_NAME) .

Expand Down
12 changes: 3 additions & 9 deletions Makefile.inc
Expand Up @@ -11,7 +11,7 @@ STATIC ?=
VERBOSE ?=
# Build tags
BUILDTAGS ?=
# Adjust parallelism for gox
# Adjust number of parallel builds (XXX not used)
PARALLEL ?= -1
# Coverage default directory
COVERAGE_DIR ?= cover
Expand All @@ -20,20 +20,14 @@ USE_CONTAINER ?=

# List of cross compilation targets
ifeq ($(TARGET_OS),)
TARGET_OS := darwin freebsd linux windows
TARGET_OS := darwin linux windows
endif

ifeq ($(TARGET_ARCH),)
TARGET_ARCH := amd64 arm 386
TARGET_ARCH := amd64 386
endif

# Output prefix, defaults to local directory if not specified
ifeq ($(PREFIX),)
PREFIX := $(shell pwd)
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
3 changes: 1 addition & 2 deletions circle.yml
Expand Up @@ -9,7 +9,6 @@ machine:

post:
- gvm install go1.5 -B --name=stable
- gvm use stable && go get github.com/mitchellh/gox

environment:
# Convenient shortcuts to "common" locations
Expand All @@ -30,7 +29,7 @@ dependencies:
test:
pre:
- 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

override:
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions doc.go
@@ -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
40 changes: 15 additions & 25 deletions mk/build.mk
@@ -1,33 +1,23 @@
build-clean:
@rm -f $(PREFIX)/bin/*

# Simple build
build-simple: $(PREFIX)/bin/$(PKG_NAME)
# Cross builder helper
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) ????
$(PREFIX)/bin/$(PKG_NAME): $(shell find . -type f -name '*.go')
@go build -o $@ $(VERBOSE_GO) -tags "$(BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" $(GO_GCFLAGS) ./main.go
$(PREFIX)/bin/docker-%: ./cmd/%.go $(shell find . -type f -name '*.go')
$(GO) build -o $@ $(VERBOSE_GO) -tags "$(BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" $(GO_GCFLAGS) $<

# Cross-build: careful, does always rebuild!
build-x: clean
$(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)
# Native build
build-simple: $(patsubst ./cmd/%.go,$(PREFIX)/bin/docker-%,$(wildcard ./cmd/*.go))

# Cross builder helper
# define gocross
# GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build -o $(PREFIX)/$(PKG_NAME)_$(1)-$(2) \
# -a $(VERBOSE_GO) -tags "static_build netgo $(BUILDTAGS)" -installsuffix netgo -ldflags "$(GO_LDFLAGS) -extldflags -static" $(GO_GCFLAGS) ./main.go;
# endef
# Cross compilation targets
build-x-%: ./cmd/%.go $(shell find . -type f -name '*.go')
@$(foreach GOARCH,$(TARGET_ARCH),$(foreach GOOS,$(TARGET_OS),$(call gocross,$(GOOS),$(GOARCH),$<)))

# Native build-x (no gox)
# build-x: $(shell find . -type f -name '*.go')
# @$(foreach GOARCH,$(TARGET_ARCH),$(foreach GOOS,$(TARGET_OS),$(call gocross,$(GS),$(GA))))
# Cross-build
build-x: $(patsubst ./cmd/%.go,build-x-%,$(wildcard ./cmd/*.go))
4 changes: 2 additions & 2 deletions mk/coverage.mk
Expand Up @@ -37,9 +37,9 @@ coverage-clean:

$(COVERAGE_PROFILE): $(shell find . -type f -name '*.go')
@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)"
@grep -h -v "^mode:" "$(COVERAGE_OUTPUT)/coverage"/*.cover >> "$(COVERAGE_PROFILE)"

$(COVERAGE_HTML): $(COVERAGE_PROFILE)
@go tool cover -html="$(COVERAGE_PROFILE)" -o "$(COVERAGE_HTML)"
$(GO) tool cover -html="$(COVERAGE_PROFILE)" -o "$(COVERAGE_HTML)"
12 changes: 9 additions & 3 deletions mk/main.mk
Expand Up @@ -32,10 +32,10 @@ endif

# Honor verbose
VERBOSE_GO :=
VERBOSE_GOX :=
GO := @go
ifeq ($(VERBOSE),true)
VERBOSE_GO := -v
VERBOSE_GOX := -verbose
GO := go
endif

include mk/build.mk
Expand All @@ -50,4 +50,10 @@ include mk/validate.mk
.all_test: test-short test-long test-integration
.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
12 changes: 7 additions & 5 deletions mk/release.mk
@@ -1,12 +1,14 @@
# XXX FIXME: suboptimal, as it will sign signatures files if they are there
release-checksum:
$(foreach MACHINE_FILE, $(wildcard $(PREFIX)/bin/*), \
$(foreach MACHINE_FILE, $(wildcard $(PREFIX)/bin/*.zip), \
$(shell openssl dgst -sha256 < "$(MACHINE_FILE)" > "$(MACHINE_FILE).sha256" && \
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), , \
$(error GITHUB_TOKEN must be set for github-release))

Expand All @@ -28,7 +30,7 @@ release: clean dco fmt test test-long build-x release-checksum
--description "" \
--pre-release

$(foreach MACHINE_FILE, $(wildcard $(PREFIX)/bin/*), \
$(foreach MACHINE_FILE, $(wildcard $(PREFIX)/bin/*.zip), \
$(shell github-release upload \
--user $(GH_USER) \
--repo $(GH_REPO) \
Expand All @@ -39,4 +41,4 @@ release: clean dco fmt test test-long build-x release-checksum
)

%:
@:
@:
6 changes: 3 additions & 3 deletions mk/test.mk
@@ -1,12 +1,12 @@
# Quick test. You can bypass long tests using: `if testing.Short() { t.Skip("Skipping in short mode.") }`
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
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)))
test/integration/run-bats.sh $(TESTSUITE)

Expand Down
11 changes: 8 additions & 3 deletions mk/validate.mk
@@ -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:
@script/validate-dco
@echo `bash $(current_dir)/../script/validate-dco`

# Fmt
fmt:
Expand All @@ -15,4 +21,3 @@ lint:
$(if $(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)"

0 comments on commit 56160e0

Please sign in to comment.