-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
133 lines (103 loc) · 4.58 KB
/
Makefile
File metadata and controls
133 lines (103 loc) · 4.58 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Heavily inspired by Lighthouse: https://github.com/sigp/lighthouse/blob/stable/Makefile
# and Reth: https://github.com/paradigmxyz/reth/blob/main/Makefile
.DEFAULT_GOAL := help
VERSION := $(shell git describe --tags --always --dirty="-dev")
# Admin API auth for curl examples (set ADMIN_AUTH="admin:secret" or similar. can be empty when server is run with --disable-admin-auth)
ADMIN_AUTH ?=
CURL ?= curl -v
CURL_AUTH := $(if $(ADMIN_AUTH),-u $(ADMIN_AUTH),)
# A few colors
RED:=\033[0;31m
BLUE:=\033[0;34m
GREEN:=\033[0;32m
NC:=\033[0m
##@ Help
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: v
v: ## Show the version
@echo "Version: ${VERSION}"
##@ Build
.PHONY: clean
clean: ## Clean the build directory
rm -rf build/
.PHONY: build
build: ## Build the HTTP server
@mkdir -p ./build
go build -trimpath -ldflags "-X github.com/flashbots/builder-hub/common.Version=${VERSION}" -v -o ./build/builder-hub cmd/httpserver/main.go
##@ Test & Development
.PHONY: dev-postgres-up
dev-postgres-up: ## Start the PostgreSQL database for development
docker run -d --name postgres-test -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=postgres postgres
for file in schema/*.sql; do psql "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable" -f $file; done
.PHONY: dev-postgres-down
dev-postgres-down: ## Stop the PostgreSQL database for development
docker rm -f postgres-test
.PHONY: dev-docker-compose-up
dev-docker-compose-up: ## Start Docker compose
docker compose -f docker/docker-compose.yaml build
docker compose -f docker/docker-compose.yaml up -d
.PHONY: dev-docker-compose-down
dev-docker-compose-down: ## Stop Docker compose
docker compose -f docker/docker-compose.yaml down
.PHONY: dev-docker-compose-restart
dev-docker-compose-restart: dev-docker-compose-down dev-docker-compose-up
.PHONY: lt
lt: lint test ## Run linters and tests (always do this!)
.PHONY: fmt
fmt: ## Format the code (use this often)
gofmt -s -w .
gci write .
gofumpt -w -extra .
go mod tidy
.PHONY: test
test: ## Run tests
go test -race ./...
.PHONY: test-with-db
test-with-db: ## Run tests including live database tests
RUN_DB_TESTS=1 go test -race ./...
.PHONY: lint
lint: ## Run linters
gofmt -d -s .
gofumpt -d -extra .
go vet ./...
staticcheck ./...
golangci-lint run
.PHONY: gofumpt
gofumpt: ## Run gofumpt
gofumpt -l -w -extra .
.PHONY: cover
cover: ## Run tests with coverage
go test -coverprofile=/tmp/go-sim-lb.cover.tmp ./...
go tool cover -func /tmp/go-sim-lb.cover.tmp
unlink /tmp/go-sim-lb.cover.tmp
.PHONY: cover-html
cover-html: ## Run tests with coverage and open the HTML report
go test -coverprofile=/tmp/go-sim-lb.cover.tmp ./...
go tool cover -html=/tmp/go-sim-lb.cover.tmp
unlink /tmp/go-sim-lb.cover.tmp
.PHONY: docker-httpserver
docker-httpserver: ## Build the HTTP server Docker image
DOCKER_BUILDKIT=1 docker build \
--file docker/httpserver/Dockerfile \
--platform linux/amd64 \
--build-arg VERSION=${VERSION} \
--tag builder-hub \
.
.PHONY: db-dump
db-dump: ## Dump the database contents to file 'database.dump'
pg_dump -h localhost -U postgres --column-inserts --data-only postgres -f database.dump
@printf "Database dumped to file: $(GREEN)database.dump$(NC) ✅\n"
.PHONY: dev-db-setup
dev-db-setup: ## Create the basic database entries for testing and development
@printf "$(BLUE)Create the allow-all measurements $(NC)\n"
$(CURL) $(CURL_AUTH) --request POST --url http://localhost:8081/api/admin/v1/measurements --data '{"measurement_id": "test1","attestation_type": "test","measurements": {}}'
@printf "$(BLUE)Enable the measurements $(NC)\n"
$(CURL) $(CURL_AUTH) --request POST --url http://localhost:8081/api/admin/v1/measurements/activation/test1 --data '{"enabled": true}'
@printf "$(BLUE)Create the builder $(NC)\n"
$(CURL) $(CURL_AUTH) --request POST --url http://localhost:8081/api/admin/v1/builders --data '{"name": "test_builder","ip_address": "1.2.3.4", "network": "production"}'
@printf "$(BLUE)Create the builder configuration $(NC)\n"
$(CURL) $(CURL_AUTH) --request POST --url http://localhost:8081/api/admin/v1/builders/configuration/test_builder --data '{"dns_name": "foobar-v1.a.b.c","rbuilder": {"extra_data": "FooBar"}}'
@printf "$(BLUE)Enable the builder $(NC)\n"
$(CURL) $(CURL_AUTH) --request POST --url http://localhost:8081/api/admin/v1/builders/activation/test_builder --data '{"enabled": true}'