-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
91 lines (70 loc) · 2.76 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
.DEFAULT_GOAL := help
MIGRATIONS_PATH = sql/migrations
GOFILES = $(shell find . -name '*.go')
DOCKER_IMG_PRODUCER = ghcr.io/popsu/gww-producer
DOCKER_TAG_PRODUCER = latest
PRODUCER_PACKAGE = github.com/popsu/go-website-watcher/producer/cmd/producer
DOCKER_IMG_CONSUMER = ghcr.io/popsu/gww-consumer
DOCKER_TAG_CONSUMER = latest
CONSUMER_PACKAGE = github.com/popsu/go-website-watcher/consumer/cmd/consumer
# build flags
CGO_ENABLED = 0
LDFLAGS = -ldflags='-s -w'
BUILDFLAGS = -tags "osusergo netgo" -trimpath
.PHONY: help
help: ## This help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: test
test: ## Run tests
# Use richgo if installed
# https://github.com/kyoh86/richgo
ifneq (, $(shell which richgo))
richgo test -race -cover -v ./...
else
go test -race -cover ./...
endif
.PHONY: tools
tools: ## Install required tools (go-migrate)
go install -tags "postgres" github.com/golang-migrate/migrate/v4/cmd/[email protected]
.PHONY: tidy
tidy: ## Tidy go modules
go mod tidy
.PHONY: clean
clean: ## Clean artifacts
go clean ./...
rm -vrf bin/*
.PHONY: build
build: build-producer build-consumer ## Build producer and consumer dev
.PHONY: build-producer
build-producer: bin/dev/gww-producer tidy ## Build producer dev
.PHONY: build-consumer
build-consumer: bin/dev/gww-consumer tidy ## Build consumer dev
.PHONY: db-migrate-up
db-migrate-up: ## Run db migrations up
ifneq (, $(shell which migrate))
migrate -database ${POSTGRES_DBURL} -path ${MIGRATIONS_PATH} up
else
@echo Requires go-migrate, install with "make tools" or from https://github.com/golang-migrate/migrate
endif
.PHONY: db-migrate-down
db-migrate-down: ## Run db migrations down
migrate -database ${POSTGRES_DBURL} -path ${MIGRATIONS_PATH} down
.PHONY: generate-sql
generate-sql: ## Generate sql from template in sql/migrations/templates
go run ./sql/migrations/templates > sql/migrations/001_create_initial_table.up.sql
bin/dev/gww-producer: $(GOFILES)
go build -race $(LDFLAGS) $(BUILDFLAGS) -o $@ ${PRODUCER_PACKAGE}
bin/dev/gww-consumer: $(GOFILES)
go build -race $(LDFLAGS) $(BUILDFLAGS) -o $@ ${CONSUMER_PACKAGE}
bin/release/gww-producer: $(GOFILES)
CGO_ENABLED=$(CGO_ENABLED) go build $(LDFLAGS) $(BUILDFLAGS) -o $@ ${PRODUCER_PACKAGE}
upx --lzma $@
bin/release/gww-consumer: $(GOFILES)
CGO_ENABLED=$(CGO_ENABLED) go build $(LDFLAGS) $(BUILDFLAGS) -o $@ ${CONSUMER_PACKAGE}
upx --lzma $@
.PHONY: docker-build-producer
docker-build-producer: ## Build producer docker image
docker build -t ${DOCKER_IMG_PRODUCER}:${DOCKER_TAG_PRODUCER} -f producer/Dockerfile .
.PHONY: docker-build-consumer
docker-build-consumer: ## Build consumer docker image
docker build -t ${DOCKER_IMG_CONSUMER}:${DOCKER_TAG_CONSUMER} -f consumer/Dockerfile .