-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
123 lines (89 loc) · 3.75 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
.PHONY: all deps docker docker-cgo clean docs test test-race fmt lint install deploy-docs
TAGS =
INSTALL_DIR = $(GOPATH)/bin
DEST_DIR = ./target
PATHINSTBIN = $(abspath $(DEST_DIR)/bin)
PATHINSTDOCKER = $(DEST_DIR)/docker
# Add target bin dir to PATH
export PATH := $(PATHINSTBIN):$(PATH)
VERSION := $(shell git describe --tags || echo "v0.0.0")
VER_CUT := $(shell echo $(VERSION) | cut -c2-)
VER_MAJOR := $(shell echo $(VER_CUT) | cut -f1 -d.)
VER_MINOR := $(shell echo $(VER_CUT) | cut -f2 -d.)
VER_PATCH := $(shell echo $(VER_CUT) | cut -f3 -d.)
VER_RC := $(shell echo $(VER_PATCH) | cut -f2 -d-)
DATE := $(shell date +"%Y-%m-%dT%H:%M:%SZ")
LD_FLAGS =
GO_FLAGS =
DOCS_FLAGS =
NAME?="new"
GOLANGCI_VERSION = latest
# Get binary versions from go.mod
GQLGEN_VERSION = $(shell go list -m -f '{{.Version}}' github.com/99designs/gqlgen)
GOOSE_VERSION = $(shell go list -m -f '{{.Version}}' github.com/pressly/goose/v3)
SQLBOILER_VERSION = $(shell go list -m -f '{{.Version}}' github.com/volatiletech/sqlboiler/v4)
APPS = accounts-api
help:
@echo "\nSpecify a subcommand:\n"
@grep -hE '^[0-9a-zA-Z_-]+:.*?## .*$$' ${MAKEFILE_LIST} | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[0;36m%-20s\033[m %s\n", $$1, $$2}'
@echo ""
all: $(APPS)
install: $(APPS)
@mkdir -p bin
@cp $(PATHINSTBIN)/$(APPS) ./bin/
deps:
@go mod tidy
@go mod vendor
SOURCE_FILES = $(shell find graph internal models cmd -type f -name "*.go")
$(PATHINSTBIN)/%: $(SOURCE_FILES)
@go build $(GO_FLAGS) -tags "$(TAGS)" -ldflags "$(LD_FLAGS) " -o $@ ./cmd/$*
$(APPS): %: $(PATHINSTBIN)/%
docker-tags:
@echo "latest,$(VER_CUT),$(VER_MAJOR).$(VER_MINOR),$(VER_MAJOR)" > .tags
docker-rc-tags:
@echo "latest,$(VER_CUT),$(VER_MAJOR)-$(VER_RC)" > .tags
docker-cgo-tags:
@echo "latest-cgo,$(VER_CUT)-cgo,$(VER_MAJOR).$(VER_MINOR)-cgo,$(VER_MAJOR)-cgo" > .tags
docker: deps
@docker build -f ./resources/docker/Dockerfile . -t dimozone/accounts-api:$(VER_CUT)
@docker tag dimozone/accounts-api:$(VER_CUT) dimozone/accounts-api:latest
docker-cgo: deps
@docker build -f ./resources/docker/Dockerfile.cgo . -t dimozone/accounts-api:$(VER_CUT)-cgo
@docker tag dimozone/accounts-api:$(VER_CUT)-cgo dimozone/accounts-api:latest-cgo
fmt:
@go list -f {{.Dir}} ./... | xargs -I{} gofmt -w -s {}
@go mod tidy
lint: ## Run linter.
@golangci-lint run
test: ## Run all package tests.
@go test $(GO_FLAGS) -timeout 3m -p=1 ./...
clean: ## Remove previous builds.
rm -rf $(PATHINSTBIN)
rm -rf $(DEST_DIR)/dist
rm -rf $(PATHINSTDOCKER)
run: $(APPS) ## Run the app.
$(PATHINSTBIN)/$(APPS)
migrate: $(APPS) ## Run database migrations.
$(PATHINSTBIN)/$(APPS) migrate
sql: ## Create a new SQL migration file. Use the NAME variable to set the name: "make sql NAME=dcn_table".
@goose -version
goose -dir migrations -s create $(NAME) sql
boil: ## Generate SQLBoiler models.
@sqlboiler --version
sqlboiler psql --no-tests --wipe
gql: ## Generate gqlgen code.
@gqlgen version
gqlgen generate
tools-golangci-lint: ## Install golangci-lint dependency.
@mkdir -p $(PATHINSTBIN)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(PATHINSTBIN) $(GOLANGCI_VERSION)
tools-gqlgen: ## Install gqlgen dependency.
@mkdir -p $(PATHINSTBIN)
GOBIN=$(PATHINSTBIN) go install github.com/99designs/gqlgen@$(GQLGEN_VERSION)
tools-goose: ## Install goose dependency.
@mkdir -p $(PATHINSTBIN)
GOBIN=$(PATHINSTBIN) go install github.com/pressly/goose/v3/cmd/goose@$(GOOSE_VERSION)
tools-sqlboiler: ## Install sqlboiler dependency.
@mkdir -p $(PATHINSTBIN)
GOBIN=$(PATHINSTBIN) go install github.com/volatiletech/sqlboiler/v4@$(SQLBOILER_VERSION)
tools: tools-golangci-lint tools-gqlgen tools-goose tools-sqlboiler ## Install all tool dependencies.