Skip to content
File

Blob: Makefile

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