-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
164 lines (148 loc) · 3.62 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
override APP_NAME=pinchy
override GO_VERSION=1.15
override DOCKER_BUILDKIT=1
GOOS?=$(shell go env GOOS || echo linux)
GOARCH?=$(shell go env GOARCH || echo amd64)
CGO_ENABLED?=0
BUIlD_VERSION?=latest
DOCKER_REGISTRY?=docker.io
DOCKER_IMAGE?=insidieux/${APP_NAME}
DOCKER_TAG?=latest
DOCKER_USER=
DOCKER_PASSWORD=
ifeq (, $(shell which docker))
$(error "Binary docker not found in $(PATH)")
endif
.PHONY: all
all: cleanup vendor wire lint test build
.PHONY: cleanup
cleanup:
@rm ${PWD}/bin/${APP_NAME}* || true
@rm ${PWD}/coverage.out || true
@find ${PWD} -type f -name "wire_gen.go" -delete
@find ${PWD} -type f -name "mock_*_test.go" -delete
@rm -r ${PWD}/vendor || true
.PHONY: vendor
vendor:
@rm -r ${PWD}/vendor || true
@docker run --rm -v ${PWD}:/project -w /project golang:${GO_VERSION} go mod tidy
@docker run --rm -v ${PWD}:/project -w /project golang:${GO_VERSION} go mod vendor
.PHONY: wire
wire:
@docker build \
--build-arg GO_VERSION=${GO_VERSION} \
-f ${PWD}/build/docker/utils/wire/Dockerfile \
-t wire:custom \
build/docker/utils/wire
@find ${PWD} -type f -name "wire_gen.go" -delete
@docker run --rm \
-v ${PWD}:/project \
-w /project \
wire:custom \
/project/...
.PHONY: lint-golangci-lint
lint-golangci-lint:
@docker run --rm \
-v ${PWD}:/project \
-w /project \
golangci/golangci-lint:v1.33.0 \
golangci-lint run -v
.PHONY: lint-golint
lint-golint:
@docker build \
--build-arg GO_VERSION=${GO_VERSION} \
-f ${PWD}/build/docker/utils/golint/Dockerfile \
-t golint:custom \
build/docker/utils/golint
@docker run --rm \
-v ${PWD}:/project \
-w /project \
golint:custom \
--set_exit_status \
/project/pkg/... \
/project/internal/... \
/project/cmd/...
.PHONY: lint
lint:
@make lint-golangci-lint
@make lint-golint
.PHONY: test
test:
@rm -r ${PWD}/coverage.out || true
@docker run --rm \
-v ${PWD}:/project \
-w /project \
golang:${GO_VERSION} \
go test \
-race \
-mod vendor \
-covermode=atomic \
-coverprofile=/project/coverage.out \
/project/...
.PHONY: build
build:
@rm ${PWD}/bin/${APP_NAME} || true
@docker run --rm \
-v ${PWD}:/project \
-w /project \
-e GOOS=${GOOS} \
-e GOARCH=${GOARCH} \
-e CGO_ENABLED=${CGO_ENABLED} \
-e GO111MODULE=on \
golang:${GO_VERSION} \
go build \
-mod vendor \
-ldflags "-X main.version=${BUIlD_VERSION}" \
-o /project/bin/${APP_NAME} \
-v /project/cmd/${APP_NAME}
.PHONY: docker-image-build
docker-image-build:
ifndef DOCKER_IMAGE
$(error DOCKER_IMAGE is not set)
endif
ifndef DOCKER_TAG
$(error DOCKER_TAG is not set)
endif
@docker rmi ${DOCKER_IMAGE}:${DOCKER_TAG} || true
@docker build \
-f ${PWD}/build/docker/cmd/pinchy/Dockerfile \
-t ${DOCKER_IMAGE}:${DOCKER_TAG} \
.
.PHONY: docker-image-push
docker-image-push:
ifndef DOCKER_REGISTRY
$(error DOCKER_REGISTRY is not set)
endif
ifndef DOCKER_USER
$(error DOCKER_USER is not set)
endif
ifndef DOCKER_PASSWORD
$(error DOCKER_PASSWORD is not set)
endif
ifndef DOCKER_IMAGE
$(error DOCKER_IMAGE is not set)
endif
ifndef DOCKER_TAG
$(error DOCKER_TAG is not set)
endif
@docker login -u ${DOCKER_USER} -p ${DOCKER_PASSWORD} ${DOCKER_REGISTRY}
@docker push ${DOCKER_IMAGE}:${DOCKER_TAG}
.PHONY: mockery
mockery:
ifndef MOCKERY_SOURCE_DIR
$(error MOCKERY_SOURCE_DIR is not set)
endif
@docker pull vektra/mockery:v2.4.0
@find ${PWD} -type f -name "mock_*_test.go" -delete
@docker run \
--rm \
-v ${PWD}:/project \
-w /project \
vektra/mockery:v2.4.0 \
--testonly \
--inpackage \
--all \
--dir /project/${MOCKERY_SOURCE_DIR} \
--output /project/${MOCKERY_SOURCE_DIR} \
--case snake \
--log-level trace