File
Blob: Makefile
| 1 | PLATFORMS := windows/amd64/.exe linux/amd64 darwin/amd64 illumos/amd64 windows/arm64/.exe android/arm64 linux/arm64 darwin/arm64 linux/arm freebsd/amd64 |
| 2 | BUILD := $(shell git rev-parse --short HEAD) |
| 3 | BUILT_TIME := $(shell date +%s) |
| 4 | |
| 5 | PB_REL="https://github.com/protocolbuffers/protobuf/releases" |
| 6 | PROTOC_VERSION=34.0 |
| 7 | PROTOC_GO=`which protoc-gen-go` |
| 8 | PROTOC_TWIRP=`which protoc-gen-twirp` |
| 9 | PROTOC_VTPROTO=`which protoc-gen-go-vtproto` |
| 10 | |
| 11 | COUNT=3 |
| 12 | GOARM=7 |
| 13 | GOAMD64=v3 |
| 14 | GOTAGS=-tags 'osusergo netgo no_mocks' -trimpath |
| 15 | LDFLAGS=-ldflags "-s -w -extldflags -static -X go.miragespace.co/specter/spec.BuildVersion=$(BUILD) -X go.miragespace.co/specter/spec.BuildTime=$(BUILT_TIME)" |
| 16 | TIMEOUT=180s |
| 17 | PACKAGE_VERSION ?= 0.0.0 |
| 18 | PACKAGE_RELEASE ?= edge.$(BUILD) |
| 19 | |
| 20 | plat_temp = $(subst /, ,$@) |
| 21 | os = $(word 1, $(plat_temp)) |
| 22 | arch = $(word 2, $(plat_temp)) |
| 23 | ext = $(word 3, $(plat_temp)) |
| 24 | |
| 25 | .DEFAULT_GOAL := all |
| 26 | |
| 27 | # ==========================DEV=========================== |
| 28 | |
| 29 | build-dev: certs |
| 30 | docker build -t specter-dev -f Dockerfile.dev . |
| 31 | |
| 32 | dev-server: build-dev |
| 33 | SKIP=" " docker compose -f compose-server.yaml up |
| 34 | |
| 35 | dev-server-acme:build-dev |
| 36 | docker compose -f compose-server.yaml up |
| 37 | |
| 38 | dev-client: build-dev |
| 39 | docker compose -f compose-client.yaml up |
| 40 | |
| 41 | dev-server-logs: |
| 42 | docker compose -f compose-server.yaml logs -f |
| 43 | |
| 44 | yeet-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 | |
| 49 | yeet-server-all: yeet-server |
| 50 | docker compose -f compose-server.yaml down -v |
| 51 | |
| 52 | yeet-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 | |
| 57 | yeet-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 | |
| 62 | prune: |
| 63 | docker image prune -f |
| 64 | docker volume prune -f |
| 65 | |
| 66 | buildx-validator: |
| 67 | docker buildx build -t validator -f Dockerfile.validator . |
| 68 | |
| 69 | dev-validate: buildx-validator |
| 70 | docker compose -f compose-validator.yaml up --abort-on-container-exit --exit-code-from validator |
| 71 | |
| 72 | # ======================================================== |
| 73 | |
| 74 | all: proto test clean release |
| 75 | |
| 76 | release: $(PLATFORMS) |
| 77 | |
| 78 | package-linux: linux/amd64 linux/arm64 linux/arm |
| 79 | PACKAGE_VERSION=$(PACKAGE_VERSION) PACKAGE_RELEASE=$(PACKAGE_RELEASE) sh scripts/package-linux.sh |
| 80 | |
| 81 | package-freebsd: |
| 82 | @echo "freebsd packaging is currently unsupported" >&2 |
| 83 | @exit 1 |
| 84 | |
| 85 | package-illumos: |
| 86 | @echo "illumos packaging is currently unsupported" >&2 |
| 87 | @exit 1 |
| 88 | |
| 89 | packages: package-linux |
| 90 | |
| 91 | compat: GOAMD64 = v1 |
| 92 | compat: GOARM = 6 |
| 93 | compat: ext = -compat$(word 3, $(plat_temp)) |
| 94 | compat: 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) . |
| 98 | ifdef 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 |
| 100 | endif |
| 101 | |
| 102 | upx: release |
| 103 | -find ./bin -type f -exec upx --best --lzma {} + |
| 104 | |
| 105 | DOCKER_TAG ?= miragespace/specter |
| 106 | docker: |
| 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 | |
| 109 | ui: |
| 110 | cd ui && npm ci --ignore-scripts && npm run check && npm run build |
| 111 | |
| 112 | proto: 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 | |
| 133 | proto_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 | |
| 144 | benchmark_kv: |
| 145 | go test -benchmem -bench=. -benchtime=10s -cpu 1,2,4 ./kv |
| 146 | |
| 147 | dep: |
| 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 | |
| 156 | vet: |
| 157 | go vet ./... |
| 158 | staticcheck ./... |
| 159 | |
| 160 | full_test: test extended_test long_test concurrency_test |
| 161 | |
| 162 | integration_test: certs run_integration |
| 163 | |
| 164 | test: |
| 165 | go test -short -cover -count=1 -timeout 60s ./... |
| 166 | go test -short -race -cover -count=1 -timeout 60s ./... |
| 167 | |
| 168 | extended_test: |
| 169 | go test -short -race -count=$(COUNT) -timeout 300s ./... |
| 170 | |
| 171 | long_test: |
| 172 | go test -timeout $(TIMEOUT) -run ^TestLotsOfNodes -race -count=1 ./chord/... |
| 173 | |
| 174 | concurrency_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 | |
| 178 | coverage: |
| 179 | GO_INTEGRATION_ACME=1 go test -timeout $(TIMEOUT) -coverprofile=cover.out -covermode=count ./... |
| 180 | |
| 181 | run_integration: |
| 182 | GO_INTEGRATION_ACME=1 GO_INTEGRATION_TUNNEL=1 go test -timeout $(TIMEOUT) -race -v -count=1 -run ^TestIntegration ./... |
| 183 | |
| 184 | clean: |
| 185 | -rm bin/* |
| 186 | -rm -rf dist |
| 187 | -rm cover.out |
| 188 | |
| 189 | certs: |
| 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 | |
| 215 | fly_deploy: |
| 216 | flyctl deploy --build-arg GIT_HASH=$$(git rev-parse --short HEAD) |
| 217 | |
| 218 | fly_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 | |
| 236 | licenses: |
| 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 |