Skip to content

Commit 73f58e1

Browse files
authored
Merge pull request #1776 from fcrisciani/makefile
Makefile
2 parents f4a15a0 + 4994c59 commit 73f58e1

File tree

23 files changed

+93
-48
lines changed

23 files changed

+93
-48
lines changed

Dockerfile.build

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
FROM golang:1.7.1
1+
FROM golang:1.8.3
22
RUN apt-get update && apt-get -y install iptables
33

44
RUN go get github.com/tools/godep \
55
github.com/golang/lint/golint \
6-
golang.org/x/tools/cmd/cover\
7-
github.com/mattn/goveralls
6+
golang.org/x/tools/cmd/cover \
7+
github.com/mattn/goveralls \
8+
github.com/gordonklaus/ineffassign \
9+
github.com/client9/misspell/cmd/misspell

Makefile

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
1+
.PHONY: all all-local build build-local clean cross cross-local vet lint misspell check check-code check-format run-tests integration-tests check-local coveralls circle-ci-cross circle-ci-build circle-ci-check circle-ci
22
SHELL=/bin/bash
33
build_image=libnetworkbuild
44
dockerargs = --privileged -v $(shell pwd):/go/src/github.com/docker/libnetwork -w /go/src/github.com/docker/libnetwork
@@ -7,6 +7,7 @@ docker = docker run --rm -it ${dockerargs} $$EXTRA_ARGS ${container_env} ${build
77
ciargs = -e CIRCLECI -e "COVERALLS_TOKEN=$$COVERALLS_TOKEN" -e "INSIDECONTAINER=-incontainer=true"
88
cidocker = docker run ${dockerargs} ${ciargs} $$EXTRA_ARGS ${container_env} ${build_image}
99
CROSS_PLATFORMS = linux/amd64 linux/386 linux/arm windows/amd64
10+
PACKAGES=$(shell go list ./... | grep -v /vendor/)
1011
export PATH := $(CURDIR)/bin:$(PATH)
1112
hostOS = ${shell go env GOHOSTOS}
1213
ifeq (${hostOS}, solaris)
@@ -22,25 +23,31 @@ all: ${build_image}.created build check integration-tests clean
2223
all-local: build-local check-local integration-tests-local clean
2324

2425
${build_image}.created:
26+
@echo "🐳 $@"
2527
docker build -f Dockerfile.build -t ${build_image} .
2628
touch ${build_image}.created
2729

2830
build: ${build_image}.created
29-
@echo "Building code... "
31+
@echo "🐳 $@"
3032
@${docker} ./wrapmake.sh build-local
31-
@echo "Done building code"
3233

3334
build-local:
35+
@echo "🐳 $@"
3436
@mkdir -p "bin"
3537
go build -tags experimental -o "bin/dnet" ./cmd/dnet
3638
go build -o "bin/docker-proxy" ./cmd/proxy
3739

3840
clean:
41+
@echo "🐳 $@"
3942
@if [ -d bin ]; then \
4043
echo "Removing dnet and proxy binaries"; \
4144
rm -rf bin; \
4245
fi
4346

47+
force-clean: clean
48+
@echo "🐳 $@"
49+
@rm -rf ${build_image}.created
50+
4451
cross: ${build_image}.created
4552
@mkdir -p "bin"
4653
@for platform in ${CROSS_PLATFORMS}; do \
@@ -50,25 +57,19 @@ cross: ${build_image}.created
5057
done
5158

5259
cross-local:
60+
@echo "🐳 $@"
5361
go build -o "bin/dnet-$$GOOS-$$GOARCH" ./cmd/dnet
5462
go build -o "bin/docker-proxy-$$GOOS-$$GOARCH" ./cmd/proxy
5563

5664
check: ${build_image}.created
5765
@${docker} ./wrapmake.sh check-local
5866

59-
check-code:
60-
@echo "Checking code... "
61-
test -z "$$(golint ./... | grep -Ev 'vendor|.pb.go:' | tee /dev/stderr)"
62-
test -z "$$(go vet ./... 2>&1 > /dev/null | grep -Ev 'vendor|exit' | tee /dev/stderr)"
63-
@echo "Done checking code"
67+
check-code: lint vet ineffassign
6468

65-
check-format:
66-
@echo "Checking format... "
67-
test -z "$$(gofmt -s -l . | grep -v vendor/ | tee /dev/stderr)"
68-
@echo "Done checking format"
69+
check-format: fmt misspell
6970

7071
run-tests:
71-
@echo "Running tests... "
72+
@echo "🐳 Running tests... "
7273
@echo "mode: count" > coverage.coverprofile
7374
@for dir in $$( ${gnufind} . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -not -path './vendor/*' -type d); do \
7475
if [ ${hostOS} == solaris ]; then \
@@ -130,6 +131,28 @@ integration-tests: ./bin/dnet
130131
coveralls:
131132
-@goveralls -service circleci -coverprofile=coverage.coverprofile -repotoken $$COVERALLS_TOKEN
132133

134+
# Depends on binaries because vet will silently fail if it can not load compiled imports
135+
vet: ## run go vet
136+
@echo "🐳 $@"
137+
@test -z "$$(go vet ${PACKAGES} 2>&1 | grep -v 'constant [0-9]* not a string in call to Errorf' | egrep -v '(timestamp_test.go|duration_test.go|exit status 1)' | tee /dev/stderr)"
138+
139+
misspell:
140+
@echo "🐳 $@"
141+
@test -z "$$(find . -type f | grep -v vendor/ | grep -v bin/ | grep -v .git/ | grep -v MAINTAINERS | xargs misspell | tee /dev/stderr)"
142+
143+
fmt: ## run go fmt
144+
@echo "🐳 $@"
145+
@test -z "$$(gofmt -s -l . | grep -v vendor/ | grep -v ".pb.go$$" | tee /dev/stderr)" || \
146+
(echo "👹 please format Go code with 'gofmt -s -w'" && false)
147+
148+
lint: ## run go lint
149+
@echo "🐳 $@"
150+
@test -z "$$(golint ./... | grep -v vendor/ | grep -v ".pb.go:" | grep -v ".mock.go" | tee /dev/stderr)"
151+
152+
ineffassign: ## run ineffassign
153+
@echo "🐳 $@"
154+
@test -z "$$(ineffassign . | grep -v vendor/ | grep -v ".pb.go:" | grep -v ".mock.go" | tee /dev/stderr)"
155+
133156
# CircleCI's Docker fails when cleaning up using the --rm flag
134157
# The following targets are a workaround for this
135158
circle-ci-cross: ${build_image}.created

agent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ func (c *controller) handleKeyChange(keys []*types.EncryptionKey) error {
165165
a.networkDB.SetKey(added)
166166
}
167167

168-
key, tag, err := c.getPrimaryKeyTag(subsysGossip)
168+
key, _, err := c.getPrimaryKeyTag(subsysGossip)
169169
if err != nil {
170170
return err
171171
}
172172
a.networkDB.SetPrimaryKey(key)
173173

174-
key, tag, err = c.getPrimaryKeyTag(subsysIPSec)
174+
key, tag, err := c.getPrimaryKeyTag(subsysIPSec)
175175
if err != nil {
176176
return err
177177
}

api/api_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,9 @@ func TestAttachDetachBackend(t *testing.T) {
914914

915915
cid := "abcdefghi"
916916
sbox, err := c.NewSandbox(cid)
917+
if err != nil {
918+
t.Fatal(err)
919+
}
917920
sid := sbox.ID()
918921
defer sbox.Delete()
919922

@@ -1280,6 +1283,9 @@ func TestJoinLeave(t *testing.T) {
12801283

12811284
cid := "abcdefghi"
12821285
sb, err := c.NewSandbox(cid)
1286+
if err != nil {
1287+
t.Fatal(err)
1288+
}
12831289
defer sb.Delete()
12841290

12851291
jl := endpointJoin{SandboxID: sb.ID()}

client/mflag/example/example.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var (
1313
)
1414

1515
func init() {
16-
flag.Bool([]string{"#hp", "#-halp"}, false, "display the halp")
16+
flag.Bool([]string{"#hp", "#-help"}, false, "display the help")
1717
flag.BoolVar(&b, []string{"b", "#bal", "#bol", "-bal"}, false, "a simple bool")
1818
flag.BoolVar(&b, []string{"g", "#gil"}, false, "a simple bool")
1919
flag.BoolVar(&b2, []string{"#-bool"}, false, "a simple bool")

common/setmatrix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type SetMatrix interface {
2222
// returns true if the mapping was deleted, false otherwise
2323
// returns also the number of endpoints associated to the IP
2424
Remove(key string, value interface{}) (bool, int)
25-
// Cardinality returns the number of elements in the set of a specfic key
25+
// Cardinality returns the number of elements in the set of a specific key
2626
// returns false if the key is not in the map
2727
Cardinality(key string) (int, bool)
2828
// String returns the string version of the set, empty otherwise

controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ func (c *controller) NetworkByID(id string) (Network, error) {
10141014
}
10151015

10161016
// NewSandbox creates a new sandbox for the passed container id
1017-
func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (sBox Sandbox, err error) {
1017+
func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (Sandbox, error) {
10181018
if containerID == "" {
10191019
return nil, types.BadRequestErrorf("invalid container ID")
10201020
}
@@ -1054,7 +1054,6 @@ func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (s
10541054
extDNS: []extDNSEntry{},
10551055
}
10561056
}
1057-
sBox = sb
10581057

10591058
heap.Init(&sb.endpoints)
10601059

@@ -1073,6 +1072,8 @@ func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (s
10731072
sb.id = "ingress_sbox"
10741073
}
10751074
c.Unlock()
1075+
1076+
var err error
10761077
defer func() {
10771078
if err != nil {
10781079
c.Lock()

datastore/datastore_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ func TestAtomicKVObjectFlatKey(t *testing.T) {
101101
// Get the Object using GetObject, then set again.
102102
newObj := dummyObject{}
103103
err = store.GetObject(Key(expected.Key()...), &newObj)
104+
if err != nil {
105+
t.Fatal(err)
106+
}
104107
assert.True(t, newObj.Exists())
105108
err = store.PutObjectAtomic(&n)
106109
if err != nil {

drivers/overlay/ov_network.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ func (n *network) initSandbox(restore bool) error {
670670
// In the restore case network sandbox already exist; but we don't know
671671
// what epoch number it was created with. It has to be retrieved by
672672
// searching the net namespaces.
673-
key := ""
673+
var key string
674674
if restore {
675675
key = osl.GenerateKey("-" + n.id)
676676
} else {
@@ -872,15 +872,10 @@ func (n *network) Value() []byte {
872872
netJSON = append(netJSON, sj)
873873
}
874874

875-
b, err := json.Marshal(netJSON)
876-
if err != nil {
877-
return []byte{}
878-
}
879-
880875
m["secure"] = n.secure
881876
m["subnets"] = netJSON
882877
m["mtu"] = n.mtu
883-
b, err = json.Marshal(m)
878+
b, err := json.Marshal(m)
884879
if err != nil {
885880
return []byte{}
886881
}

drivers/solaris/overlay/ov_network.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ func (n *network) initSandbox(restore bool) error {
457457
// In the restore case network sandbox already exist; but we don't know
458458
// what epoch number it was created with. It has to be retrieved by
459459
// searching the net namespaces.
460-
key := ""
460+
var key string
461461
if restore {
462462
key = osl.GenerateKey("-" + n.id)
463463
} else {
@@ -570,15 +570,10 @@ func (n *network) Value() []byte {
570570
netJSON = append(netJSON, sj)
571571
}
572572

573-
b, err := json.Marshal(netJSON)
574-
if err != nil {
575-
return []byte{}
576-
}
577-
578573
m["secure"] = n.secure
579574
m["subnets"] = netJSON
580575
m["mtu"] = n.mtu
581-
b, err = json.Marshal(m)
576+
b, err := json.Marshal(m)
582577
if err != nil {
583578
return []byte{}
584579
}

0 commit comments

Comments
 (0)