-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·86 lines (69 loc) · 2.35 KB
/
Copy pathMakefile
File metadata and controls
executable file
·86 lines (69 loc) · 2.35 KB
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
.DEFAULT: all
.PHONY: fmt test gen clean run help sql docker
# command aliases
test := CONFIG_ENV=test go test ./...
targets := nalpaca
MODULE := github.com/AnthonyHewins/nalpaca
VERSION ?= v?.?.?
COMMIT ?= $(shell git rev-list -1 HEAD)
IMAGE := docker.io/ahewins/nalpaca
BUILD_FLAGS :=
docker_bin ?= podman
ifneq (,$(wildcard ./vendor))
$(info Found vendor directory; setting "-mod vendor" to any "go build" commands)
BUILD_FLAGS += -mod vendor
endif
#======================================
# Builds
#======================================
systeminfo := $(MODULE)/internal/system
$(targets): ## Build a target server binary
go build $(BUILD_FLAGS) -ldflags " \
-X '$(systeminfo).Version=$(VERSION)' \
-X '$(systeminfo).Commit=$(COMMIT)' \
-X '$(systeminfo).BuildTime=$(shell date -Iseconds)'" \
-o bin/$@ ./cmd/$@
$(SERVICES):
CGO_ENABLED=1 go build -ldflags " \
$(BUILD_FLAGS) -o ./bin/$@ ./cmd/$@
all: $(targets) ## Build all targets
#======================================
# Docker
#======================================
docker: ## build docker image
go mod tidy
$(docker_bin) login docker.io
$(docker_bin) build -t $(IMAGE) --build-arg target=nalpaca -f docker/Dockerfile .
$(docker_bin) push $(IMAGE)
composer := docker compose -f ./docker/compose.yaml
compose: ## build docker compose
$(composer) build
up: ## run docker compose
$(composer) up
down: ## teardown docker compose
$(composer) down
#======================================
# Running
#======================================
run-%: ## Run the server using .env variables
export $$(cat .env | xargs) && ./bin/$(patsubst run-%,%,$@)
#======================================
# Protobuf
#======================================
proto: ## buf generate
rm -rf gen
buf generate
#======================================
# App hygiene
#======================================
clean: ## gofmt, go generate, then go mod tidy, and finally rm -rf bin/
find . -iname *.go -type f -exec gofmt -w -s {} \;
go generate ./...
go mod tidy
rm -rf ./bin
test: ## Run go vet, then test all files
go vet ./...
$(test)
help: ## Print help
@printf "\033[36m%-30s\033[0m %s\n" "(target)" "Build a target binary in current arch for running locally: $(targets)"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'