Skip to content

Commit 56160e0

Browse files
author
Olivier Gambier
committed
Prepare build for plugins PR
Signed-off-by: Olivier Gambier <olivier@docker.com>
1 parent 870d5c9 commit 56160e0

File tree

14 files changed

+81
-110
lines changed

14 files changed

+81
-110
lines changed

CONTRIBUTING.md

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,25 @@ guidelines](https://github.com/docker/docker/blob/master/CONTRIBUTING.md).
1818

1919
The requirements to build Machine are:
2020

21-
1. A running instance of Docker (or alternatively a golang 1.5 development environment)
21+
1. A running instance of Docker
2222
2. The `bash` shell
2323
3. [Make](https://www.gnu.org/software/make/)
2424

2525
Call `export USE_CONTAINER=true` to instruct the build system to use containers to build.
26-
If you want to build natively using golang instead, don't set this variable.
26+
27+
# Alternative: build using go only
28+
29+
Alternatively, you can build without docker, using only golang.
30+
31+
[Install and setup go](https://golang.org/doc/install), then clone the machine repository inside your gopath.
2732

2833
## Building
2934

3035
To build the docker-machine binary, simply run:
3136

32-
$ make
37+
$ make build
3338

34-
From the Machine repository's root. You will now find a `bin/docker-machine`
35-
binary at the root of the project.
39+
From the Machine repository's root. You will now have a `bin/docker-machine`.
3640

3741
You may call:
3842

@@ -61,6 +65,8 @@ To generate an html code coverage report of the Machine codebase, run:
6165

6266
And navigate to http://localhost:8000 (hit `CTRL+C` to stop the server).
6367

68+
### Native build
69+
6470
Alternatively, if you are building natively, you can simply run:
6571

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

8187
### Build targets
8288

83-
Build a single, native machine binary:
89+
Just build the machine binary itself:
8490

85-
make build-simple
91+
make `pwd`/bin/docker-machine
8692

8793
Build for all supported oses and architectures (binaries will be in the `bin` project subfolder):
8894

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

103108
Scrub build results:
104109

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

135140
### Basic Usage
136141

137-
Integration tests can be invoked calling `make test-integration`.
138-
139-
:warn: you cannot run integration test inside a container for now.
140-
Be sure to unset the `USE_CONTAINER` env variable if you set it earlier, or alternatively
141-
call directly `./test/integration/run-bats.sh` instead of `make test-integration`.
142+
You first need to build, calling `make build`.
142143

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

146-
To invoke just one test:
147+
Examples:
147148

148149
```console
149150
$ DRIVER=virtualbox make test-integration test/integration/core/core-commands.bats
@@ -170,13 +171,6 @@ Cleaning up machines...
170171
Successfully removed bats-virtualbox-test
171172
```
172173

173-
To invoke a shared test with a different driver:
174-
175-
```console
176-
$ DRIVER=digitalocean make test-integration test/integration/core/core-commands.bats
177-
...
178-
```
179-
180174
To invoke a directory of tests recursively:
181175

182176
```console

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
FROM golang:1.5
22

3-
RUN go get github.com/mitchellh/gox \
4-
github.com/golang/lint/golint \
3+
RUN go get github.com/golang/lint/golint \
54
github.com/mattn/goveralls \
65
golang.org/x/tools/cover \
76
github.com/tools/godep \

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
# Plain make targets if not requested inside a container
2-
ifeq ($(USE_CONTAINER),)
1+
# # Plain make targets if not requested inside a container
2+
ifneq (,$(findstring test-integration,$(MAKECMDGOALS)))
3+
include Makefile.inc
4+
include mk/main.mk
5+
else ifeq ($(USE_CONTAINER),)
36
include Makefile.inc
47
include mk/main.mk
58
else
69
# Otherwise, with docker, swallow all targets and forward into a container
710
DOCKER_IMAGE_NAME := "docker-machine-build"
811
DOCKER_CONTAINER_NAME := "docker-machine-build-container"
912

13+
test: FORCE
14+
1015
%:
1116
@docker build -t $(DOCKER_IMAGE_NAME) .
1217

Makefile.inc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ STATIC ?=
1111
VERBOSE ?=
1212
# Build tags
1313
BUILDTAGS ?=
14-
# Adjust parallelism for gox
14+
# Adjust number of parallel builds (XXX not used)
1515
PARALLEL ?= -1
1616
# Coverage default directory
1717
COVERAGE_DIR ?= cover
@@ -20,20 +20,14 @@ USE_CONTAINER ?=
2020

2121
# List of cross compilation targets
2222
ifeq ($(TARGET_OS),)
23-
TARGET_OS := darwin freebsd linux windows
23+
TARGET_OS := darwin linux windows
2424
endif
2525

2626
ifeq ($(TARGET_ARCH),)
27-
TARGET_ARCH := amd64 arm 386
27+
TARGET_ARCH := amd64 386
2828
endif
2929

3030
# Output prefix, defaults to local directory if not specified
3131
ifeq ($(PREFIX),)
3232
PREFIX := $(shell pwd)
3333
endif
34-
35-
default: build
36-
clean: coverage-clean build-clean
37-
build: build-simple
38-
test: dco fmt vet test-short
39-
validate: dco fmt vet lint test-short test-long

circle.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ machine:
99

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

1413
environment:
1514
# Convenient shortcuts to "common" locations
@@ -30,7 +29,7 @@ dependencies:
3029
test:
3130
pre:
3231
- gvm use stable && go version
33-
- gvm use stable && TARGET_ARCH=amd64 TARGET_OS=linux make build-x:
32+
- gvm use stable && make build-simple:
3433
pwd: $BASE_STABLE
3534

3635
override:
File renamed without changes.

doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Machine defines interfaces to manage a variety of docker instances
2+
// deployed on different backends (VMs, baremetal).
3+
// The goal is to allow users get from zero to docker as fast as possible.
4+
package machine

mk/build.mk

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
11
build-clean:
22
@rm -f $(PREFIX)/bin/*
33

4-
# Simple build
5-
build-simple: $(PREFIX)/bin/$(PKG_NAME)
4+
# Cross builder helper
5+
define gocross
6+
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build -o $(PREFIX)/bin/$(1)-$(2)/docker-$(patsubst cmd/%.go,%,$3) \
7+
-a $(VERBOSE_GO) -tags "static_build netgo $(BUILDTAGS)" -installsuffix netgo -ldflags "$(GO_LDFLAGS) \
8+
-extldflags -static" $(GO_GCFLAGS) $(3);
9+
endef
610

711
# XXX building with -a fails in debug (with -N -l) ????
8-
$(PREFIX)/bin/$(PKG_NAME): $(shell find . -type f -name '*.go')
9-
@go build -o $@ $(VERBOSE_GO) -tags "$(BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" $(GO_GCFLAGS) ./main.go
12+
$(PREFIX)/bin/docker-%: ./cmd/%.go $(shell find . -type f -name '*.go')
13+
$(GO) build -o $@ $(VERBOSE_GO) -tags "$(BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" $(GO_GCFLAGS) $<
1014

11-
# Cross-build: careful, does always rebuild!
12-
build-x: clean
13-
$(if $(GOX), , \
14-
$(error Please install gox: go get -u github.com/mitchellh/gox))
15-
@$(GOX) \
16-
-os "$(TARGET_OS)" \
17-
-arch "$(TARGET_ARCH)" \
18-
-output="$(PREFIX)/bin/docker-machine_{{.OS}}-{{.Arch}}" \
19-
-ldflags="$(GO_LDFLAGS)" \
20-
-tags="$(BUILDTAGS)" \
21-
-gcflags="$(GO_GCFLAGS)" \
22-
-parallel=$(PARALLEL) \
23-
-rebuild $(VERBOSE_GOX)
15+
# Native build
16+
build-simple: $(patsubst ./cmd/%.go,$(PREFIX)/bin/docker-%,$(wildcard ./cmd/*.go))
2417

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

31-
# Native build-x (no gox)
32-
# build-x: $(shell find . -type f -name '*.go')
33-
# @$(foreach GOARCH,$(TARGET_ARCH),$(foreach GOOS,$(TARGET_OS),$(call gocross,$(GS),$(GA))))
22+
# Cross-build
23+
build-x: $(patsubst ./cmd/%.go,build-x-%,$(wildcard ./cmd/*.go))

mk/coverage.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ coverage-clean:
3737

3838
$(COVERAGE_PROFILE): $(shell find . -type f -name '*.go')
3939
@mkdir -p "$(COVERAGE_OUTPUT)/coverage"
40-
@$(foreach PKG,$(PKGS), go test $(VERBOSE) -tags "$(BUILDTAGS)" -covermode=$(COVERAGE_MODE) -coverprofile="$(COVERAGE_OUTPUT)/coverage/`echo $(PKG) | tr "/" "-"`.cover" "$(PKG)";)
40+
@$(foreach PKG,$(PKGS), go test $(VERBOSE_GO) -tags "$(BUILDTAGS)" -covermode=$(COVERAGE_MODE) -coverprofile="$(COVERAGE_OUTPUT)/coverage/`echo $(PKG) | tr "/" "-"`.cover" "$(PKG)";)
4141
@echo "mode: $(COVERAGE_MODE)" > "$(COVERAGE_PROFILE)"
4242
@grep -h -v "^mode:" "$(COVERAGE_OUTPUT)/coverage"/*.cover >> "$(COVERAGE_PROFILE)"
4343

4444
$(COVERAGE_HTML): $(COVERAGE_PROFILE)
45-
@go tool cover -html="$(COVERAGE_PROFILE)" -o "$(COVERAGE_HTML)"
45+
$(GO) tool cover -html="$(COVERAGE_PROFILE)" -o "$(COVERAGE_HTML)"

mk/main.mk

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ endif
3232

3333
# Honor verbose
3434
VERBOSE_GO :=
35-
VERBOSE_GOX :=
35+
GO := @go
3636
ifeq ($(VERBOSE),true)
3737
VERBOSE_GO := -v
38-
VERBOSE_GOX := -verbose
38+
GO := go
3939
endif
4040

4141
include mk/build.mk
@@ -50,4 +50,10 @@ include mk/validate.mk
5050
.all_test: test-short test-long test-integration
5151
.all_validate: dco fmt vet lint
5252

53-
.PHONY: .all_build .all_coverage .all_release .all_test .all_validate
53+
default: build
54+
clean: coverage-clean build-clean
55+
build: build-simple
56+
test: dco fmt vet test-short
57+
validate: dco fmt vet lint test-short test-long
58+
59+
.PHONY: .all_build .all_coverage .all_release .all_test .all_validate test build validate clean

0 commit comments

Comments
 (0)