-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
101 lines (82 loc) · 2.49 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
98
99
100
101
NAME := walter
DOCKER_PREFIX = benmatselby
DOCKER_RELEASE ?= latest
DOCKER_PLATFORM ?= --platform=amd64
BUILD_DIR ?= build
GOOS ?=
ARCH ?=
OUT_PATH=$(BUILD_DIR)/$(NAME)-$(GOOS)-$(GOARCH)
GIT_RELEASE ?= $(shell git rev-parse --short HEAD)
.PHONY: explain
explain:
### Welcome
#
# _ _ _ _ _ _
# / \ / \ / \ / \ / \ /
# ( W | a | l | t | e | r )
# \_/ \_/ \_/ \_/ \_/ \_/
#
#
### Installation
#
# $$ make all
#
### Targets
@cat Makefile* | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: clean
clean: ## Clean the local dependencies
rm -fr vendor
rm -fr $(BUILD_DIR) && mkdir -p $(BUILD_DIR)
.PHONY: install
install: ## Install the local dependencies
go install github.com/golang/mock/mockgen@master
go install github.com/securego/gosec/cmd/gosec@master
go install golang.org/x/lint/golint@master
go get ./...
.PHONY: lint
lint: ## Vet the code
golangci-lint run
.PHONY: security
security: ## Inspect the code
gosec ./...
.PHONY: build
build: ## Build the application
go build .
.PHONY: static
static: ## Build the application
CGO_ENABLED=0 go build -ldflags "-extldflags -static -X github.com/benmatselby/$(NAME)/version.GITCOMMIT=$(GIT_RELEASE)" -o $(NAME) .
.PHONY: static-named
static-named: ## Build the application with named outputs
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 \
go build \
-ldflags "-extldflags -static -X github.com/benmatselby/$(NAME)/version.GITCOMMIT=$(GIT_RELEASE)" \
-o $(OUT_PATH) .
md5sum $(OUT_PATH) > $(OUT_PATH).md5 || md5 $(OUT_PATH) > $(OUT_PATH).md5
sha256sum $(OUT_PATH) > $(OUT_PATH).sha256 || shasum $(OUT_PATH) > $(OUT_PATH).sha256
.PHONY: test
test: ## Run the unit tests
go test ./... -coverprofile=coverage.out
go tool cover -func=coverage.out
.PHONY: test-cov
test-cov: test ## Run the unit tests with coverage
go tool cover -html=coverage.out
.PHONY: mocks
mocks: ## Generate the mocks for the tests
mockgen -source jira/jira.go
.PHONY: all ## Run everything
all: clean install build test
.PHONY: static-all ## Run everything
static-all: clean install static test
###
# Docker
###
.PHONY: docker-build
docker-build:
docker build -t $(DOCKER_PREFIX)/$(NAME):$(DOCKER_RELEASE) $(DOCKER_PLATFORM) .
.PHONY: docker-push
docker-push:
docker push $(DOCKER_PREFIX)/$(NAME):$(DOCKER_RELEASE)
.PHONY: docker-scan
docker-scan: ## Scan the docker image
docker scout recommendations $(DOCKER_PREFIX)/$(NAME)
docker scout quickview $(DOCKER_PREFIX)/$(NAME)