-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
91 lines (78 loc) · 2.25 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
# General
CMD :=
PKG := go.soon.build/sslcheck
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)
# Docker
DOCKER_IMAGE = soon/sslcheck
# Versioning
GIT_COMMIT ?= $(shell git rev-parse HEAD)
GIT_SHA ?= $(shell git rev-parse --short HEAD)
GIT_TAG ?= $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
GIT_DIRTY ?= $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean")
# Binary Name
BIN_OUTDIR ?= ./build/bin
BIN_NAME ?= sslcheck-$(shell go env GOOS)-$(shell go env GOARCH)
ifeq ("$(GIT_TAG)","")
BIN_VERSION = $(GIT_SHA)
endif
BIN_VERSION ?= ${GIT_TAG}
# Docker Tag from Git
DOCKER_TAG ?= ${GIT_TAG}
ifeq ("$(DOCKER_TAG)","")
DOCKER_TAG = $(GIT_SHA)
endif
# LDFlags
# LDFLAGS := -w -s
LDFLAGS += -X $(PKG)/internal/version.Timestamp=$(shell date +%s)
LDFLAGS += -X $(PKG)/internal/version.GitCommit=${GIT_COMMIT}
LDFLAGS += -X $(PKG)/internal/version.GitTreeState=${GIT_DIRTY}
LDFLAGS += -X $(PKG)/internal/version.Version=${BIN_VERSION}
# CGO
CGO ?= 1
# Go Build Flags
GOBUILDFLAGS :=
GOBUILDFLAGS += -o $(BIN_OUTDIR)/$(BIN_NAME)
.PHONY: info
info:
@echo "Version: ${BIN_VERSION}"
@echo "Binary Name: ${BIN_NAME}"
@echo "Git Tag: ${GIT_TAG}"
@echo "Git Commit: ${GIT_COMMIT}"
@echo "Git Tree State: ${GIT_DIRTY}"
# Build a statically linked binary
.PHONY: static
static: CGO = 0
static: GOBUILDFLAGS += -a
static: GOBUILDFLAGS += -tags netgo -installsuffix netgo
static: GOBUILDFLAGS += -installsuffix netgo
static: LDFLAGS += -a -extldflags "-static"
static: build
# Build a binary
.PHONY: build
build: CMD = ./cmd/sslcheck
build: GOBUILDFLAGS += -ldflags '$(LDFLAGS)'
build:
@CGO_ENABLED=$(CGO) go build $(GOBUILDFLAGS) $(CMD)
# Build and run the application
.PHONY: run
run: GOBUILDFLAGS += -i
run: build
@$(BIN_OUTDIR)/$(BIN_NAME)
# Build docker image
.PHONY: image
image:
docker build \
--build-arg GIT_COMMIT=${GIT_COMMIT} \
--build-arg GIT_SHA=${GIT_SHA} \
--build-arg GIT_TAG=${GIT_TAG} \
--build-arg GIT_DIRTY=${GIT_DIRTY} \
--build-arg GOPROXY \
-t ${DOCKER_IMAGE}:${DOCKER_TAG} \
-f ./build/package/Dockerfile .
# Run test suite
.PHONY: test
test:
ifeq ("$(wildcard $(shell which gocov))","")
go get github.com/axw/gocov/gocov
endif
gocov test ${PKG_LIST} | gocov report