Skip to content
File

Blob: Makefile

makefile242 lines
1PLATFORMS := windows/amd64/.exe linux/amd64 darwin/amd64 illumos/amd64 windows/arm64/.exe android/arm64 linux/arm64 darwin/arm64 linux/arm freebsd/amd64
2BUILD := $(shell git rev-parse --short HEAD)
3BUILT_TIME := $(shell date +%s)
4 
5PB_REL="https://github.com/protocolbuffers/protobuf/releases"
6PROTOC_VERSION=34.0
7PROTOC_GO=`which protoc-gen-go`
8PROTOC_TWIRP=`which protoc-gen-twirp`
9PROTOC_VTPROTO=`which protoc-gen-go-vtproto`
10 
11COUNT=3
12GOARM=7
13GOAMD64=v3
14GOTAGS=-tags 'osusergo netgo no_mocks' -trimpath
15LDFLAGS=-ldflags "-s -w -extldflags -static -X go.miragespace.co/specter/spec.BuildVersion=$(BUILD) -X go.miragespace.co/specter/spec.BuildTime=$(BUILT_TIME)"
16TIMEOUT=180s
17PACKAGE_VERSION ?= 0.0.0
18PACKAGE_RELEASE ?= edge.$(BUILD)
19 
20plat_temp = $(subst /, ,$@)
21os = $(word 1, $(plat_temp))
22arch = $(word 2, $(plat_temp))
23ext = $(word 3, $(plat_temp))
24 
25.DEFAULT_GOAL := all
26 
27# ==========================DEV===========================
28 
29build-dev: certs
30 docker build -t specter-dev -f Dockerfile.dev .
31 
32dev-server: build-dev
33 SKIP=" " docker compose -f compose-server.yaml up
34 
35dev-server-acme:build-dev
36 docker compose -f compose-server.yaml up
37 
38dev-client: build-dev
39 docker compose -f compose-client.yaml up
40 
41dev-server-logs:
42 docker compose -f compose-server.yaml logs -f
43 
44yeet-server:
45 docker compose -f compose-server.yaml down
46 docker compose -f compose-server.yaml stop
47 docker compose -f compose-server.yaml rm
48 
49yeet-server-all: yeet-server
50 docker compose -f compose-server.yaml down -v
51 
52yeet-client:
53 docker compose -f compose-client.yaml down
54 docker compose -f compose-client.yaml stop
55 docker compose -f compose-client.yaml rm
56 
57yeet-validator:
58 docker compose -f compose-validator.yaml down
59 docker compose -f compose-validator.yaml stop
60 docker compose -f compose-validator.yaml rm
61 
62prune:
63 docker image prune -f
64 docker volume prune -f
65 
66buildx-validator:
67 docker buildx build -t validator -f Dockerfile.validator .
68 
69dev-validate: buildx-validator
70 docker compose -f compose-validator.yaml up --abort-on-container-exit --exit-code-from validator
71 
72# ========================================================
73 
74all: proto test clean release
75 
76release: $(PLATFORMS)
77 
78package-linux: linux/amd64 linux/arm64 linux/arm
79 PACKAGE_VERSION=$(PACKAGE_VERSION) PACKAGE_RELEASE=$(PACKAGE_RELEASE) sh scripts/package-linux.sh
80 
81package-freebsd:
82 @echo "freebsd packaging is currently unsupported" >&2
83 @exit 1
84 
85package-illumos:
86 @echo "illumos packaging is currently unsupported" >&2
87 @exit 1
88 
89packages: package-linux
90 
91compat: GOAMD64 = v1
92compat: GOARM = 6
93compat: ext = -compat$(word 3, $(plat_temp))
94compat: release
95 
96$(PLATFORMS):
97 CGO_ENABLED=0 GOOS=$(os) GOARCH=$(arch) GOARM=$(GOARM) GOAMD64=$(GOAMD64) go build $(GOTAGS) $(LDFLAGS) -o bin/specter-$(os)-$(arch)$(ext) .
98ifdef wal
99 CGO_ENABLED=0 GOOS=$(os) GOARCH=$(arch) GOARM=$(GOARM) GOAMD64=$(GOAMD64) go build $(GOTAGS) $(LDFLAGS) -o bin/wal-$(os)-$(arch)$(ext) ./cmd/wal
100endif
101 
102upx: release
103 -find ./bin -type f -exec upx --best --lzma {} +
104 
105DOCKER_TAG ?= miragespace/specter
106docker:
107 docker buildx build --platform linux/amd64,linux/amd64/v3,linux/arm64,linux/arm,linux/ppc64le,linux/s390x -t $(DOCKER_TAG):$(BUILD) --push -f Dockerfile .
108 
109ui:
110 cd ui && npm ci --ignore-scripts && npm run check && npm run build
111 
112proto: dep
113 dep/bin/protoc \
114 --plugin protoc-gen-go-vtproto="$(PROTOC_VTPROTO)" \
115 --plugin protoc-gen-twirp="$(PROTOC_TWIRP)" \
116 --plugin protoc-gen-go="$(PROTOC_GO)" \
117 --go_out=. \
118 --twirp_out=. \
119 --go-vtproto_out=. \
120 --go_opt=module=go.miragespace.co/specter \
121 --twirp_opt=module=go.miragespace.co/specter \
122 --go-vtproto_opt=module=go.miragespace.co/specter \
123 --go-vtproto_opt=features=marshal+unmarshal+size \
124 ./spec/proto/*.proto
125 for twirp in ./spec/protocol/*.twirp.go; \
126 do \
127 echo 'Updating' $${twirp}; \
128 sed -i -e 's/respBytes, err := proto.Marshal(respContent)/respBytes, err := respContent.MarshalVT()/g' $${twirp}; \
129 sed -i -e 's/if err = proto.Unmarshal(buf, reqContent); err != nil {/if err = reqContent.UnmarshalVT(buf); err != nil {/g' $${twirp}; \
130 done;
131 git apply spec/vt.patch
132 
133proto_aof_kv: dep
134 dep/bin/protoc \
135 --go_opt=module=go.miragespace.co/specter \
136 --go-vtproto_opt=module=go.miragespace.co/specter \
137 --go_out=. --plugin protoc-gen-go="$(PROTOC_GO)" \
138 --go-vtproto_out=. --plugin protoc-gen-go-vtproto="$(PROTOC_VTPROTO)" \
139 --go-vtproto_opt=features=marshal+unmarshal+size+pool \
140 --go-vtproto_opt=pool=go.miragespace.co/specter/kv/aof/proto.Mutation \
141 --go-vtproto_opt=pool=go.miragespace.co/specter/kv/aof/proto.LogEntry \
142 ./kv/aof/proto/*.proto
143 
144benchmark_kv:
145 go test -benchmem -bench=. -benchtime=10s -cpu 1,2,4 ./kv
146 
147dep:
148 -mkdir dep/
149 (cd dep/ && curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-linux-x86_64.zip)
150 (cd dep/ && unzip protoc-$(PROTOC_VERSION)-linux-x86_64.zip)
151 go install golang.org/x/tools/cmd/stringer@latest
152 go install github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto@latest
153 go install github.com/twitchtv/twirp/protoc-gen-twirp@latest
154 go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
155 
156vet:
157 go vet ./...
158 staticcheck ./...
159 
160full_test: test extended_test long_test concurrency_test
161 
162integration_test: certs run_integration
163 
164test:
165 go test -short -cover -count=1 -timeout 60s ./...
166 go test -short -race -cover -count=1 -timeout 60s ./...
167 
168extended_test:
169 go test -short -race -count=$(COUNT) -timeout 300s ./...
170 
171long_test:
172 go test -timeout $(TIMEOUT) -run ^TestLotsOfNodes -race -count=1 ./chord/...
173 
174concurrency_test:
175 go test -timeout $(TIMEOUT) -run ^TestConcurrentJoin -count=$(COUNT) -parallel=$$(expr $$(nproc) - 1) ./chord/...
176 go test -timeout $(TIMEOUT) -run ^TestConcurrentLeave -count=$(COUNT) -parallel=$$(expr $$(nproc) - 1) ./chord/...
177 
178coverage:
179 GO_INTEGRATION_ACME=1 go test -timeout $(TIMEOUT) -coverprofile=cover.out -covermode=count ./...
180 
181run_integration:
182 GO_INTEGRATION_ACME=1 GO_INTEGRATION_TUNNEL=1 go test -timeout $(TIMEOUT) -race -v -count=1 -run ^TestIntegration ./...
183 
184clean:
185 -rm bin/*
186 -rm -rf dist
187 -rm cover.out
188 
189certs:
190 mkdir certs
191 # Create CA key
192 openssl ecparam -name prime256v1 -genkey -noout -out certs/ca.key
193 # Generate CA CSR
194 openssl req -new -key certs/ca.key -out certs/ca.csr -subj "/C=US/ST=California/L=San Francisco/O=Dev/OU=Dev/CN=ca.dev"
195 # Verify CA CSR
196 openssl req -text -in certs/ca.csr -noout -verify
197 # Generate self-signed CA
198 openssl x509 -signkey certs/ca.key -in certs/ca.csr -req -days 365 -out certs/ca.crt
199 # Generate node key
200 openssl ecparam -name prime256v1 -genkey -noout -out certs/node.key
201 # Generate node CSR
202 openssl req -new -key certs/node.key -out certs/node.csr -subj "/C=US/ST=California/L=San Francisco/O=Dev/OU=Dev/CN=node.ca.dev"
203 # Verify node CSR
204 openssl req -text -in certs/node.csr -noout -verify
205 # Sign and generate node certificate
206 openssl x509 -req -CA certs/ca.crt -CAkey certs/ca.key -in certs/node.csr -out certs/node.crt -days 365 -CAcreateserial -extfile dev/openssl.txt
207 # Create Client CA
208 go run ./cmd/pki/ca
209 # Generate pebble test cert
210 openssl ecparam -name prime256v1 -genkey -noout -out certs/pebble.key
211 openssl req -new -key certs/pebble.key -out certs/pebble.csr -subj "/CN=pebble" -addext "subjectAltName = DNS:localhost, DNS:pebble, IP:127.0.0.1"
212 openssl req -text -in certs/pebble.csr -noout -verify
213 openssl x509 -req -CA dev/pebble/certs/cert.pem -CAkey dev/pebble/certs/key.pem -in certs/pebble.csr -out certs/pebble.pem -days 365 -CAcreateserial -extfile dev/openssl_pebble.txt
214 
215fly_deploy:
216 flyctl deploy --build-arg GIT_HASH=$$(git rev-parse --short HEAD)
217 
218fly_certs:
219 mkdir fly
220 openssl ecparam -name prime256v1 -genkey -noout -out fly/ca.key
221 openssl req -new -key fly/ca.key -out fly/ca.csr -subj "/C=US/ST=California/L=San Francisco/O=Dev/OU=Dev/CN=ca.dev"
222 openssl req -text -in fly/ca.csr -noout -verify
223 openssl x509 -signkey fly/ca.key -in fly/ca.csr -req -days 3650 -out fly/ca.crt
224 openssl ecparam -name prime256v1 -genkey -noout -out fly/node.key
225 openssl req -new -key fly/node.key -out fly/node.csr -subj "/C=US/ST=California/L=San Francisco/O=Dev/OU=Dev/CN=node.ca.dev"
226 openssl req -text -in fly/node.csr -noout -verify
227 openssl x509 -req -CA fly/ca.crt -CAkey fly/ca.key -in fly/node.csr -out fly/node.crt -days 3650 -CAcreateserial -extfile fly.txt
228 go run ./cmd/pki/ca -certs fly
229 flyctl secrets set \
230 CERT_CA=$$(cat fly/ca.crt | openssl enc -A -base64) \
231 CERT_CLIENT_CA=$$(cat fly/client-ca.crt | openssl enc -A -base64) \
232 CERT_CLIENT_CA_KEY=$$(cat fly/client-ca.key | openssl enc -A -base64) \
233 CERT_NODE=$$(cat fly/node.crt | openssl enc -A -base64) \
234 CERT_NODE_KEY=$$(cat fly/node.key | openssl enc -A -base64)
235 
236licenses:
237 go-licenses save go.miragespace.co/specter --save_path=./licenses
238 find ./licenses -type f -exec tail -n +1 {} + > ThirdPartyLicenses.txt
239 -rm -rf ./licenses
240 
241.PHONY: all release compat package-linux package-freebsd package-illumos packages clean ui