-
Notifications
You must be signed in to change notification settings - Fork 94
/
Makefile
142 lines (113 loc) · 5.08 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
BINARY_NAME ?= monaco
VERSION ?= 2.x
RELEASES = $(BINARY_NAME)-windows-amd64.exe $(BINARY_NAME)-windows-386.exe $(BINARY_NAME)-linux-arm64 $(BINARY_NAME)-linux-amd64 $(BINARY_NAME)-linux-386 $(BINARY_NAME)-darwin-amd64 $(BINARY_NAME)-darwin-arm64
.PHONY: lint format mocks build install clean test integration-test integration-test-v1 test-package default add-license-headers compile build-release $(RELEASES) docker-container sign-image install-ko
default: build
lint:
@go install github.com/google/[email protected]
ifeq ($(OS),Windows_NT)
@.\tools\check-format.cmd
else
@go install github.com/google/addlicense@v1
@sh ./tools/check-format.sh
@sh ./tools/check-license-headers.sh
@go mod tidy
endif
format:
@gofmt -w .
add-license-headers:
ifeq ($(OS),Windows_NT)
@echo "This is currently not supported on windows"
@exit 1
else
@go install github.com/google/[email protected]
@sh ./tools/add-missing-license-headers.sh
endif
mocks:
@echo Installing mockgen
@go install go.uber.org/mock/[email protected]
@echo "Generating mocks"
@go generate ./...
vet: mocks
@echo "Vetting files"
@go vet -tags '!unit' ./...
check:
@echo "Static code analysis"
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1
@golangci-lint run ./...
compile: mocks
@echo "Compiling sources..."
@go build -tags "unit integration nightly cleanup integration_v1 download_restore" ./...
@echo "Compiling tests..."
@go test -tags "unit integration nightly cleanup integration_v1 download_restore" -run "NON_EXISTENT_TEST_TO_ENSURE_NOTHING_RUNS_BUT_ALL_COMPILE" ./...
build: mocks
@echo "Building $(BINARY_NAME)..."
@CGO_ENABLED=0 go build -a -tags netgo -ldflags '-w -extldflags "-static"' -o ./bin/${BINARY_NAME} ./cmd/monaco
build-release: clean $(RELEASES)
@echo Release build $(BINARY_NAME) $(VERSION)
#argument - splits the name of command to array and return required element
argument = $(word $1, $(subst -,$(empty) $(empty), $(subst .exe,$(empty) $(empty) , $2)))
# OUTPUT - name (and path) of output binaries
$(RELEASES):
@# Do not build Windows binaries with Go native DNS resolver
$(eval GO_TAGS := $(shell if [ "$(call argument, 2, $@)" != "windows" ]; then echo "-tags netgo"; fi))
$(eval OUTPUT ?= ./build/$@)
@echo Building binaries for $@...
@GOOS=$(call argument, 2, $@) GOARCH=$(call argument, 3, $@) CGO_ENABLED=0 go build -a $(GO_TAGS) -ldflags '-X github.com/dynatrace/dynatrace-configuration-as-code/v2/pkg/version.MonitoringAsCode=$(VERSION) -w -extldflags "-static"' -o $(OUTPUT) ./cmd/monaco
install:
@echo "Installing $(BINARY_NAME)..."
@CGO_ENABLED=0 go install -a -tags netgo -ldflags '-X github.com/dynatrace/dynatrace-configuration-as-code/v2/pkg/version.MonitoringAsCode=$(VERSION) -w -extldflags "-static"' ./cmd/monaco
clean:
@echo "Removing $(BINARY_NAME), bin/ and /build ..."
ifeq ($(OS),Windows_NT)
@echo "Windows"
@if exist bin rd /S /Q bin
@echo "Windows 2"
@if exist bin rd /S /Q build
else
@echo "Linux"
@rm -rf bin/
@rm -rf build/
endif
install-gotestsum:
@go install gotest.tools/[email protected]
test: mocks install-gotestsum
@echo "Testing $(BINARY_NAME)..."
@gotestsum ${testopts} --format testdox -- -tags=unit -v -race ./...
integration-test: mocks install-gotestsum
@gotestsum ${testopts} --format testdox -- -tags=integration -timeout=30m -v -race ./cmd/monaco/integrationtest/v2
integration-test-v1: mocks install-gotestsum
@gotestsum ${testopts} --format testdox -- -tags=integration_v1 -timeout=30m -v -race ./cmd/monaco/integrationtest/v1
download-restore-test: mocks install-gotestsum
@gotestsum ${testopts} --format testdox -- -tags=download_restore -timeout=30m -v -race ./...
account-management-test: mocks install-gotestsum
@gotestsum ${testopts} --format testdox -- -tags=integration -timeout=30m -v -race ./cmd/monaco/integrationtest/account
clean-environments:
@MONACO_ENABLE_DANGEROUS_COMMANDS=1 go run ./cmd/monaco purge cmd/monaco/integrationtest/v2/test-resources/test_environments_manifest.yaml
nightly-test:mocks install-gotestsum
@gotestsum ${testopts} --format testdox -- -tags=nightly -timeout=240m -v -race ./...
# Build and Test a single package supplied via pgk variable, without using test cache
# Run as e.g. make test-package pkg=project
pkg=...
test-package: mocks lint install-gotestsum
@echo "Testing ${pkg}..."
@gotestsum -- -tags=unit -count=1 -v -race ./pkg/${pkg}
update-dependencies:
@echo Update go dependencies
@go get -u ./...
@go mod tidy
install-ko:
@go install github.com/unseenwizzard/ko@9dfd0d7d
#TAG - specify tag value. The main purpose is to define public tag during a release build.
TAGS ?= $(VERSION)
CONTAINER_NAME ?= dynatrace-configuration-as-code
REPO_PATH ?= ko.local
IMAGE_PATH ?= $(REPO_PATH)/$(CONTAINER_NAME)
.PHONY: docker-container
docker-container: install-ko
@echo Building docker container...
KO_DOCKER_REPO=$(IMAGE_PATH) VERSION=$(VERSION) ko build --bare --sbom=none --tags=$(TAGS) ./cmd/monaco
sign-verify-image:
@go install github.com/sigstore/cosign/v2/cmd/[email protected]
COSIGN_PASSWORD=$(COSIGN_PASSWORD) cosign sign --key env://cosign_key $(FULL_IMAGE_NAME) -y
cosign verify --key env://cosign_pub $(FULL_IMAGE_NAME)