forked from eclipse-iofog/iofogctl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
184 lines (159 loc) · 6.83 KB
/
Copy pathMakefile
File metadata and controls
184 lines (159 loc) · 6.83 KB
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
SHELL = /bin/bash
OS = $(shell uname -s | tr '[:upper:]' '[:lower:]')
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
# Build variables
include versions.mk
# Build variables
FLAVOR ?= iofog
BINARY_NAME ?= iofogctl
BUILD_DIR ?= bin
PACKAGE_DIR ?= cmd/iofogctl
GOTAGS ?= containers_image_openpgp,exclude_graphdriver_btrfs
export CGO_ENABLED=1
LATEST_TAG = $(shell git for-each-ref refs/tags --sort=-taggerdate --format='%(refname)' | tail -n1 | sed "s|refs/tags/||")
MAJOR ?= $(shell echo "$(LATEST_TAG)" | tr -d "v" | sed "s|-.*||" | sed -E "s|(.)\..\..|\1|g")
MINOR ?= $(shell echo "$(LATEST_TAG)" | tr -d "v" | sed "s|-.*||" | sed -E "s|.\.(.)\..|\1|g")
PATCH ?= $(shell echo "$(LATEST_TAG)" | tr -d "v" | sed "s|-.*||" | sed -E "s|.\..\.(.)|\1|g")
TAG_SUFFIX = $(shell echo "$(LATEST_TAG)" | sed "s|v$(MAJOR)\.$(MINOR)\.$(PATCH)||")
DEV_SUFFIX = -dev
SUFFIX ?= $(shell [ -z "$(shell git tag --points-at HEAD)" ] && echo "$(DEV_SUFFIX)" || echo "$(TAG_SUFFIX)")
VERSION ?= $(MAJOR).$(MINOR).$(PATCH)$(SUFFIX)
COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null)
BUILD_DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
PREFIX = github.com/eclipse-iofog/iofogctl/pkg/util
ifeq ($(FLAVOR),datasance)
CLI_BINARY_NAME = potctl
CLI_CRD_GROUP = datasance.com
CLI_API_VERSION = datasance.com/v3
CLI_CP_CR_NAME = pot
IMAGE_REGISTRY = ghcr.io/datasance
CLI_DOCS_URL = https://docs.datasance.com
PACKAGE_REPO_BASE = https://downloads.datasance.com
OCI_SOURCE_REPO = https://github.com/Datasance/potctl
EDGELET_RELEASE_BASE = https://github.com/Datasance/edgelet/releases/download
EDGELET_GITHUB_REPO = Datasance/edgelet
else
CLI_BINARY_NAME = iofogctl
CLI_CRD_GROUP = iofog.org
CLI_API_VERSION = iofog.org/v3
CLI_CP_CR_NAME = iofog
IMAGE_REGISTRY = ghcr.io/eclipse-iofog
CLI_DOCS_URL = https://iofog.org
PACKAGE_REPO_BASE = https://iofog.datasance.com
OCI_SOURCE_REPO = https://github.com/eclipse-iofog/iofogctl
EDGELET_RELEASE_BASE = https://github.com/eclipse-iofog/edgelet/releases/download
EDGELET_GITHUB_REPO = eclipse-iofog/edgelet
endif
LDFLAGS += -X $(PREFIX).versionNumber=$(VERSION) -X $(PREFIX).commit=$(COMMIT) -X $(PREFIX).date=$(BUILD_DATE) -X $(PREFIX).platform=$(GOOS)/$(GOARCH)
LDFLAGS += -X $(PREFIX).cliBinaryName=$(CLI_BINARY_NAME)
LDFLAGS += -X $(PREFIX).cliCrdGroup=$(CLI_CRD_GROUP)
LDFLAGS += -X $(PREFIX).cliApiVersion=$(CLI_API_VERSION)
LDFLAGS += -X $(PREFIX).cliCpCrName=$(CLI_CP_CR_NAME)
LDFLAGS += -X $(PREFIX).imageRegistry=$(IMAGE_REGISTRY)
LDFLAGS += -X $(PREFIX).cliDocsUrl=$(CLI_DOCS_URL)
LDFLAGS += -X $(PREFIX).packageRepoBase=$(PACKAGE_REPO_BASE)
LDFLAGS += -X $(PREFIX).ociSourceRepo=$(OCI_SOURCE_REPO)
LDFLAGS += -X $(PREFIX).operatorTag=$(OPERATOR_VERSION)
LDFLAGS += -X $(PREFIX).routerTag=$(ROUTER_VERSION)
LDFLAGS += -X $(PREFIX).controllerTag=$(CONTROLLER_VERSION)
LDFLAGS += -X $(PREFIX).natsTag=$(NATS_VERSION)
LDFLAGS += -X $(PREFIX).edgeletTag=$(EDGELET_IMAGE_TAG)
LDFLAGS += -X $(PREFIX).controllerVersion=$(CONTROLLER_VERSION)
LDFLAGS += -X $(PREFIX).edgeletVersion=$(EDGELET_IMAGE_TAG)
LDFLAGS += -X $(PREFIX).edgeletReleaseBase=$(EDGELET_RELEASE_BASE)
LDFLAGS += -X $(PREFIX).edgeletGitHubRepo=$(EDGELET_GITHUB_REPO)
LDFLAGS += -X $(PREFIX).edgeletBinaryVersion=$(EDGELET_BINARY_VERSION)
LDFLAGS += -X $(PREFIX).debuggerTag=latest
GOLANGCI_LINT_VERSION ?= v2.12.2
GOVULNCHECK_VERSION ?= v1.1.4
GOSEC_SCOPE ?= ./cmd/... ./internal/... ./pkg/...
TEST_RESULTS ?= TEST-iofogctl.txt
TEST_REPORT ?= TEST-iofogctl.xml
.PHONY: all
all: bootstrap build install ## Bootstrap env, build and install binary
.PHONY: bootstrap
bootstrap: ## Bootstrap environment
@cp gitHooks/* .git/hooks/
@script/bootstrap.sh
.PHONY: verify-gpgme
verify-gpgme:
@if ! pkg-config --exists gpgme; then \
echo "Missing gpgme development headers. Install via 'brew install gpgme' or 'sudo apt-get install libgpgme-dev'."; \
exit 1; \
fi
.PHONY: potctl
potctl: ## Build potctl binary
@$(MAKE) FLAVOR=datasance BINARY_NAME=potctl PACKAGE_DIR=cmd/potctl build
.PHONY: iofogctl
iofogctl: ## Build iofogctl binary
@$(MAKE) FLAVOR=iofog BINARY_NAME=iofogctl PACKAGE_DIR=cmd/iofogctl build
.PHONY: build
build: GOARGS += -tags "$(GOTAGS)" -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)
build: fmt ## Build the binary
@go build -v $(GOARGS) $(PACKAGE_DIR)/main.go
.PHONY: install
install: ## Install the binary
@GOBIN=$$(go env GOPATH)/bin go install -tags "$(GOTAGS)" -ldflags "$(LDFLAGS)" ./$(PACKAGE_DIR)/
.PHONY: lint
lint: golangci-lint fmt ## Lint the source
@$(GOLANGCI_LINT) run --timeout 5m0s --build-tags "$(GOTAGS)"
golangci-lint: ## Install golangci
ifeq (, $(shell which golangci-lint))
@{ \
set -e ;\
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) ;\
}
GOLANGCI_LINT=$(GOBIN)/golangci-lint
else
GOLANGCI_LINT=$(shell which golangci-lint)
endif
.PHONY: fmt
fmt: ## Format the source
@gofmt -s -w .
.PHONY: test-unit
test-unit: ## Run unit tests (short mode)
go test ./internal/... ./pkg/... -short -count=1 -tags "$(GOTAGS)" -ldflags "$(LDFLAGS)"
.PHONY: smoke
smoke: build ## Smoke test: version and help
@$(BUILD_DIR)/$(BINARY_NAME) version
@$(BUILD_DIR)/$(BINARY_NAME) --help
@$(BUILD_DIR)/$(BINARY_NAME) deploy --help
.PHONY: grep-gates
grep-gates: ## Fail on hardcoded flavor strings in internal/
@chmod +x scripts/ci/grep-gates.sh
@scripts/ci/grep-gates.sh
.PHONY: vulncheck
vulncheck: ## Run govulncheck on module paths
@if ! command -v govulncheck >/dev/null 2>&1; then \
go install golang.org/x/vuln/cmd/govulncheck@$(GOVULNCHECK_VERSION); \
fi
@chmod +x scripts/vulncheck.sh
@GOTAGS="$(GOTAGS)" scripts/vulncheck.sh
@go mod verify
.PHONY: security-code
security-code: ## Run gosec static analysis
@if ! command -v gosec >/dev/null 2>&1; then \
go install github.com/securego/gosec/v2/cmd/gosec@latest; \
fi
@gosec -exclude-dir=build $(GOSEC_SCOPE)
.PHONY: test
test: ## Run unit tests
mkdir -p $(REPORTS_DIR)
rm -f $(REPORTS_DIR)/*
set -o pipefail; find ./internal ./pkg -name '*_test.go' -not -path vendor | sed -E "s|(/.*/).*_test.go|\1|g" | xargs -n1 go test -tags "$(GOTAGS)" -ldflags "$(LDFLAGS)" -coverprofile=$(REPORTS_DIR)/coverage.txt -v -parallel 1 2>&1 | tee $(REPORTS_DIR)/$(TEST_RESULTS)
cat $(REPORTS_DIR)/$(TEST_RESULTS) | go-junit-report -set-exit-code > $(REPORTS_DIR)/$(TEST_REPORT)
.PHONY: list
list: ## List all make targets
@$(MAKE) -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort
.PHONY: clean
clean: ## Clean working env
rm -rf $(BUILD_DIR)/
rm -rf $(REPORTS_DIR)
.PHONY: help
.DEFAULT_GOAL := help
help: ## Get help output
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
# Variable outputting/exporting rules
var-%: ; @echo $($*)
varexport-%: ; @echo $*=$($*)