-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
127 lines (103 loc) · 3.19 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
PROJECT := vault-monkey
SCRIPTDIR := $(shell pwd)
ROOTDIR := $(shell cd $(SCRIPTDIR) && pwd)
VERSION:= $(shell cat $(ROOTDIR)/VERSION)
COMMIT := $(shell git rev-parse --short HEAD)
GOBUILDDIR := $(SCRIPTDIR)/.gobuild
SRCDIR := $(SCRIPTDIR)
BINDIR := $(ROOTDIR)/bin
VENDORDIR := $(SCRIPTDIR)/deps
ORGPATH := github.com/pulcy
ORGDIR := $(GOBUILDDIR)/src/$(ORGPATH)
REPONAME := $(PROJECT)
REPODIR := $(ORGDIR)/$(REPONAME)
REPOPATH := $(ORGPATH)/$(REPONAME)
MANIFESTTOOL := $(GOPATH)/bin/manifest-tool
# Magical rubbish to teach make what commas and spaces are.
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
COMMA := $(EMPTY),$(EMPTY)
LINUX_ARCH:=amd64 arm arm64 ppc64le s390x
PLATFORMS:=$(subst $(SPACE),$(COMMA),$(foreach arch,$(LINUX_ARCH),linux/$(arch)))
GOPATH := $(GOBUILDDIR)
GOVERSION := 1.10.0-alpine
ifndef GOOS
GOOS := linux
endif
ifndef GOARCH
GOARCH := amd64
endif
BINNAME := $(PROJECT)-$(GOOS)-$(GOARCH)
BIN := $(BINDIR)/$(BINNAME)
ifndef DOCKERIMAGE
DOCKERIMAGE := $(PROJECT):dev
endif
SOURCES := $(shell find $(SRCDIR) -name '*.go')
.PHONY: all clean deps build
all: build-archs
build: $(BIN)
local:
@${MAKE} -B GOOS=$(shell go env GOHOSTOS) GOARCH=$(shell go env GOHOSTARCH) build
@ln -sf bin/$(PROJECT)-$(shell go env GOHOSTOS)-$(shell go env GOHOSTARCH) $(PROJECT)
build-archs:
for arch in $(LINUX_ARCH); do \
$(MAKE) -B DOCKERIMAGE=$(DOCKERIMAGE) GOARCH=$$arch docker ;\
done
clean:
rm -Rf bin $(GOBUILDDIR)
deps:
@${MAKE} -B -s $(GOBUILDDIR)
$(GOBUILDDIR):
@mkdir -p $(ORGDIR)
@rm -f $(REPODIR) && ln -s ../../../.. $(REPODIR)
@GOPATH=$(GOPATH) pulsar go flatten -V $(VENDORDIR)
update-vendor:
@rm -Rf $(VENDORDIR)
@pulsar go vendor -V $(VENDORDIR) \
github.com/coreos/etcd/client \
github.com/dchest/uniuri \
github.com/dustin/go-humanize \
github.com/giantswarm/retry-go \
github.com/hashicorp/consul/api \
github.com/hashicorp/go-rootcerts \
github.com/hashicorp/hcl \
github.com/hashicorp/vault/api \
github.com/juju/errgo \
github.com/kardianos/osext \
github.com/kr/pretty \
github.com/mitchellh/go-homedir \
github.com/mitchellh/mapstructure \
github.com/op/go-logging \
github.com/ryanuber/columnize \
github.com/spf13/cobra \
github.com/spf13/pflag \
github.com/YakLabs/k8s-client
$(BIN): $(GOBUILDDIR) $(SOURCES)
@mkdir -p $(BINDIR)
docker run \
--rm \
-v $(ROOTDIR):/usr/code \
-e GOPATH=/usr/code/.gobuild \
-e GOOS=$(GOOS) \
-e GOARCH=$(GOARCH) \
-e CGO_ENABLED=0 \
-w /usr/code/ \
golang:$(GOVERSION) \
go build -installsuffix netgo -tags netgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o /usr/code/bin/$(BINNAME) $(REPOPATH)
docker: $(BIN)
docker build --build-arg arch=$(GOARCH) -t $(DOCKERIMAGE)-$(GOARCH) -f Dockerfile.build .
ifdef PUSHIMAGES
docker push $(DOCKERIMAGE)-$(GOARCH)
endif
$(MANIFESTTOOL):
go get github.com/estesp/manifest-tool
.PHONY: push-manifest
push-manifest: $(MANIFESTTOOL)
echo Pushing image for platforms $(PLATFORMS)
@$(MANIFESTTOOL) $(MANIFESTAUTH) push from-args \
--platforms $(PLATFORMS) \
--template $(DOCKERIMAGE)-ARCH \
--target $(DOCKERIMAGE)
.PHONY: release
release:
@${MAKE} -B PUSHIMAGES=1 DOCKERIMAGE=pulcy/$(shell pulsar docker-tag) all push-manifest