forked from DIMO-Network/telemetry-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
94 lines (71 loc) · 3.51 KB
/
Makefile
File metadata and controls
94 lines (71 loc) · 3.51 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
87
88
89
90
91
92
93
94
.PHONY: clean run build install dep test lint format docker gqlgen
SHELL := /bin/sh
PATHINSTBIN = $(abspath ./bin)
export PATH := $(PATHINSTBIN):$(PATH)
BIN_NAME ?= telemetry-api
DEFAULT_INSTALL_DIR := $(go env GOPATH)/bin
DEFAULT_ARCH := $(shell go env GOARCH)
DEFAULT_GOOS := $(shell go env GOOS)
ARCH ?= $(DEFAULT_ARCH)
GOOS ?= $(DEFAULT_GOOS)
INSTALL_DIR ?= $(DEFAULT_INSTALL_DIR)
.DEFAULT_GOAL := run
VERSION := $(shell git describe --tags || echo "v0.0.0")
VER_CUT := $(shell echo $(VERSION) | cut -c2-)
# Dependency versions
GOLANGCI_VERSION = latest
MODEL_GARAGE_VERSION = $(shell go list -m -f '{{.Version}}' github.com/DIMO-Network/model-garage)
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 ""
build: ## Build the binary
@CGO_ENABLED=1 GOOS=$(GOOS) GOARCH=$(ARCH) \
go build -o $(PATHINSTBIN)/$(BIN_NAME) ./cmd/$(BIN_NAME)
run: build ## Run the binary
@./$(PATHINSTBIN)/$(BIN_NAME)
all: clean target
clean: ## Remove previous built binaries
@rm -rf $(PATHINSTBIN)
install: build
@install -d $(INSTALL_DIR)
@rm -f $(INSTALL_DIR)/$(BIN_NAME)
@cp $(PATHINSTBIN)/$(BIN_NAME) $(INSTALL_DIR)/$(BIN_NAME)
tidy: ## tidy go modules
@go mod tidy
test: ## Run tests
@go test -v ./...
lint: ## Run linter
@PATH=$$PATH golangci-lint run
docker: dep
@docker build -f ./Dockerfile . -t dimozone/$(BIN_NAME):$(VER_CUT)
@docker tag dimozone/$(BIN_NAME):$(VER_CUT) dimozone/$(BIN_NAME):latest
# Build multi-arch (amd64 + arm64) and push with a random tag. Does not trigger GitHub workflows.
# Requires: docker buildx, docker login. Run from repo root.
docker-push-multiarch:
$(eval TAG := dev-$(shell openssl rand -hex 6))
@echo "Building and pushing dimozone/$(BIN_NAME):$(TAG) (linux/amd64, linux/arm64)"
@docker buildx build --platform linux/amd64,linux/arm64 -f ./Dockerfile --push -t dimozone/$(BIN_NAME):$(TAG) .
@echo "Pushed dimozone/$(BIN_NAME):$(TAG)"
# Same as docker-push-multiarch but using podman (manifest list + manifest push --all).
podman-push-multiarch:
$(eval TAG := dev-$(shell openssl rand -hex 6))
$(eval IMAGE := dimozone/$(BIN_NAME):$(TAG))
@echo "Building and pushing $(IMAGE) (linux/amd64, linux/arm64)"
@podman build --platform linux/amd64,linux/arm64 --manifest $(IMAGE) -f ./Dockerfile .
@podman manifest push --all $(IMAGE) docker://$(IMAGE)
@echo "Pushed $(IMAGE)"
gqlgen: ## Generate gqlgen code.
@go tool gqlgen generate
gql-model: ## Generate gqlgen data model.
@go tool codegen -generators=custom -custom.output-file=schema/signals-events_gen.graphqls -custom.template-file=./schema/signals-events.tmpl
@go tool codegen -generators=custom -custom.output-file=internal/graph/model/signalSetter_gen.go -custom.template-file=./internal/graph/model/signalSetter.tmpl -custom.format=true
@go tool codegen -generators=custom -custom.output-file=internal/graph/signals-events_gen.resolvers.go -custom.template-file=./internal/graph/signals-events_gen.resolvers.tmpl -custom.format=true
gql: gql-model gqlgen ## Generate all gql code.
generate: gql generate-go ## Runs all code generators for the repository.
generate-go: ## Generate go code.
@go generate ./...
tools-golangci-lint: ## install golangci-lint tool
@mkdir -p $(PATHINSTBIN)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(PATHINSTBIN) $(GOLANGCI_VERSION)
tools: tools-golangci-lint ## Install all tools required for development.