This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMakefile
105 lines (87 loc) · 3.13 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# REPO
REPO?=github.com/docker/infrakit.digitalocean
# Set an output prefix, which is the local directory if not specified
PREFIX?=$(shell pwd -L)
# Used to populate version variable in main package.
VERSION?=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
REVISION?=$(shell git rev-list -1 HEAD)
.PHONY: clean all fmt vet lint build test containers integration-tests
.DEFAULT: all
all: fmt vet lint build test
ci: fmt vet lint coverage
# Package list
PKGS_AND_MOCKS := $(shell go list ./... | grep -v ^${REPO}/vendor/)
PKGS := $(shell echo $(PKGS_AND_MOCKS) | tr ' ' '\n' | grep -v /mock$)
vet:
@echo "+ $@"
@go vet $(PKGS)
fmt:
@echo "+ $@"
@test -z "$$(gofmt -s -l . 2>&1 | grep -v ^vendor/ | tee /dev/stderr)" || \
(echo >&2 "+ please format Go code with 'gofmt -s', or use 'make fmt-save'" && false)
fmt-save:
@echo "+ $@"
@gofmt -s -l . 2>&1 | grep -v ^vendor/ | xargs gofmt -s -l -w
lint:
@echo "+ $@"
$(if $(shell which golint || echo ''), , \
$(error Please install golint: `go get -u github.com/golang/lint/golint`))
@test -z "$$(golint ./... 2>&1 | grep -v ^vendor/ | grep -v mock/ | tee /dev/stderr)"
build:
@echo "+ $@"
@go build ${GO_LDFLAGS} $(PKGS)
clean:
@echo "+ $@"
rm -rf build
mkdir -p build
binaries: clean build-binaries
build-binaries:
@echo "+ $@"
ifneq (,$(findstring .m,$(VERSION)))
@echo "\nWARNING - repository contains uncommitted changes, tagging binaries as dirty\n"
endif
go build -o build/infrakit-instance-digitalocean \
-ldflags "-X github.com/docker/infrakit.digitalocean/plugin.Version=$(VERSION) -X github.com/docker/infrakit.digitalocean/plugin.Revision=$(REVISION)" ./plugin/instance/cmd
test:
@echo "+ $@"
@go test -test.short -race -v $(PKGS)
coverage:
@echo "+ $@"
@for pkg in $(PKGS); do \
go test -test.short -coverprofile="../../../$$pkg/coverage.txt" $${pkg} || exit 1; \
done
test-full:
@echo "+ $@"
@go test -race $(PKGS)
# Current working environment. Set these explicitly if you want to cross-compile
# in the build container (see the build-in-container target):
GOOS?=$(shell go env GOOS)
GOARCH?=$(shell go env GOARCH)
DOCKER_BUILD_FLAGS?=--no-cache --pull
build-in-container:
@echo "+ $@"
@docker build ${DOCKER_BUILD_FLAGS} -t infrakit-build -f ${CURDIR}/dockerfiles/Dockerfile.build .
@docker run --rm \
-e GOOS=${GOOS} -e GOARCCH=${GOARCH} -e DOCKER_CLIENT_VERSION=${DOCKER_CLIENT_VERSION} \
-v ${CURDIR}/build:/go/src/${REPO}/build \
infrakit-build
# For packaging as Docker container images. Set the environment variables DOCKER_PUSH, DOCKER_TAG_LATEST
# if also push to remote repo. You must have access to the remote repo.
DOCKER_IMAGE?=infrakit/digitalocean
DOCKER_TAG?=dev
build-docker:
@echo "+ $@"
GOOS=linux GOARCH=amd64 make build-in-container
@docker build ${DOCKER_BUILD_FLAGS} \
-t ${DOCKER_IMAGE}:${DOCKER_TAG} \
-f ${CURDIR}/dockerfiles/Dockerfile.bundle .
ifeq (${DOCKER_PUSH},true)
@docker push ${DOCKER_IMAGE}:${DOCKER_TAG}
ifeq (${DOCKER_TAG_LATEST},true)
@docker tag ${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_IMAGE}:latest
@docker push ${DOCKER_IMAGE}:latest
endif
endif
integration-tests:
@echo "+ $@"
@cd ${CURDIR}/integration; ./instance.sh