-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
108 lines (87 loc) · 3.48 KB
/
Makefile
File metadata and controls
108 lines (87 loc) · 3.48 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
.PHONY: all build clean test lint proto docker-build docker-push help
# ============================================================
# Variables
# ============================================================
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
REGISTRY ?= ghcr.io/layfz/maas-cloud-api
SERVICES := auth core billing syncer adapter
LDFLAGS := -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.buildTime=$(BUILD_TIME)
# ============================================================
# Build
# ============================================================
all: build
build: $(addprefix build-,$(SERVICES))
build-%:
@echo "==> Building $*..."
CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o bin/$* ./cmd/$*/
clean:
rm -rf bin/
# ============================================================
# Test & Lint
# ============================================================
test:
go test ./... -race -coverprofile=coverage.out -covermode=atomic
@echo "==> Coverage report: go tool cover -html=coverage.out"
lint:
golangci-lint run ./...
# ============================================================
# Proto
# ============================================================
proto:
@echo "==> Generating protobuf code..."
./scripts/gen-proto.sh
# ============================================================
# Docker
# ============================================================
docker-build: $(addprefix docker-build-,$(SERVICES))
docker-build-%:
@echo "==> Building Docker image for $*..."
docker build \
--build-arg SERVICE=$* \
--build-arg LDFLAGS="$(LDFLAGS)" \
-t $(REGISTRY)/$*:$(VERSION) \
-f deploy/docker/Dockerfile .
docker-push: $(addprefix docker-push-,$(SERVICES))
docker-push-%:
docker push $(REGISTRY)/$*:$(VERSION)
# ============================================================
# Wasm Plugin
# ============================================================
wasm-build:
@echo "==> Building Wasm plugin..."
cd plugin/usage-reporter && GOOS=wasip1 GOARCH=wasm go build -o main.wasm .
wasm-docker:
docker build -t $(REGISTRY)/usage-reporter:$(VERSION) plugin/usage-reporter/
docker push $(REGISTRY)/usage-reporter:$(VERSION)
# ============================================================
# Dev
# ============================================================
dev-auth:
ANYFAST_SERVER_HTTP_PORT=8080 ANYFAST_SERVER_GRPC_PORT=50051 go run ./cmd/auth/
dev-core:
ANYFAST_SERVER_HTTP_PORT=8081 ANYFAST_SERVER_GRPC_PORT=50052 go run ./cmd/core/
dev-billing:
go run ./cmd/billing/
dev-syncer:
go run ./cmd/syncer/
dev-adapter:
ANYFAST_SERVER_HTTP_PORT=8082 go run ./cmd/adapter/
migrate:
go run ./scripts/migrate.go
# ============================================================
# Help
# ============================================================
help:
@echo "Usage:"
@echo " make build - Build all services"
@echo " make build-auth - Build single service"
@echo " make test - Run tests with coverage"
@echo " make lint - Run linter"
@echo " make proto - Generate protobuf code"
@echo " make docker-build - Build all Docker images"
@echo " make docker-push - Push all Docker images"
@echo " make wasm-build - Build Wasm plugin"
@echo " make dev-auth - Run auth service locally"
@echo " make migrate - Run database migrations"