forked from getporter/porter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
233 lines (178 loc) · 6.48 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
SHELL = bash
# --no-print-directory avoids verbose logging when invoking targets that utilize sub-makes
MAKE_OPTS ?= --no-print-directory
VERSION ?= $(shell git describe --tags 2> /dev/null || echo v0)
PERMALINK ?= $(shell git describe --tags --exact-match &> /dev/null && echo latest || echo canary)
export PORTER_HOME = ${CURDIR}/bin
CLIENT_PLATFORM = $(shell go env GOOS)
CLIENT_ARCH = $(shell go env GOARCH)
CLIENT_GOPATH = $(shell go env GOPATH)
RUNTIME_PLATFORM = linux
RUNTIME_ARCH = amd64
BASEURL_FLAG ?=
GO = GO111MODULE=on go
# Add ~/go/bin to PATH, works for everything _except_ shell commands
HAS_GOBIN_IN_PATH := $(shell re='(:|^)$(CLIENT_GOPATH)/bin/?(:|$$)'; if [[ "$${PATH}" =~ $${re} ]];then echo $${GOPATH}/bin;fi)
ifndef HAS_GOBIN_IN_PATH
export PATH := ${CLIENT_GOPATH}/bin:${PATH}
endif
ifeq ($(CLIENT_PLATFORM),windows)
FILE_EXT=.exe
else ifeq ($(RUNTIME_PLATFORM),windows)
FILE_EXT=.exe
else
FILE_EXT=
endif
INT_MIXINS = exec
.PHONY: build
build: build-porter docs-gen build-mixins clean-packr get-mixins
build-porter: generate
$(MAKE) $(MAKE_OPTS) build MIXIN=porter -f mixin.mk BINDIR=bin
build-porter-client: generate
$(MAKE) $(MAKE_OPTS) build-client MIXIN=porter -f mixin.mk BINDIR=bin
$(MAKE) $(MAKE_OPTS) clean-packr
build-mixins: $(addprefix build-mixin-,$(INT_MIXINS))
build-mixin-%: generate
$(MAKE) $(MAKE_OPTS) build MIXIN=$* -f mixin.mk
generate: packr2
$(GO) mod tidy
$(GO) generate ./...
HAS_PACKR2 := $(shell command -v packr2)
HAS_GOBIN_IN_PATH := $(shell re='(:|^)$(CLIENT_GOPATH)/bin/?(:|$$)'; if [[ "$${PATH}" =~ $${re} ]];then echo $${GOPATH}/bin;fi)
packr2:
ifndef HAS_PACKR2
ifndef HAS_GOBIN_IN_PATH
$(error "$(CLIENT_GOPATH)/bin is not in path and packr2 is not installed. Install packr2 or add "$(CLIENT_GOPATH)/bin to your path")
endif
curl -SLo /tmp/packr.tar.gz https://github.com/gobuffalo/packr/releases/download/v2.6.0/packr_2.6.0_$(CLIENT_PLATFORM)_$(CLIENT_ARCH).tar.gz
cd /tmp && tar -xzf /tmp/packr.tar.gz
install /tmp/packr2 $(CLIENT_GOPATH)/bin/
endif
xbuild-all: xbuild-porter xbuild-mixins
xbuild-porter: generate
$(MAKE) $(MAKE_OPTS) xbuild-all MIXIN=porter -f mixin.mk BINDIR=bin
xbuild-mixins: $(addprefix xbuild-mixin-,$(INT_MIXINS))
xbuild-mixin-%: generate
$(MAKE) $(MAKE_OPTS) xbuild-all MIXIN=$* -f mixin.mk
get-mixins:
go run mage.go GetMixins
verify:
@echo 'verify does nothing for now but keeping it as a placeholder for a bit'
test: clean-last-testrun build test-unit test-integration teste2e
test-unit:
$(GO) test ./...
test-integration: clean-last-testrun start-local-docker-registry
$(GO) build -o bin/testplugin ./cmd/testplugin
PROJECT_ROOT=$(shell pwd) $(GO) test -timeout 30m -tags=integration ./...
teste2e:
go run mage.go teste2e
.PHONY: docs
docs:
hugo --source docs/ $(BASEURL_FLAG)
docs-gen:
$(GO) run --tags=docs ./cmd/porter docs
docs-preview: docs-stop-preview
@docker run -d -v $$PWD:/src -p 1313:1313 --name porter-docs -w /src/docs \
klakegg/hugo:0.78.1-ext-alpine server -D -F --noHTTPCache --watch --bind=0.0.0.0
# Wait for the documentation web server to finish rendering
@until docker logs porter-docs | grep -m 1 "Web Server is available"; do : ; done
@open "https://localhost:1313/docs/"
docs-stop-preview:
@docker rm -f porter-docs &> /dev/null || true
publish: publish-bin publish-mixins publish-images
publish-bin:
mkdir -p bin/$(VERSION)
VERSION=$(VERSION) PERMALINK=$(PERMALINK) ./scripts/prep-install-scripts.sh
# AZURE_STORAGE_CONNECTION_STRING will be used for auth in the following commands
if [[ "$(PERMALINK)" == "latest" ]]; then \
az storage blob upload-batch -d porter/$(VERSION) -s bin/$(VERSION); \
fi
az storage blob upload-batch -d porter/$(PERMALINK) -s bin/$(VERSION)
publish-mixins:
$(MAKE) $(MAKE_OPTS) publish MIXIN=exec -f mixin.mk
# Generate the mixin feed
az storage blob download -c porter -n atom.xml -f bin/atom.xml
bin/porter mixins feed generate -d bin/mixins -f bin/atom.xml -t build/atom-template.xml
az storage blob upload -c porter -n atom.xml -f bin/atom.xml
.PHONY: build-images
build-images:
VERSION=$(VERSION) PERMALINK=$(PERMALINK) ./scripts/build-images.sh
.PHONY: publish-images
publish-images: build-images
VERSION=$(VERSION) PERMALINK=$(PERMALINK) ./scripts/publish-images.sh
start-local-docker-registry:
@docker run -d -p 5000:5000 --name registry registry:2
stop-local-docker-registry:
@if $$(docker inspect registry > /dev/null 2>&1); then \
docker rm -f registry ; \
fi
# all-bundles loops through all items under the dir provided by the first argument
# and if the item is a sub-directory containing a porter.yaml file,
# runs the make target(s) provided by the second argument
define all-bundles
@for dir in $$(ls -1 $(1)); do \
if [[ -e "$(1)/$$dir/porter.yaml" ]]; then \
BUNDLE=$$dir make $(MAKE_OPTS) $(2) || exit $$? ; \
fi ; \
done
endef
EXAMPLES_DIR := examples
.PHONY: build-bundle
build-bundle:
ifndef BUNDLE
$(call all-bundles,$(EXAMPLES_DIR),build-bundle)
else
cd $(EXAMPLES_DIR)/$(BUNDLE) && ../../bin/porter build
endif
.PHONY: publish-bundle
publish-bundle:
ifndef BUNDLE
$(call all-bundles,$(EXAMPLES_DIR),publish-bundle)
else
cd $(EXAMPLES_DIR)/$(BUNDLE) && ../../bin/porter publish
endif
SCHEMA_VERSION := cnab-core-1.0.1
BUNDLE_SCHEMA := bundle.schema.json
DEFINITIONS_SCHEMA := definitions.schema.json
define fetch-schema
@curl -L --fail --silent --show-error -o /tmp/$(1) \
https://cnab.io/schema/$(SCHEMA_VERSION)/$(1)
endef
fetch-schemas: fetch-bundle-schema fetch-definitions-schema
fetch-bundle-schema:
$(call fetch-schema,$(BUNDLE_SCHEMA))
fetch-definitions-schema:
$(call fetch-schema,$(DEFINITIONS_SCHEMA))
HAS_AJV := $(shell command -v ajv)
ajv:
ifndef HAS_AJV
npm install -g [email protected]
endif
.PHONY: validate-bundle
validate-bundle: fetch-schemas ajv
ifndef BUNDLE
$(call all-bundles,$(EXAMPLES_DIR),validate-bundle)
else
cd $(EXAMPLES_DIR)/$(BUNDLE) && \
ajv test -s /tmp/$(BUNDLE_SCHEMA) -r /tmp/$(DEFINITIONS_SCHEMA) -d .cnab/bundle.json --valid
endif
install: install-porter install-mixins
install-porter:
mkdir -p $(HOME)/.porter
cp bin/porter $(HOME)/.porter/
cp -R bin/runtimes $(HOME)/.porter/
install-mixins:
cp -R bin/mixins $(HOME)/.porter/
setup-dco:
@scripts/setup-dco/setup.sh
clean: clean-mixins clean-last-testrun
clean-mixins:
-rm -fr bin/
clean-last-testrun: stop-local-docker-registry
-rm -fr cnab/ porter.yaml Dockerfile bundle.json
clean-packr: packr2
cd cmd/porter && packr2 clean
cd pkg/porter && packr2 clean
$(foreach MIXIN, $(INT_MIXINS), \
`cd pkg/$(MIXIN) && packr2 clean`; \
)