1SOURCE = $(shell ls -1 *.go | grep -v _test.go) 2SOURCE_PATH = /go/src/github.com/buger/goreplay/ 3PORT = 8000 4FADDR = :8000 5CONTAINER=gor 6PREFIX= 7RUN = docker run -v `pwd`:$(SOURCE_PATH) -e AWS_ACCESS_KEY_ID=$(AWS_ACCESS_KEY_ID) -e AWS_SECRET_ACCESS_KEY=$(AWS_SECRET_ACCESS_KEY) -p 0.0.0.0:$(PORT):$(PORT) -t -i $(CONTAINER) 8BENCHMARK = BenchmarkRAWInput 9TEST = TestRawListenerBench 10BIN_NAME = gor 11VERSION = DEV-$(shell date +%s) 12LDFLAGS = -ldflags "-X main.VERSION=$(VERSION)$(PREFIX) -extldflags \"-static\" -X main.DEMO=$(DEMO)" 13MAC_LDFLAGS = -ldflags "-X main.VERSION=$(VERSION)$(PREFIX) -X main.DEMO=$(DEMO)" 14FADDR = ":8000" 15 16FPMCOMMON= \ 17 --name goreplay \ 18 --description "GoReplay is an open-source network monitoring tool which can record your live traffic, and use it for shadowing, load testing, monitoring and detailed analysis." \ 19 -v $(VERSION) \ 20 --vendor "Leonid Bugaev" \ 21 -m "<support@goreplay.org>" \ 22 --url "https://goreplay.org" \ 23 -s dir \ 24 -C /tmp/gor-build \ 25 26release: release-x64 release-mac 27 28release-bin: 29 docker run -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=amd64 -i $(CONTAINER) go build -o $(BIN_NAME) -tags netgo $(LDFLAGS) 30 31release-bin-mac: 32 GOOS=darwin go build -o $(BIN_NAME) $(MAC_LDFLAGS) 33 34release-x64: 35 docker run -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=amd64 -i $(CONTAINER) go build -o $(BIN_NAME) -tags netgo $(LDFLAGS) 36 tar -czf gor_$(VERSION)$(PREFIX)_x64.tar.gz $(BIN_NAME) 37 mkdir -p /tmp/gor-build 38 mv ./$(BIN_NAME) /tmp/gor-build/$(BIN_NAME) 39 cd /tmp/gor-build 40 rm -f goreplay_$(VERSION)_amd64.deb 41 rm -f goreplay-$(VERSION)-1.x86_64.rpm 42 fpm $(FPMCOMMON) -a amd64 -t deb ./=/usr/local/bin 43 fpm $(FPMCOMMON) -a amd64 -t rpm ./=/usr/local/bin 44 rm -rf /tmp/gor-build 45 46release-x86: 47 docker run -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=386 -i $(CONTAINER) go build -o $(BIN_NAME) -tags netgo $(LDFLAGS) 48 tar -czf gor_$(VERSION)$(PREFIX)_x86.tar.gz $(BIN_NAME) 49 rm $(BIN_NAME) 50 51release-mac: 52 go build -o $(BIN_NAME) $(MAC_LDFLAGS) 53 tar -czf gor_$(VERSION)$(PREFIX)_mac.tar.gz $(BIN_NAME) 54 mkdir -p /tmp/gor-build 55 mv ./$(BIN_NAME) /tmp/gor-build/$(BIN_NAME) 56 cd /tmp/gor-build 57 rm -f goreplay-$(VERSION).pkg 58 fpm $(FPMCOMMON) -a amd64 -t osxpkg ./=/usr/local/bin 59 rm -rf /tmp/gor-build 60 61 62install: 63 go install $(MAC_LDFLAGS) 64 65build: 66 docker build -t $(CONTAINER) -f Dockerfile.dev . 67 68profile: 69 go build && ./$(BIN_NAME) --output-http="http://localhost:9000" --input-dummy 0 --input-raw :9000 --input-http :9000 --memprofile=./mem.out --cpuprofile=./cpu.out --stats --output-http-stats --output-http-timeout 100ms 70 71lint: 72 $(RUN) golint $(PKG) 73 74race: 75 $(RUN) go test ./... $(ARGS) -v -race -timeout 15s 76 77test: 78 $(RUN) go test ./. -timeout 120s $(LDFLAGS) $(ARGS) -v 79 80test_all: 81 $(RUN) go test ./... -timeout 120s $(LDFLAGS) $(ARGS) -v 82 83testone: 84 $(RUN) go test ./. -timeout 60s $(LDFLAGS) -run $(TEST) $(ARGS) -v 85 86cover: 87 $(RUN) go test $(ARGS) -race -v -timeout 15s -coverprofile=coverage.out 88 go tool cover -html=coverage.out 89 90fmt: 91 $(RUN) gofmt -w -s ./.. 92 93vet: 94 $(RUN) go vet 95 96bench: 97 $(RUN) go test $(LDFLAGS) -v -run NOT_EXISTING -bench $(BENCHMARK) -benchtime 5s 98 99profile_test: 100 $(RUN) go test $(LDFLAGS) -run $(TEST) ./capture/. $(ARGS) -memprofile mem.mprof -cpuprofile cpu.out 101 $(RUN) go test $(LDFLAGS) -run $(TEST) ./capture/. $(ARGS) -c 102 103# Used mainly for debugging, because docker container do not have access to parent machine ports 104run: 105 $(RUN) go run $(LDFLAGS) $(SOURCE) --input-dummy=0 --output-http="http://localhost:9000" --input-raw-track-response --input-raw 127.0.0.1:9000 --verbose --debug --middleware "./examples/middleware/echo.sh" --output-file requests.gor 106 107run-2: 108 $(RUN) go run $(LDFLAGS) $(SOURCE) --input-raw :8000 --input-raw-bpf-filter "dst port 8000" --output-stdout --output-http "http://localhost:8000" --input-dummy=0 109 110run-3: 111 sudo -E go run $(SOURCE) --input-tcp :27001 --output-stdout 112 113run-arg: 114 sudo -E go run $(SOURCE) $(ARGS) 115 116file-server: 117 go run $(SOURCE) file-server $(FADDR) 118 119readpcap: 120 go run $(SOURCE) --input-raw $(FILE) --input-raw-track-response --input-raw-engine pcap_file --output-stdout 121 122record: 123 $(RUN) go run $(SOURCE) --input-dummy=0 --output-file=requests.gor --verbose --debug 124 125replay: 126 $(RUN) go run $(SOURCE) --input-file=requests.bin --output-tcp=:9000 --verbose -h 127 128bash: 129 $(RUN) /bin/bash 130 131 132FPMCOMMON= \ 133 --name goreplay \ 134 --description "GoReplay is an open-source network monitoring tool which can record your live traffic, and use it for shadowing, load testing, monitoring and detailed analysis." \ 135 -v $(VERSION) \ 136 --vendor "Leonid Bugaev" \ 137 -m "<support@goreplay.org>" \ 138 --url "https://goreplay.org" \ 139 -s dir \ 140 -C /tmp/gor-build \ 141 142build_packages: 143 mkdir -p /tmp/gor-build 144 go build -i -o /tmp/gor-build/$(BIN_NAME) 145 fpm $(FPMCOMMON) -a amd64 -t deb ./=/usr/local/bin 146 fpm $(FPMCOMMON) -a amd64 -t rpm ./=/usr/local/bin 147