forked from brigadecore/brigade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
155 lines (128 loc) · 4.23 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# The Docker registry where images are pushed.
# Note that if you use an org (like on Quay and DockerHub), you should
# include that: quay.io/foo
DOCKER_REGISTRY ?= deis
DOCKER_BUILD_FLAGS :=
LDFLAGS :=
BINS = brigade-api brigade-controller brigade-github-gateway brigade-cr-gateway brigade-vacuum brig
IMAGES = brigade-api brigade-controller brigade-github-gateway brigade-cr-gateway brigade-vacuum brig brigade-worker git-sidecar
GIT_TAG = $(shell git describe --tags --always 2>/dev/null)
VERSION ?= ${GIT_TAG}
IMAGE_TAG ?= ${VERSION}
LDFLAGS += -X github.com/Azure/brigade/pkg/version.Version=$(VERSION)
CX_OSES = linux windows darwin
CX_ARCHS = amd64
# Build native binaries
.PHONY: build
build: $(BINS)
.PHONY: $(BINS)
$(BINS): vendor
go build -ldflags '$(LDFLAGS)' -o bin/$@ ./$@/cmd/$@
# Cross-compile for Docker+Linux
build-docker-bins: $(addsuffix -docker-bin,$(BINS))
%-docker-bin: vendor
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o ./$*/rootfs/$* ./$*/cmd/$*
# To use docker-build, you need to have Docker installed and configured. You should also set
# DOCKER_REGISTRY to your own personal registry if you are not pushing to the official upstream.
.PHONY: docker-build
docker-build: build-docker-bins
docker-build: $(addsuffix -image,$(IMAGES))
%-image:
docker build $(DOCKER_BUILD_FLAGS) -t $(DOCKER_REGISTRY)/$*:$(IMAGE_TAG) $*
# You must be logged into DOCKER_REGISTRY before you can push.
.PHONY: docker-push
docker-push: $(addsuffix -push,$(IMAGES))
%-push:
docker push $(DOCKER_REGISTRY)/$*:$(IMAGE_TAG)
# Cross-compile binaries for our CX targets.
# Mainly, this is for brig-cross-compile
%-cross-compile: vendor
@for os in $(CX_OSES); do \
echo "building $$os"; \
for arch in $(CX_ARCHS); do \
GOOS=$$os GOARCH=$$arch CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o ./bin/$*-$$os-$$arch ./$*/cmd/$*; \
done; \
if [ $$os == 'windows' ]; then \
mv ./bin/$*-$$os-$$arch ./bin/$*-$$os-$$arch.exe; \
fi; \
done
.PHONY: build-release
build-release: brig-cross-compile
.PRECIOUS: build-chart
.PHONY: build-chart
build-chart:
helm package -d docs/ ./charts/brigade
helm package -d docs/ ./charts/brigade-project
helm repo index docs/
# All non-functional tests
.PHONY: test
test: test-style
test: test-unit
test: test-js
test: test-chart
# Unit tests. Local only.
.PHONY: test-unit
test-unit: vendor
go test -v ./...
# Functional tests assume access to github.com
# To set this up in your local environment:
# - Make sure kubectl is pointed to the right cluster
# - Create "myvals.yaml" and set to something like this:
# project: "deis/empty-testbed"
# repository: "github.com/deis/empty-testbed"
# secret: "MySecret"
# - Run "helm install ./charts/brigade-project -f myvals.yaml
# - Run "make run" in one terminal
# - Run "make test-functional" in another terminal
#
# This will clone the github.com/deis/empty-testbed repo and run the brigade.js
# file found there.
# Test Repo is https://github.com/deis/empty-testbed
TEST_REPO_COMMIT = 589e15029e1e44dee48de4800daf1f78e64287c0
KUBECONFIG ?= ${HOME}/.kube/config
.PHONY: test-functional
test-functional: vendor
test-functional:
go test --tags integration ./tests -kubeconfig $(KUBECONFIG) $(TEST_REPO_COMMIT)
# JS test is local only
.PHONY: test-js
test-js: bootstrap-js
cd brigade-worker && yarn test
.PHONY: test-style
test-style:
gometalinter --config ./gometalinter.json ./...
.PHONY: test-chart
test-chart:
helm lint ./charts/*
.PHONY: format
format: format-go format-js
.PHONY: format-go
format-go:
go list -f '{{.Dir}}' ./... | xargs goimports -w -local github.com/Azure/brigade
.PHONY: format-js
format-js:
cd brigade-worker && yarn format
HAS_GOMETALINTER := $(shell command -v gometalinter;)
HAS_DEP := $(shell command -v dep;)
HAS_GIT := $(shell command -v git;)
HAS_YARN := $(shell command -v yarn;)
.PHONY: bootstrap-js
bootstrap-js:
ifndef HAS_YARN
$(error You must install yarn)
endif
cd brigade-worker && yarn install
vendor:
ifndef HAS_GIT
$(error You must install git)
endif
ifndef HAS_DEP
go get -u github.com/golang/dep/cmd/dep
endif
ifndef HAS_GOMETALINTER
go get -u github.com/alecthomas/gometalinter
gometalinter --install
endif
dep ensure
.PHONY: bootstrap
bootstrap: vendor