-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
135 lines (106 loc) · 3.6 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
GOLANG_VERSION?=1.16.7
SWAGGER_UI_VERSION?=3.20.6
SWAGGER_UI_DIST_URL?=https://raw.githubusercontent.com/swagger-api/swagger-ui/v$(SWAGGER_UI_VERSION)/dist
REGISTRY?=quay.io/opsway
BIN:=$(shell basename "$(PWD)")
REPO:=$(REGISTRY)/$(BIN)
SHELL:=/bin/bash
DATE:=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
VCS_REF:=$(shell git log -n 1 --pretty=format:%H)
VERSION:=$(shell git describe --tags --always --dirty)
DOCKER_CMD:=docker run --rm --interactive --tty --volume $(PWD):/src
WKHTML_IMAGE:=$(REPO):wkhtml
WKHTML_IMAGE_FILE:=build/wkhtml.docker
IMAGE_BASE:=$(WKHTML_IMAGE)
BASE_IMAGE:=$(WKHTML_IMAGE)
DEVELOP_IMAGE:=$(REPO):develop
DEVELOP_IMAGE_FILE:=build/develop.docker
RELEASE_IMAGE:=$(REPO):$(VERSION)
RELEASE_IMAGE_ALIASE:=$(REPO):latest
.DEFAULT_GOAL:=help
help: # Output usage documentation
@echo "Usage: make <target>"
@echo " "
@echo "Commands:"
@echo " "
@@grep -E '^[a-z\-]+' $(MAKEFILE_LIST)
@echo " "
image-wkhtml: # build wkhtml image
docker build \
--build-arg BUILD_DATE=$(DATE) \
--build-arg VERSION=$(VERSION) \
--build-arg VCS_REF=$(VCS_REF) \
--tag $(WKHTML_IMAGE) \
--file $(WKHTML_IMAGE_FILE) . |& tee image-wkhtml
image-develop: image-wkhtml # build develop image
docker build \
--build-arg GOLANG_VERSION=$(GOLANG_VERSION) \
--build-arg IMAGE_BASE=$(IMAGE_BASE) \
--build-arg BUILD_DATE=$(DATE) \
--build-arg VERSION=$(VERSION) \
--build-arg VCS_REF=$(VCS_REF) \
--tag $(DEVELOP_IMAGE) \
--file $(DEVELOP_IMAGE_FILE) . |& tee image-develop
image-release: image-develop # build release image
docker build \
--no-cache \
--build-arg DEVELOP_IMAGE=$(DEVELOP_IMAGE) \
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
--build-arg VERSION=$(VERSION) \
--build-arg BUILD_DATE=$(DATE) \
--build-arg VCS_REF=$(VCS_REF) \
--tag $(RELEASE_IMAGE) \
--tag $(RELEASE_IMAGE_ALIASE) \
--file build/release.docker .
run-in-docker: # run command in docker, use: cmd=<command>
$(DOCKER_CMD) $(DEVELOP_IMAGE) $(cmd)
fmt: # gofmt and goimports all go files
go fmt ./...
lint:
goreportcard-cli -v -t 100
codequality: lint test
entrypoint: codequality docs
CGO_ENABLED=0 go build \
-o entrypoint \
main.go
test: # run all tests
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out -o coverage.html
go tool cover -func=coverage.out
clean:
rm -fr public/assets
rm -fr public/index.json
rm -fr entrypoint
public/assets: # assets build
mkdir -p public/assets
curl $(SWAGGER_UI_DIST_URL)/favicon-16x16.png --output public/assets/favicon-16x16.png --silent
curl $(SWAGGER_UI_DIST_URL)/favicon-32x32.png --output public/assets/favicon-32x32.png --silent
curl $(SWAGGER_UI_DIST_URL)/swagger-ui.css --output public/assets/swagger-ui.css --silent
curl $(SWAGGER_UI_DIST_URL)/swagger-ui-bundle.js --output public/assets/swagger-ui-bundle.js --silent
curl $(SWAGGER_UI_DIST_URL)/swagger-ui-standalone-preset.js --output public/assets/swagger-ui-standalone-preset.js --silent
public/index.json: public/assets
swagger generate spec --output=public/index.json
docs: clean public/assets public/index.json
start:
docker run \
--rm \
--publish 8515:8515 \
$(RELEASE_IMAGE)
build: entrypoint
publish-release: image-release # image publish release image
docker push $(RELEASE_IMAGE)
docker push $(RELEASE_IMAGE_ALIASE)
publish-develop: image-wkhtml image-develop
docker push $(DEVELOP_IMAGE)
docker push $(WKHTML_IMAGE)
say-image-name:
@echo "wkhtml: $(WKHTML_IMAGE)"
@echo "develop: $(DEVELOP_IMAGE)"
@echo "release: $(RELEASE_IMAGE)"
say-image-labels:
@docker inspect \
$(RELEASE_IMAGE) \
| jq .[0].Config.Labels
say-image-history:
@docker history \
$(RELEASE_IMAGE)