-
Notifications
You must be signed in to change notification settings - Fork 37
/
Makefile
217 lines (182 loc) · 7.35 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
OS_TYPE=$(shell echo `uname`| tr '[A-Z]' '[a-z]')
ifeq ($(OS_TYPE),darwin)
OS := osx
else
OS := linux
endif
# version 11.4 or later of go
HAS_REQUIRED_GO := $(shell go version | grep -E 'go[2-9]|go1.1[2-9]|go1.11.[4-9]')
# version 9 or later of node
HAS_REQUIRED_NODE := $(shell node --version | grep -E 'v9|v[0-9]{2}')
PACKAGE_NAME = github.com/lyraproj/lyra
LDFLAGS += -X "$(PACKAGE_NAME)/pkg/version.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S %Z')"
LDFLAGS += -X "$(PACKAGE_NAME)/pkg/version.BuildTag=$(shell git describe --all --exact-match `git rev-parse HEAD` | grep tags | sed 's/tags\///')"
LDFLAGS += -X "$(PACKAGE_NAME)/pkg/version.BuildSHA=$(shell git rev-parse --short HEAD)"
BUILDARGS = GO111MODULE=on
GO_PLUGINS := $(subst cmd/,,$(wildcard cmd/goplugin-*))
TERRAFORM_PLUGINS := \
aws \
azurerm \
github \
google \
kubernetes
PHONY+= default
default: LINTFLAGS = --fast
default: everything
PHONY+= all
all: LDFLAGS += -s -w # Strip debug information
all: TESTFLAGS = --race
all: everything
PHONY+= everything
everything: check-mods clean lint test lyra plugins generate smoke-test
PHONY+= docker-build
docker-build: BUILDARGS += CGO_ENABLED=0 GOOS=linux
docker-build: LDFLAGS += -extldflags "-static"
docker-build: lyra plugins
PHONY+= shrink
shrink:
for f in build/*; do \
upx $$f; \
done;
PHONY+= plugins
plugins: check-mods identity puppet-dsl yaml-dsl lyra-plugins terraform-plugins
PHONY+= lyra-plugins
lyra-plugins: check-mods
@$(foreach plugin,$(GO_PLUGINS),$(call build,goplugins/$(subst goplugin-,,$(plugin)),cmd/$(plugin)/main.go);)
PHONY+= terraform-plugins
terraform-plugins: check-mods
@$(foreach plugin,$(TERRAFORM_PLUGINS),$(call build,goplugins/$(plugin),github.com/lyraproj/terraform-bridge/cmd/goplugin-$(plugin));)
PHONY+= identity
identity:
@$(call build,goplugins/identity,github.com/lyraproj/identity/main)
PHONY+= puppet-dsl
puppet-dsl:
@$(call build,goplugins/puppet,github.com/lyraproj/puppet-workflow/main)
PHONY+= yaml-dsl
yaml-dsl:
@$(call build,goplugins/yaml,github.com/lyraproj/yaml-workflow/main)
PHONY+= lyra
lyra: check-mods
@$(call build,bin/lyra,cmd/lyra/main.go)
test: yaml-dsl
@echo "🔘 Running unit tests... (`date '+%H:%M:%S'`)"
$(BUILDARGS) go test $(TESTFLAGS) github.com/lyraproj/lyra/...
PHONY+= clean
clean:
@echo "🔘 Cleaning build dir..."
@rm -rf build
@echo "🔘 Cleaning ts dist..."
@rm -rf examples/ts-samples/dist
@rm -rf examples/ts-samples/src/types
@echo "🔘 Cleaning foobernetes state..."
@rm -f deployment.json*
# This is not run as a pre-commit hook unless configured locally using .git/hooks
PHONY+= pre-commit
pre-commit: format tidy lint
# Run go mod tidy and check go.sum is unchanged
PHONY+= tidy
tidy:
@echo "🔘 Checking that go mod tidy does not make a change..."
@cp go.sum go.sum.bak
@go mod tidy
@diff go.sum go.sum.bak || (echo "🔴 go mod tidy would make a change, exiting"; exit 1)
@echo "✅ Checking go mod tidy complete"
# Format go code and error if any changes are made
PHONY+= format
format:
@echo "🔘 Checking that go fmt does not make any changes..."
@test -z $$(go fmt ./...) || (echo "🔴 go fmt would make a change, exiting"; exit 1)
@echo "✅ Checking go fmt complete"
PHONY+= lint
lint: $(GOPATH)/bin/golangci-lint
@$(call checklint,pkg/...)
@$(call checklint,cmd/lyra/...)
@$(foreach plugin,$(GO_PLUGINS),$(call checklint,cmd/$(plugin)/...);)
PHONY+= generate
generate:
@echo "🔘 Generating Puppet types ... (`date '+%H:%M:%S'`)"
@build/bin/lyra generate -t build/types puppet
PHONY+= dist-release
dist-release:
@if [ "$(OS)" != "linux" ]; \
then \
echo ""; \
echo "🔴 dist-release target only supported on linux (Travis CI)"; \
exit 1; \
fi
echo "🔘 Deploying release to Github..."
for f in build/*; do \
echo " - $$f"; \
tar czf $$f.tar.gz $$f; \
sha256sum $$f.tar.gz | awk '{ print $1 }' > $$f.tar.gz.sha256 ; \
done;
# Recursion note: this target is to build a container on a host OS.
# The Dockerfile will then run `make docker-build` *inside* the container
PHONY+= docker
docker:
@echo "🔘 Building docker container (`date '+%H:%M:%S'`)"
@docker build --tag lyraproj/lyra .
@echo "✅ Successfully dockerized (`date '+%H:%M:%S'`)"
PHONY+= check-mods
check-mods:
@echo "🔘 Ensuring go version is 1.11.4 or later (`date '+%H:%M:%S'`)"
@if [ "$(HAS_REQUIRED_GO)" = "" ]; \
then \
echo "🔴 must be running Go version 1.11.4 or later. Please upgrade and run go clean -modcache"; \
exit 1; \
fi
@echo "✅ Go version is sufficient (`date '+%H:%M:%S'`)"
@echo "🔘 Ensuring go mod is available and turned on (`date '+%H:%M:%S'`)"
@GO111MODULE=on go mod download || (echo "🔴 The command 'GO111MODULE=on go mod download' did not return zero exit code (exit code was $$?)"; exit 1)
@echo "✅ Go mod is available (`date '+%H:%M:%S'`)"
PHONY+= check-node
check-node:
@echo "🔘 Ensuring node version is 9.0.0 or later (`date '+%H:%M:%S'`)"
@if [ "$(HAS_REQUIRED_NODE)" = "" ]; \
then \
echo "🔴 must be running Node version 9.0.0 or later. Exiting"; \
exit 1; \
fi
@echo "✅ Node version is sufficient (`date '+%H:%M:%S'`)"
PHONY+= smoke-test
smoke-test: lyra identity puppet-dsl yaml-dsl lyra-plugins generate
@echo "🔘 Running a smoke test with 'foobernetes' workflow"
@rm -f deployment.json*
@build/bin/lyra delete foobernetes || (echo "Failed deleting 'foobernetes' workflow: exit code $$?"; exit 1)
@build/bin/lyra apply foobernetes || (echo "Failed applying 'foobernetes' workflow the first time: exit code $$?"; exit 1)
@sort deployment.json|grep -v "[0-9]\{8,\}" > deployment.json.sorted
@cp deployment.json.sorted deployment.json.sorted.original
@sort tests/expected/deployment.json|grep -v "[0-9]\{8,\}" > deployment.json.sorted.expected
@diff deployment.json.sorted.expected deployment.json.sorted || (echo "First run results are not as expected"; exit 1)
@build/bin/lyra apply foobernetes || (echo "Failed applying 'foobernetes' workflow the second time: exit code $$?"; exit 1)
@sort deployment.json|grep -v "[0-9]\{8,\}" > deployment.json.sorted
@diff deployment.json.sorted.original deployment.json.sorted || (echo "Second run results are not as expected"; exit 1)
@build/bin/lyra delete foobernetes || (echo "Failed deleting 'foobernetes' workflow: exit code $$?"; exit 1)
@diff tests/expected/deployment.empty.json deployment.json || (echo "Final deletion run results are not as expected"; exit 1)
@rm deployment.json*
smoke-test-ts: check-node generate-ts
@build/bin/lyra apply foobernetes_ts || (echo "Failed apply typescript foobernetes_ts $$?"; exit 1)
smoke-test-go-wf:
build/bin/lyra apply imperative_go
build/bin/lyra apply declarative_go
generate-ts:
@build/bin/lyra generate typescript --target-directory examples/ts-samples/src/types
@cd examples/ts-samples && npm install
define build
echo "🔘 Building - $(1) (`date '+%H:%M:%S'`)"
mkdir -p build/
$(BUILDARGS) go build -ldflags '$(LDFLAGS)' -o build/$(1) $(2)
echo "✅ Build complete - $(1) (`date '+%H:%M:%S'`)"
endef
define checklint
echo "🔘 Linting $(1) (`date '+%H:%M:%S'`)"
lint=`$(BUILDARGS) golangci-lint run $(LINTFLAGS) $(1)`; \
if [ "$$lint" != "" ]; \
then echo "🔴 Lint found"; echo "$$lint"; exit 1;\
else echo "✅ Lint-free (`date '+%H:%M:%S'`)"; \
fi
endef
$(GOPATH)/bin/golangci-lint:
@echo "🔘 Installing golangci-lint... (`date '+%H:%M:%S'`)"
@GO111MODULE=off go get github.com/golangci/golangci-lint/cmd/golangci-lint
.PHONY: $(PHONY)