github.com/anycable/anycable-go@v1.5.1/Makefile (about)

     1  OUTPUT ?= dist/anycable-go
     2  GOBENCHDIST ?= dist/gobench
     3  EMBEDDEDDIST ?= dist/embedded-cable
     4  
     5  export GO111MODULE=on
     6  
     7  MODIFIER ?= ""
     8  
     9  ifndef ANYCABLE_DEBUG
    10    export ANYCABLE_DEBUG=1
    11  endif
    12  
    13  ifndef ANYCABLE_DISABLE_TELEMETRY
    14    export ANYCABLE_DISABLE_TELEMETRY=true
    15  endif
    16  
    17  BUILD_ARGS ?=
    18  TEST_FLAGS=
    19  TEST_BUILD_FLAGS=
    20  
    21  ifdef COVERAGE
    22    TEST_FLAGS=-coverprofile=coverage.out
    23    TEST_BUILD_FLAGS=-cover
    24  	BUILD_ARGS += -cover
    25  endif
    26  
    27  # If port 6379 is listening, we assume that this is a Redis instance,
    28  # so we can use a Redis broadcast adapter.
    29  # Otherwise we fallback to HTTP adapter.
    30  ifndef ANYCABLE_BROADCAST_ADAPTER
    31  	ifndef REDIS_URL
    32  		HAS_REDIS := $(shell lsof -Pi :6379 -sTCP:LISTEN -t >/dev/null; echo $$?)
    33  		ifneq ($(HAS_REDIS), 0)
    34  			export ANYCABLE_BROADCAST_ADAPTER=http
    35  		endif
    36  	endif
    37  endif
    38  
    39  ifdef VERSION
    40  	LD_FLAGS="-s -w -X github.com/anycable/anycable-go/version.version=$(VERSION) -X github.com/anycable/anycable-go/version.modifier=$(MODIFIER)"
    41  else
    42  	COMMIT := $(shell sh -c 'git log --pretty=format:"%h" -n 1 ')
    43  	VERSION := $(shell sh -c 'git tag -l --sort=-version:refname "v*" | head -n1')
    44  	LD_FLAGS="-s -w -X github.com/anycable/anycable-go/version.sha=$(COMMIT) -X github.com/anycable/anycable-go/utils.version=$(VERSION) -X github.com/anycable/anycable-go/version.modifier=$(MODIFIER)"
    45  endif
    46  
    47  GOBUILD=go build -ldflags $(LD_FLAGS) -a
    48  
    49  MRUBY_VERSION=1.2.0
    50  
    51  current_dir = $(shell pwd)
    52  MRUBY_CONFIG ?= $(current_dir)/etc/build_config.rb
    53  
    54  # Standard build
    55  default: build
    56  
    57  # Install current version
    58  install:
    59  	go install ./...
    60  
    61  install-with-mruby:
    62  	go install -tags mrb ./...
    63  
    64  build:
    65  	go build $(BUILD_ARGS) -tags "mrb gops" -ldflags $(LD_FLAGS) -o $(OUTPUT) cmd/anycable-go/main.go
    66  
    67  build-gobench:
    68  	go build -tags "mrb gops" -ldflags $(LD_FLAGS) -o $(GOBENCHDIST) cmd/gobench-cable/main.go
    69  
    70  build-embedded:
    71  	go build -tags "mrb gops" -ldflags $(LD_FLAGS) -o $(EMBEDDEDDIST) cmd/embedded-cable/main.go
    72  
    73  download-mruby:
    74  	go mod download github.com/mitchellh/go-mruby
    75  
    76  prepare-mruby: download-mruby
    77  	cd $$(go list -m -f '{{.Dir}}' github.com/mitchellh/go-mruby) && \
    78  	MRUBY_COMMIT=$(MRUBY_VERSION) MRUBY_CONFIG=$(MRUBY_CONFIG) make libmruby.a || \
    79  	(sed -i '' 's/{ :verbose => $$verbose }/verbose: $$verbose/g' ./mruby-build/mruby/Rakefile && \
    80  		MRUBY_COMMIT=$(MRUBY_VERSION) MRUBY_CONFIG=$(MRUBY_CONFIG) make libmruby.a)
    81  
    82  upgrade-mruby: clean-mruby prepare-mruby
    83  
    84  clean-mruby:
    85  	cd $$(go list -m -f '{{.Dir}}' github.com/mitchellh/go-mruby) && \
    86  	rm -rf vendor/mruby
    87  
    88  build-all-mruby:
    89  	env $(GOBUILD) -tags mrb -o "dist/anycable-go-$(VERSION)-mrb-macos-amd64" cmd/anycable-go/main.go
    90  	docker run --rm -v $(PWD):/go/src/github.com/anycable/anycable-go -w /go/src/github.com/anycable/anycable-go -e OUTPUT="dist/anycable-go-$(VERSION)-mrb-linux-amd64" amd64/golang:1.11.4 make build
    91  
    92  build-clean:
    93  	rm -rf ./dist
    94  
    95  build-linux:
    96  	env GOOS=linux   GOARCH=amd64 $(GOBUILD) -o "dist/anycable-go-linux-amd64"   cmd/anycable-go/main.go
    97  	env GOOS=linux   GOARCH=arm64 $(GOBUILD) -o "dist/anycable-go-linux-arm64"   cmd/anycable-go/main.go
    98  
    99  build-all: build-clean build-linux
   100  	env GOOS=linux   GOARCH=arm   $(GOBUILD) -o "dist/anycable-go-linux-arm"     cmd/anycable-go/main.go
   101  	env GOOS=linux   GOARCH=arm64 $(GOBUILD) -o "dist/anycable-go-linux-arm64"   cmd/anycable-go/main.go
   102  	env GOOS=linux   GOARCH=amd64 $(GOBUILD) -o "dist/anycable-go-linux-amd64"   cmd/anycable-go/main.go
   103  	env GOOS=windows GOARCH=amd64 $(GOBUILD) -o "dist/anycable-go-win-amd64.exe" cmd/anycable-go/main.go
   104  	env GOOS=darwin  GOARCH=arm64 $(GOBUILD) -o "dist/anycable-go-darwin-arm64"  cmd/anycable-go/main.go
   105  	env GOOS=darwin  GOARCH=amd64 $(GOBUILD) -o "dist/anycable-go-darwin-amd64"  cmd/anycable-go/main.go
   106  	env GOOS=freebsd GOARCH=arm   $(GOBUILD) -o "dist/anycable-go-freebsd-arm"   cmd/anycable-go/main.go
   107  	env GOOS=freebsd GOARCH=amd64 $(GOBUILD) -o "dist/anycable-go-freebsd-amd64" cmd/anycable-go/main.go
   108  
   109  build-docker-local:
   110  	env GOOS=linux   GOARCH=arm64 $(GOBUILD) -o ".docker/linux/arm64/anycable-go"   cmd/anycable-go/main.go
   111  	docker buildx build --platform linux/arm64 --file .docker/Dockerfile.universal --tag anycable/anycable-go:$(subst v,,$(VERSION))-dev --load .
   112  	docker buildx build --platform linux/arm64 --file .docker/Dockerfile.alpine --tag anycable/anycable-go:$(subst v,,$(VERSION))-alpine-dev --load .
   113  
   114  # Run server
   115  run:
   116  	go run -ldflags $(LD_FLAGS) -tags "mrb gops" ./cmd/anycable-go/main.go
   117  
   118  run-gobench:
   119  	go run -ldflags $(LD_FLAGS) -tags "mrb gops" ./cmd/gobench-cable/main.go
   120  
   121  run-embedded:
   122  	go run -ldflags $(LD_FLAGS) -tags "mrb gops" ./cmd/embedded-cable/main.go
   123  
   124  build-protos:
   125  	protoc --proto_path=./etc --go_out=plugins=grpc:./protos --grpchan_out=./protos ./etc/rpc.proto
   126  
   127  bench:
   128  	go test -tags mrb -bench=. ./...
   129  
   130  test:
   131  	go test -count=1 -timeout=30s -race -tags mrb ./... $(TEST_FLAGS)
   132  
   133  benchmarks: build
   134  	ruby features/runner.rb features/*.benchfile
   135  
   136  tmp/anycable-go-test:
   137  	go build $(TEST_BUILD_FLAGS) -tags mrb -race -o tmp/anycable-go-test cmd/anycable-go/main.go
   138  
   139  tmp/anycable-embedded-test:
   140  	go build $(TEST_BUILD_FLAGS) -tags mrb -race -o tmp/anycable-embedded-test cmd/embedded-cable/main.go
   141  
   142  test-conformance: tmp/anycable-go-test
   143  	bundle exec anyt -c "tmp/anycable-go-test --headers=cookie,x-api-token" --target-url="ws://localhost:8080/cable"
   144  
   145  test-conformance-ssl: tmp/anycable-go-test
   146  	ANYCABLE_RPC_TLS_CERT=etc/ssl/server.crt \
   147  	ANYCABLE_RPC_TLS_KEY=etc/ssl/server.key \
   148  	bundle exec anyt -c \
   149  	"tmp/anycable-go-test --headers=cookie,x-api-token --rpc_enable_tls --rpc_tls_verify=false --ssl_key=etc/ssl/server.key --ssl_cert=etc/ssl/server.crt --port=8443" \
   150  	--target-url="wss://localhost:8443/cable"
   151  
   152  test-conformance-http: tmp/anycable-go-test
   153  	\
   154  	ANYCABLE_BROADCAST_ADAPTER=http ANYCABLE_HTTP_BROADCAST_SECRET=any_secret \
   155  	ANYCABLE_HTTP_RPC_SECRET=rpc_secret ANYCABLE_HTTP_RPC_MOUNT_PATH=/_anycable \
   156  	ANYCABLE_HTTP_BROADCAST_URL=http://localhost:8080/_broadcast \
   157  	bundle exec anyt -c "tmp/anycable-go-test --headers=cookie,x-api-token --rpc_host=http://localhost:9292/_anycable" --target-url="ws://localhost:8080/cable" --require=etc/anyt/broadcast_tests/*.rb
   158  
   159  test-conformance-nats: tmp/anycable-go-test
   160  	ANYCABLE_BROADCAST_ADAPTER=nats bundle exec anyt -c "tmp/anycable-go-test --headers=cookie,x-api-token" --target-url="ws://localhost:8080/cable" --require=etc/anyt/broadcast_tests/*.rb
   161  
   162  test-conformance-nats-embedded: tmp/anycable-go-test
   163  	ANYCABLE_BROADCAST_ADAPTER=nats ANYCABLE_NATS_SERVERS=nats://127.0.0.1:4242 ANYCABLE_EMBED_NATS=true ANYCABLE_ENATS_ADDR=nats://127.0.0.1:4242 bundle exec anyt -c "tmp/anycable-go-test --headers=cookie,x-api-token" --target-url="ws://localhost:8080/cable" --require=etc/anyt/broadcast_tests/*.rb
   164  
   165  test-conformance-broker-http: tmp/anycable-go-test
   166  	ANYCABLE_BROKER=memory ANYCABLE_BROADCAST_ADAPTER=http bundle exec anyt -c "tmp/anycable-go-test --headers=cookie,x-api-token" --target-url="ws://localhost:8080/cable" --require=etc/anyt/**/*.rb
   167  
   168  test-conformance-broker-redis: tmp/anycable-go-test
   169  	ANYCABLE_BROKER=memory ANYCABLE_BROADCAST_ADAPTER=redisx ANYCABLE_HTTP_BROADCAST_SECRET=any_secret ANYCABLE_PUBSUB=redis bundle exec anyt -c "tmp/anycable-go-test --headers=cookie,x-api-token" --target-url="ws://localhost:8080/cable" --require=etc/anyt/**/*.rb
   170  
   171  test-conformance-broker-nats: tmp/anycable-go-test
   172  	ANYCABLE_BROKER=nats ANYCABLE_EMBED_NATS=true ANYCABLE_ENATS_ADDR=nats://127.0.0.1:4343 ANYCABLE_PUBSUB=nats ANYCABLE_BROADCAST_ADAPTER=http bundle exec anyt -c "tmp/anycable-go-test --headers=cookie,x-api-token" --target-url="ws://localhost:8080/cable" --require=etc/anyt/**/*.rb
   173  
   174  test-conformance-embedded: tmp/anycable-embedded-test
   175  	\
   176  	ANYCABLE_BROADCAST_ADAPTER=http ANYCABLE_HTTP_BROADCAST_SECRET=any_secret \
   177  	ANYCABLE_HTTP_BROADCAST_URL=http://localhost:8080/broadcast \
   178  	ANYCABLE_HTTP_RPC_SECRET=rpc_secret ANYCABLE_HTTP_RPC_MOUNT_PATH=/_anycable \
   179  	ANYCABLE_RPC_HOST=http://localhost:9292/_anycable \
   180  	ANYCABLE_HEADERS=cookie,x-api-token \
   181  	bundle exec anyt -c "tmp/anycable-embedded-test" --target-url="ws://localhost:8080/cable" --require=etc/anyt/broadcast_tests/*.rb
   182  
   183  test-conformance-all: test-conformance test-conformance-ssl test-conformance-http test-conformance-embedded
   184  
   185  TESTFILE ?= features/*.testfile
   186  test-features: build
   187  	ruby features/runner.rb $(TESTFILE)
   188  
   189  test-ci: prepare prepare-mruby test test-conformance
   190  
   191  prepare:
   192  	bundle install
   193  
   194  gen-ssl:
   195  	mkdir -p tmp/ssl
   196  	openssl genrsa -out tmp/ssl/server.key 2048
   197  	openssl req -new -x509 -sha256 -key tmp/ssl/server.key -out tmp/ssl/server.crt -days 3650
   198  
   199  bin/golangci-lint:
   200  	@test -x $$(go env GOPATH)/bin/golangci-lint || \
   201  		curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.55.2
   202  
   203  lint: bin/golangci-lint
   204  	$$(go env GOPATH)/bin/golangci-lint run
   205  
   206  fmt:
   207  	go fmt ./...
   208  
   209  bin/go-licenses:
   210  	@which go-licenses &> /dev/null || \
   211  		env GO111MODULE=off go get -v github.com/google/go-licenses
   212  
   213  licenses: bin/go-licenses
   214  	@env GOFLAGS="-tags=mrb" $$(go env GOPATH)/bin/go-licenses csv github.com/anycable/anycable-go/cli 2>/dev/null | awk -F',' '{ print $$3 }' | sort | uniq | grep -v "Unknown"
   215  	@env GOFLAGS="-tags=mrb" $$(go env GOPATH)/bin/go-licenses csv github.com/anycable/anycable-go/cli 2>/dev/null | grep "Unknown" | grep -v "anycable-go" || echo "No unknown licenses 👌"
   216  
   217  .PHONY: tmp/anycable-go-test tmp/anycable-embedded-test vendor