-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
100 lines (79 loc) · 3.53 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
MIXIN = helm3
PKG = github.com/MChorfa/porter-$(MIXIN)
SHELL = bash
GO = GO111MODULE=on go
PORTER_HOME ?= $(HOME)/.porter
COMMIT ?= $(shell git rev-parse --short HEAD)
VERSION ?= $(shell git describe --tags 2> /dev/null || echo v0)
PERMALINK ?= $(shell git describe --tags --exact-match &> /dev/null && echo latest || echo canary)
LDFLAGS = -w -X $(PKG)/pkg.Version=$(VERSION) -X $(PKG)/pkg.Commit=$(COMMIT)
XBUILD = CGO_ENABLED=0 $(GO) build -a -tags netgo -ldflags '$(LDFLAGS)'
BINDIR = bin/mixins/$(MIXIN)
CLIENT_PLATFORM ?= $(shell go env GOOS)
CLIENT_ARCH ?= $(shell go env GOARCH)
RUNTIME_PLATFORM ?= linux
RUNTIME_ARCH ?= amd64
SUPPORTED_PLATFORMS = linux darwin windows
SUPPORTED_ARCHES = amd64
ifeq ($(CLIENT_PLATFORM),windows)
FILE_EXT=.exe
else ifeq ($(RUNTIME_PLATFORM),windows)
FILE_EXT=.exe
else
FILE_EXT=
endif
REGISTRY ?= $(USER)
.PHONY: build
build: build-client build-runtime
build-runtime:
mkdir -p $(BINDIR)
GOARCH=$(RUNTIME_ARCH) GOOS=$(RUNTIME_PLATFORM) $(GO) build -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(MIXIN)-runtime$(FILE_EXT) ./cmd/$(MIXIN)
build-client:
mkdir -p $(BINDIR)
$(GO) build -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(MIXIN)$(FILE_EXT) ./cmd/$(MIXIN)
xbuild-all:
$(foreach OS, $(SUPPORTED_PLATFORMS), \
$(foreach ARCH, $(SUPPORTED_ARCHES), \
$(MAKE) $(MAKE_OPTS) CLIENT_PLATFORM=$(OS) CLIENT_ARCH=$(ARCH) MIXIN=$(MIXIN) xbuild; \
))
# Buid for linux arm64
$(MAKE) $(MAKE_OPTS) CLIENT_PLATFORM=linux CLIENT_ARCH=arm64 MIXIN=$(MIXIN) xbuild;
xbuild: $(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT)
$(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT):
mkdir -p $(dir $@)
GOOS=$(CLIENT_PLATFORM) GOARCH=$(CLIENT_ARCH) $(XBUILD) -o $@ ./cmd/$(MIXIN)
test: test-unit
$(BINDIR)/$(MIXIN)$(FILE_EXT) version
test-unit: build
$(GO) test ./...
test-integration: xbuild
# Test against the cross-built client binary that we will publish
cp $(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT) $(BINDIR)/$(MIXIN)$(FILE_EXT)
$(GO) test -tags=integration ./tests/...
publish: bin/porter$(FILE_EXT)
# The following demonstrates how to publish a mixin. As an example, we show how to publish to azure.
# The porter mixins feed generate command is used to build an ATOM feed for sharing mixins once published
# AZURE_STORAGE_CONNECTION_STRING will be used for auth in the following commands
# if [[ "$(PERMALINK)" == "latest" ]]; then \
# az storage blob upload-batch -d porter/mixins/$(MIXIN)/$(VERSION) -s $(BINDIR)/$(VERSION); \
# az storage blob upload-batch -d porter/mixins/$(MIXIN)/$(PERMALINK) -s $(BINDIR)/$(VERSION); \
# else \
# mv $(BINDIR)/$(VERSION) $(BINDIR)/$(PERMALINK); \
# az storage blob upload-batch -d porter/mixins/$(MIXIN)/$(PERMALINK) -s $(BINDIR)/$(PERMALINK); \
# fi
# 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
cp bin/atom.xml docs/
#az storage blob upload -c porter -n atom.xml -f bin/atom.xml
bin/porter$(FILE_EXT):
curl -fsSLo bin/porter$(FILE_EXT) https://cdn.porter.sh/canary/porter-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT)
chmod +x bin/porter$(FILE_EXT)
install:
# @porter mixin uninstall $(MIXIN)
mkdir -p $(PORTER_HOME)/mixins/$(MIXIN)/runtimes
install $(BINDIR)/$(MIXIN)$(FILE_EXT) $(PORTER_HOME)/mixins/$(MIXIN)/$(MIXIN)$(FILE_EXT)
install $(BINDIR)/$(MIXIN)-runtime$(FILE_EXT) $(PORTER_HOME)/mixins/$(MIXIN)/runtimes/$(MIXIN)-runtime$(FILE_EXT)
# @porter mixin list
clean:
-rm -fr bin/