-
Notifications
You must be signed in to change notification settings - Fork 41
/
Makefile
64 lines (53 loc) · 1.75 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
# Metadata about this makefile and position
MKFILE_PATH := $(lastword $(MAKEFILE_LIST))
CURRENT_DIR := $(patsubst %/,%,$(dir $(realpath $(MKFILE_PATH))))
# System information
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
# Project information
NAME := "consul-esm"
GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
GIT_DESCRIBE ?= $(shell git describe --tags --always)
VERSION := $(shell awk -F\" '/^[ \t]+Version/ { print $$2; exit }' "${CURRENT_DIR}/version/version.go")
PRERELEASE := $(shell awk -F\" '/^[ \t]+VersionPrerelease/ { print $$2; exit }' "${CURRENT_DIR}/version/version.go")
# Tags specific for building
GOTAGS ?=
# List of ldflags
LD_FLAGS ?= \
-s -w \
-X github.com/hashicorp/consul-esm/version.Name=${NAME} \
-X github.com/hashicorp/consul-esm/version.GitCommit=${GIT_COMMIT} \
-X github.com/hashicorp/consul-esm/version.GitDescribe=${GIT_DESCRIBE}
# for CRT build process
version:
@echo ${VERSION}${PRERELEASE}
.PHONY: version
# dev builds and installs the project locally.
dev:
@echo "==> Installing ${NAME} for ${GOOS}/${GOARCH}"
@env CGO_ENABLED="0" \
go install -ldflags "${LD_FLAGS}" -tags "${GOTAGS}"
.PHONY: dev
# dev docker builds
docker:
mkdir -p dist/linux/amd64/
@env CGO_ENABLED="0" go build -ldflags "${LD_FLAGS}" -o dist/linux/amd64/$(NAME)
env DOCKER_BUILDKIT=1 docker build -t $(NAME) .
.PHONY: docker
test:
@echo "==> Testing ${NAME}"
@go test -timeout=60s -tags="${GOTAGS}" ${TESTARGS} ./...
.PHONY: test
test-race:
@echo "==> Testing ${NAME}"
@go test -race -timeout=60s -tags="${GOTAGS}" ${TESTARGS} ./...
.PHONY: test-race
# clean removes any previous binaries
clean:
@rm -rf "${CURRENT_DIR}/dist/"
@rm -f "consul-esm"
.PHONY: clean
# noop command to get build pipeline working
dev-tree:
@true
.PHONY: dev-tree