-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
83 lines (66 loc) · 1.89 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
_date := $(shell date '+%y%m%d')
_hash := $(shell git rev-parse --short=8 HEAD)
_dirty := $(shell git diff --quiet || echo '-dev')
_tag := $(shell git tag | tail -n 1 | grep "" || echo 'v0.0.0')
VERSION ?= v${_date}-${_tag}-${_hash}
LATEST := $(shell [ ! -z "${_dirty}" ] && echo 'latest' || echo '')
REGISTRY := docker.io
NAME ?= $(shell sed -En 's/^module (.*)$$/\1/p' go.mod | cut -d / -f 3 )
REPOSITORY := $(shell sed -En 's/^module (.*)$$/\1/p' go.mod | cut -d / -f 2 )
TOOLCHAIN_VERSION := $(shell sed -En 's/^go (.*)$$/\1/p' go.mod)
MODULE_NAME := $(shell sed -En 's/^module (.*)$$/\1/p' go.mod)
GO ?= go
ENGINE ?= docker
LDFLAGS += -X ${MODULE_NAME}/version.Version=${VERSION}
LDFLAGS += -X ${MODULE_NAME}/version.Name=${NAME}
CONTAINERFILE ?= Dockerfile
ifeq (${LATEST},latest)
OCI_TAGS += --tag=${REGISTRY}/${REPOSITORY}/${NAME}:${LATEST}
endif
OCI_TAGS += --tag=${REGISTRY}/${REPOSITORY}/${NAME}:${VERSION}
OCI_BUILDARGS += --build-arg=TOOLCHAIN_VERSION=${TOOLCHAIN_VERSION}
GO_SETTINGS += CGO_ENABLED=0
.PHONY: build
build: clean
${GO_SETTINGS} ${GO} build \
-ldflags="${LDFLAGS}" \
-o ./build/${NAME}
.PHONY: build-release
build-release: clean
LDFLAGS="-s -w" make build
.PHONY: dev-dependencies
dev-dependencies:
cd .dev && docker compose up --detach
.PHONY: docs
docs:
rm -rf ./docs/*.md
${GO} run \
-ldflags="${LDFLAGS}" \
./scripts/docs-generator.go
.PHONY: e2e
e2e:
TEST_MODE="-tags=e2e" make test
.PHONY: test
test:
${GO} test ${TEST_MODE} \
-cover \
-race \
-covermode=atomic \
-coverprofile=coverage.out \
./...
.PHONY: lint
lint:
golangci-lint run -v
.PHONY: clean
clean:
rm -rf ./build
.PHONY: clean-image
clean-image:
@-${ENGINE} image rm -f $(shell ${ENGINE} image ls -aq ${REGISTRY}/${REPOSITORY}/${NAME}:${VERSION} | xargs -n1 | sort -u | xargs)
.PHONY: image
image: clean-image
${ENGINE} build \
${OCI_TAGS} \
${OCI_BUILDARGS} \
--file ${CONTAINERFILE} \
.