-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
88 lines (70 loc) · 2.07 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
.DEFAULT_GOAL := help
BIN:=$(CURDIR)/bin
BIN_LINTER:=$(BIN)/golangci-lint
VERSION:=$(shell cat VERSION)
REGISTRY_DOMAIN=ghcr.io
REGISTRY_NAME=ghcr.io/wault-pw/alice
help:
@echo 'Available targets: $(VERSION)'
@echo ' make build'
@echo ' make push'
@echo ' make outdated'
@echo ' '
@echo ' make db:status'
@echo ' make db:up'
@echo ' make db:down'
@echo ' make NAME="create_users" db:create'
@echo ' '
@echo ' make test'
@echo ' make outdated'
.PHONY: install-lint
install-lint:
ifeq ($(wildcard $(BIN_LINTER)),)
$(info Downloading golangci-lint)
GOBIN=$(BIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.1
endif
t:
$(eval PG_DSN?=postgres://localhost:5432/alice_test?sslmode=disable&timezone=utc)
d:
$(eval PG_DSN?=postgres://localhost:5432/alice?sslmode=disable&timezone=utc)
db\:up: d
db\:up:
goose -dir migrations postgres "$(PG_DSN)" up
db\:down: d
db\:down:
goose -dir migrations postgres "$(PG_DSN)" down
db\:status: d
db\:status:
goose -dir migrations postgres "$(PG_DSN)" status
db\:create: NAME=$NAME
db\:create:
goose -dir migrations postgres "$(PG_DSN)" create $(NAME) sql
proto:
protoc --proto_path=protos --go_out=. alice_v1.proto
test: t
test:
PG_DSN="$(PG_DSN)" go test -count=1 -p 4 -race -cover -covermode atomic ./...
outdated:
go list -u -m all
lint: install-lint
lint:
$(BIN_LINTER) run --config=.golangci.yaml ./...
generate:
go generate ./...
generate_build:
go generate cmd/goose.go
linux: generate_build
linux:
env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -buildvcs=false -ldflags "-s -X 'main.Version=$(VERSION)'" -a -installsuffix cgo -o build/linux
mac: generate_build
mac:
env GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -buildvcs=false -ldflags "-s -X 'main.Version=$(VERSION)'" -a -installsuffix cgo -o build/mac
.PHONY: build
build: export TAG=$(VERSION)
build:
docker build --no-cache -f ./Dockerfile -t ${REGISTRY_NAME}:${TAG} .
docker tag ${REGISTRY_NAME}:${TAG} ${REGISTRY_NAME}:latest
push: export TAG=$(VERSION)
push:
docker push ${REGISTRY_NAME}:${TAG}
docker push ${REGISTRY_NAME}:latest