-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
77 lines (60 loc) · 1.91 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
PROJECT?=github.com/adrianriobo/qe-eventmanager
VERSION ?= 0.0.4
COMMIT ?= $(shell git rev-parse --short HEAD)
BUILD_TIME ?= $(shell date -u '+%Y-%m-%d_%H:%M:%S')
CONTAINER_MANAGER ?= podman
# Image URL to use all building/pushing image targets
IMG ?= quay.io/ariobolo/qe-eventmanager:${VERSION}
# Go and compilation related variables
GOPATH ?= $(shell go env GOPATH)
BUILD_DIR ?= out
SOURCE_DIRS = cmd pkg test
# https://golang.org/cmd/link/
LDFLAGS := $(VERSION_VARIABLES) -extldflags='-static' ${GO_EXTRA_LDFLAGS}
GCFLAGS := all=-N -l
# Add default target
.PHONY: default
default: install
# Create and update the vendor directory
.PHONY: vendor
vendor:
go mod tidy
go mod vendor
.PHONY: check
check: build test lint
# Start of the actual build targets
.PHONY: install
install: $(SOURCES)
go install -ldflags="$(LDFLAGS)" $(GO_EXTRA_BUILDFLAGS) ./cmd
$(BUILD_DIR)/qe-eventmanager: $(SOURCES)
GOOS=linux GOARCH=amd64 go build -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS) \
-X ${PROJECT}/version.Version=${VERSION} \
-X ${PROJECT}/version.Commit=${COMMIT} \
-X ${PROJECT}/version.BuildTime=${BUILD_TIME}" \
-o $(BUILD_DIR)/qe-eventmanager $(GO_EXTRA_BUILDFLAGS) ./cmd
.PHONY: build
build: $(BUILD_DIR)/qe-eventmanager
.PHONY: test
test:
go test -race --tags build -v -ldflags="$(VERSION_VARIABLES)" ./pkg/... ./cmd/...
.PHONY: clean ## Remove all build artifacts
clean:
rm -rf $(BUILD_DIR)
rm -f $(GOPATH)/bin/qe-eventmanager
.PHONY: fmt
fmt:
@gofmt -l -w $(SOURCE_DIRS)
$(GOPATH)/bin/golangci-lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2
# Run golangci-lint against code
.PHONY: lint
lint: $(GOPATH)/bin/golangci-lint
$(GOPATH)/bin/golangci-lint run
# Build the container image
.PHONY: container-build
container-build: test
${CONTAINER_MANAGER} build -t ${IMG} -f images/builder/Dockerfile .
# Push the docker image
.PHONY: container-push
container-push:
${CONTAINER_MANAGER} push ${IMG}