-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
172 lines (121 loc) · 4.11 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
165
166
167
168
169
170
171
172
## hocon Makefile:
#:
SHELL = /bin/sh
GO ?= go
CFG ?= .env
PRG ?= $(shell basename $$PWD)
SOURCES = $(shell find . -maxdepth 3 -mindepth 1 -path ./var -prune -o -name '*.go')
# do not include docker-compose.yml from dcape
# docker-compose can't build docker image if it included
DCAPE_DC_USED = false
VERSION ?= $(shell git describe --tags --always)
# Last project tag
RELEASE ?= $(shell git describe --tags --abbrev=0 --always)
APP_ROOT ?= .
APP_SITE ?= $(PRG).dev.lan
APP_PROTO ?= http
APP_TOKEN ?= $(shell < /dev/urandom tr -dc A-Za-z0-9 | head -c16; echo)
IMAGE ?= $(PRG)
IMAGE_VER ?= latest
# Hardcoded in docker-compose.yml service name
DC_SERVICE ?= app
# docker app for change inside containers
DOCKER_BIN ?= docker
# Docker-compose project name (container name prefix)
PROJECT_NAME ?= $(PRG)
# dcape network connect to, must be set in .env
DCAPE_NET ?= dcape_default
GOGENS_IMG ?= ghcr.io/lekovr/gogens:latest
# ------------------------------------------------------------------------------
# .env template (custom part)
# inserted in .env.sample via 'make config'
define CONFIG_CUSTOM
# ------------------------------------------------------------------------------
# app custom config, generated by make config
APP_PROTO=$(APP_PROTO)
APP_TOKEN=$(APP_TOKEN)
# dcape network connect to, must be set in .env
DCAPE_NET=$(DCAPE_NET)
endef
.PHONY: buf.lock dep build run lint test clean
# ------------------------------------------------------------------------------
## Code generate operations
#:
buf.lock:
@id=$$(docker create $(GOGENS_IMG)) ; \
docker cp $$id:/app/$@ $@ ; \
docker rm -v $$id
gen-go:
docker run --rm -v `pwd`:/mnt/pwd -w /mnt/pwd $(GOGENS_IMG) --debug generate --template buf.gen.yaml --path proto
buf:
docker run --rm -it -v `pwd`:/mnt/pwd -w /mnt/pwd $(GOGENS_IMG) $(CMD)
gen-js: static/js/api.js
static/js/api.js: zgen/ts/proto/service.pb.ts
docker run --rm -v `pwd`:/mnt/pwd -w /mnt/pwd --entrypoint /go/bin/esbuild $(GOGENS_IMG) \
zgen/ts/proto/service.pb.ts --bundle --outfile=/mnt/pwd/static/js/api.js --global-name=AppAPI
# --sourcemap --target=chrome58 \
# --minify --sourcemap --target=chrome58,firefox57,safari11,edge16 \
gen: gen-go gen-js
# ------------------------------------------------------------------------------
## Compile operations
#:
$(PRG): $(SOURCES)
$(GO) build -ldflags "-X main.version=$(VERSION)" ./cmd/$(PRG)
run: $(PRG)
./$(PRG) --token $(APP_TOKEN)
build: $(PRG)
version: $(PRG)
go version -m $(PRG)
## Format go sources
fmt:
$(GO) fmt ./...
## Run vet
vet:
$(GO) vet ./...
## Run linter
lint:
golint ./...
## Run more linters
lint-more:
golangci-lint run ./...
## Run tests
test: coverage.out
## Run tests and fill coverage.out
cov: coverage.out
# internal target
coverage.out: $(SOURCES)
GIN_MODE=release $(GO) test -test.v -test.race -coverprofile=$@ -covermode=atomic ./...
## Open coverage report in browser
cov-html: cov
$(GO) tool cover -html=coverage.out
## Clean coverage report
cov-clean:
rm -f coverage.*
## Changes from last tag
changelog:
@echo Changes since $(RELEASE)
@echo
@git log $(RELEASE)..@ --pretty=format:"* %s"
# ------------------------------------------------------------------------------
## Docker operations
#:
docker: $(PRG)
docker build -t $(PRG) .
# ------------------------------------------------------------------------------
## Build docker image
docker-build: CMD="build --no-cache --force-rm $(DC_SERVICE)"
docker-build: dc
## Remove docker image & temp files
docker-clean:
[ "$$($(DOCKER_BIN) images -q $(DC_IMAGE) 2> /dev/null)" = "" ] || $(DOCKER_BIN) rmi $(DC_IMAGE)
clean: ## Remove previous builds
@rm -f $(PRG)
# ------------------------------------------------------------------------------
# Find and include DCAPE/apps/drone/dcape-app/Makefile
DCAPE_COMPOSE ?= dcape-compose
DCAPE_MAKEFILE ?= $(shell docker inspect -f "{{.Config.Labels.dcape_app_makefile}}" $(DCAPE_COMPOSE))
ifeq ($(shell test -e $(DCAPE_MAKEFILE) && echo -n yes),yes)
include $(DCAPE_MAKEFILE)
else
-include /opt/dcape-app/Makefile
endif