generated from edgexfoundry-holding/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
97 lines (77 loc) · 3.76 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
#
# Copyright (c) 2023 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
.PHONY: build tidy docker test clean vendor
# change the following boolean flag to enable or disable the Full RELRO (RELocation Read Only) for linux ELF (Executable and Linkable Format) binaries
ENABLE_FULL_RELRO=true
# change the following boolean flag to enable or disable PIE for linux binaries which is needed for ASLR (Address Space Layout Randomization) on Linux, the ASLR support on Windows is enabled by default
ENABLE_PIE=true
# VERSION file is not needed for local development, In the CI/CD pipeline, a temporary VERSION file is written
# if you need a specific version, just override below
APPVERSION=$(shell cat ./VERSION 2>/dev/null || echo 0.0.0)
# This pulls the version of the SDK from the go.mod file. If the SDK is the only required module,
# it must first remove the word 'required' so the offset of $2 is the same if there are multiple required modules
SDKVERSION=$(shell cat ./go.mod | grep 'github.com/edgexfoundry/app-functions-sdk-go/v4 v' | sed 's/require//g' | awk '{print $$2}')
ifeq ($(ENABLE_FULL_RELRO), true)
ENABLE_FULL_RELRO_GOFLAGS = -bindnow
endif
MICROSERVICE=app-record-replay
GOFLAGS=-ldflags "-s -w -X github.com/edgexfoundry/app-functions-sdk-go/v4/internal.SDKVersion=$(SDKVERSION) \
-X github.com/edgexfoundry/app-functions-sdk-go/v4/internal.ApplicationVersion=$(APPVERSION) \
$(ENABLE_FULL_RELRO_GOFLAGS)" \
-trimpath -mod=readonly
GOTESTFLAGS?=-race
GIT_SHA=$(shell git rev-parse HEAD)
ARCH=$(shell uname -m)
ifeq ($(ENABLE_PIE), true)
GOFLAGS += -buildmode=pie
endif
# CGO is enabled by default and causes docker builds to fail due to no gcc,
# but is required for test with -race, so must disable it for the builds only
build:
CGO_ENABLED=0 go build -tags "$(ADD_BUILD_TAGS)" $(GOFLAGS) -o $(MICROSERVICE)
build-nats:
make -e ADD_BUILD_TAGS=include_nats_messaging build
tidy:
go mod tidy
# NOTE: This is only used for local development. Jenkins CI does not use this make target
docker:
docker build \
--build-arg ADD_BUILD_TAGS=$(ADD_BUILD_TAGS) \
--build-arg http_proxy \
--build-arg https_proxy \
-f Dockerfile \
--label "git_sha=$(GIT_SHA)" \
-t edgexfoundry/app-record-replay:$(GIT_SHA) \
-t edgexfoundry/app-record-replay:${APPVERSION}-dev \
.
docker-nats:
make -C . -e ADD_BUILD_TAGS=include_nats_messaging docker
lint:
@which golangci-lint >/dev/null || echo "WARNING: go linter not installed. To install, run make install-lint"
@if [ "z${ARCH}" = "zx86_64" ] && which golangci-lint >/dev/null ; then echo "running golangci-lint"; golangci-lint version; go version; golangci-lint cache clean; golangci-lint run --verbose --config .golangci.yml ; else echo "WARNING: Linting skipped (not on x86_64 or linter not installed)"; fi
install-lint:
sudo curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.61.0
unittest:
go test $(GOTESTFLAGS) -coverprofile=coverage.out ./...
test: unittest lint
go vet ./...
gofmt -l $$(find . -type f -name '*.go'| grep -v "/vendor/")
[ "`gofmt -l $$(find . -type f -name '*.go'| grep -v "/vendor/")`" = "" ]
./bin/test-attribution-txt.sh
clean:
rm -f $(MICROSERVICE)
vendor:
go mod vendor