diff --git a/Dockerfile.dev b/Dockerfile.dev index cb85572e..1d0ffcae 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,8 +1,16 @@ -FROM golang:1.19 +ARG BASE_IMAGE +FROM ${BASE_IMAGE} -RUN apt-get update && apt-get install ruby vim-common -y +RUN apk add --no-cache \ + gcc \ + g++ \ + make \ + linux-headers \ + bison \ + flex \ + git \ + wget -RUN apt-get install flex bison -y RUN wget http://www.tcpdump.org/release/libpcap-1.10.0.tar.gz && tar xzf libpcap-1.10.0.tar.gz && cd libpcap-1.10.0 && ./configure && make install WORKDIR /go/src/github.com/buger/goreplay/ diff --git a/Makefile b/Makefile index ba060d2c..e04be209 100644 --- a/Makefile +++ b/Makefile @@ -11,18 +11,19 @@ BENCHMARK = BenchmarkRAWInput TEST = TestRawListenerBench BIN_NAME = gor VERSION := DEV-$(shell date +%s) +CUSTOM_TAGS := --tags "ngo$(if $(CUSTOM_BUILD_TAGS), $(CUSTOM_BUILD_TAGS),)" LDFLAGS = -ldflags "-X main.VERSION=$(VERSION) -extldflags \"-static\" -X main.DEMO=$(DEMO)" MAC_LDFLAGS = -ldflags "-X main.VERSION=$(VERSION) -X main.DEMO=$(DEMO)" DOCKER_FPM_CMD := docker run --rm -t -v `pwd`:/src -w /src fleetdm/fpm FPM_COMMON= \ - --name $(PROJECT_NAME) \ - --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." \ - -v $(VERSION) \ - --vendor "Leonid Bugaev" \ - -m "" \ - --url "https://goreplay.org" \ - -s dir + --name $(PROJECT_NAME) \ + --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." \ + -v $(VERSION) \ + --vendor "Leonid Bugaev" \ + -m "" \ + --url "https://goreplay.org" \ + -s dir release: clean release-linux-amd64 release-linux-arm64 release-mac-amd64 release-mac-arm64 release-windows @@ -31,19 +32,19 @@ vendor: go mod vendor release-bin-linux-amd64: vendor - docker run --platform linux/amd64 --rm -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=amd64 -i $(CONTAINER_AMD) go build -mod=vendor -o $(BIN_NAME) -tags netgo $(LDFLAGS) ./cmd/gor/ + docker run --platform linux/amd64 --rm -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=amd64 -i $(CONTAINER_AMD) go build -mod=vendor -o $(BIN_NAME) $(CUSTOM_TAGS) $(LDFLAGS) ./cmd/gor/ release-bin-linux-arm64: vendor - docker run --platform linux/arm64 --rm -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=arm64 -i $(CONTAINER_ARM) go build -mod=vendor -o $(BIN_NAME) -tags netgo $(LDFLAGS) ./cmd/gor/ + docker run --platform linux/arm64 --rm -v `pwd`:$(SOURCE_PATH) -t --env GOOS=linux --env GOARCH=arm64 -i $(CONTAINER_ARM) go build -mod=vendor -o $(BIN_NAME) $(CUSTOM_TAGS) $(LDFLAGS) ./cmd/gor/ release-bin-mac-amd64: vendor - GOOS=darwin go build -mod=vendor -o $(BIN_NAME) $(MAC_LDFLAGS) ./cmd/gor/ + GOOS=darwin go build -mod=vendor -o $(BIN_NAME) $(CUSTOM_TAGS) $(MAC_LDFLAGS) ./cmd/gor/ release-bin-mac-arm64: vendor - GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build -mod=vendor -o $(BIN_NAME) $(MAC_LDFLAGS) + GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build -mod=vendor -o $(BIN_NAME) $(CUSTOM_TAGS) $(MAC_LDFLAGS) release-bin-windows: vendor - docker run -it --rm -v `pwd`:$(SOURCE_PATH) -w $(SOURCE_PATH) -e CGO_ENABLED=1 docker.elastic.co/beats-dev/golang-crossbuild:1.19.2-main --build-cmd "make VERSION=$(VERSION) build" -p "windows/amd64" ./cmd/gor/ + docker run -it --rm -v `pwd`:$(SOURCE_PATH) -w $(SOURCE_PATH) -e CGO_ENABLED=1 docker.elastic.co/beats-dev/golang-crossbuild:1.19.2-main --build-cmd "make VERSION=$(VERSION) CUSTOM_BUILD_TAGS=$(CUSTOM_BUILD_TAGS) build" -p "windows/amd64" ./cmd/gor/ mv $(BIN_NAME) "$(BIN_NAME).exe" release-linux-amd64: dist release-bin-linux-amd64 @@ -78,18 +79,18 @@ clean: rm -rf $(DIST_PATH) build: - go build -mod=vendor -o $(BIN_NAME) $(LDFLAGS) + go build -mod=vendor -o $(BIN_NAME) $(CUSTOM_TAGS) $(LDFLAGS) install: - go install $(MAC_LDFLAGS) + go install $(CUSTOM_TAGS) $(MAC_LDFLAGS) build-env: build-amd64-env build-arm64-env build-amd64-env: - docker buildx build --platform linux/amd64 -t $(CONTAINER_AMD) -f Dockerfile.dev . + docker buildx build --build-arg BASE_IMAGE=golang:1.22-alpine --platform linux/amd64 -t $(CONTAINER_AMD) -f Dockerfile.dev --load . build-arm64-env: - docker buildx build --platform linux/arm64 -t $(CONTAINER_ARM) -f Dockerfile.dev . + docker buildx build --build-arg BASE_IMAGE=arm64v8/golang:1.22-alpine --platform linux/arm64 -t $(CONTAINER_ARM) -f Dockerfile.dev --load . build-docker: docker build -t gor-dev -f Dockerfile . @@ -104,13 +105,13 @@ race: $(RUN) go test ./... $(ARGS) -v -race -timeout 15s test: - $(RUN) go test ./. -timeout 120s $(LDFLAGS) $(ARGS) -v + $(RUN) go test ./. -timeout 120s $(CUSTOM_TAGS) $(LDFLAGS) $(ARGS) -v test_all: - $(RUN) go test ./... -timeout 120s $(LDFLAGS) $(ARGS) -v + $(RUN) go test ./... -timeout 120s $(CUSTOM_TAGS) $(LDFLAGS) $(ARGS) -v testone: - $(RUN) go test ./. -timeout 60s $(LDFLAGS) -run $(TEST) $(ARGS) -v + $(RUN) go test ./. -timeout 60s $(CUSTOM_TAGS) $(LDFLAGS) -run $(TEST) $(ARGS) -v cover: $(RUN) go test $(ARGS) -race -v -timeout 15s -coverprofile=coverage.out @@ -123,36 +124,36 @@ vet: $(RUN) go vet bench: - $(RUN) go test $(LDFLAGS) -v -run NOT_EXISTING -bench $(BENCHMARK) -benchtime 5s + $(RUN) go test $(CUSTOM_TAGS) $(LDFLAGS) -v -run NOT_EXISTING -bench $(BENCHMARK) -benchtime 5s profile_test: - $(RUN) go test $(LDFLAGS) -run $(TEST) ./capture/. $(ARGS) -memprofile mem.mprof -cpuprofile cpu.out - $(RUN) go test $(LDFLAGS) -run $(TEST) ./capture/. $(ARGS) -c + $(RUN) go test $(CUSTOM_TAGS) $(LDFLAGS) -run $(TEST) ./capture/. $(ARGS) -memprofile mem.mprof -cpuprofile cpu.out + $(RUN) go test $(CUSTOM_TAGS) $(LDFLAGS) -run $(TEST) ./capture/. $(ARGS) -c # Used mainly for debugging, because docker container do not have access to parent machine ports run: - $(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 0 --middleware "./examples/middleware/echo.sh" --output-file requests.gor + $(RUN) go run $(CUSTOM_TAGS) $(LDFLAGS) $(SOURCE) --input-dummy=0 --output-http="http://localhost:9000" --input-raw-track-response --input-raw 127.0.0.1:9000 --verbose 0 --middleware "./examples/middleware/echo.sh" --output-file requests.gor run-2: - $(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 + $(RUN) go run $(CUSTOM_TAGS) $(LDFLAGS) $(SOURCE) --input-raw :8000 --input-raw-bpf-filter "dst port 8000" --output-stdout --output-http "http://localhost:8000" --input-dummy=0 run-3: - sudo -E go run $(SOURCE) --input-tcp :27001 --output-stdout + sudo -E go run $(CUSTOM_TAGS) $(SOURCE) --input-tcp :27001 --output-stdout run-arg: - sudo -E go run $(SOURCE) $(ARGS) + sudo -E go run $(CUSTOM_TAGS) $(SOURCE) $(ARGS) file-server: - go run $(SOURCE) file-server $(FADDR) + go run $(CUSTOM_TAGS) $(SOURCE) file-server $(FADDR) readpcap: - go run $(SOURCE) --input-raw $(FILE) --input-raw-track-response --input-raw-engine pcap_file --output-stdout + go run $(CUSTOM_TAGS) $(SOURCE) --input-raw $(FILE) --input-raw-track-response --input-raw-engine pcap_file --output-stdout record: - $(RUN) go run $(SOURCE) --input-dummy=0 --output-file=requests.gor --verbose --debug + $(RUN) go run $(CUSTOM_TAGS) $(SOURCE) --input-dummy=0 --output-file=requests.gor --verbose --debug replay: - $(RUN) go run $(SOURCE) --input-file=requests.bin --output-tcp=:9000 --verbose -h + $(RUN) go run $(CUSTOM_TAGS) $(SOURCE) --input-file=requests.bin --output-tcp=:9000 --verbose -h bash: $(RUN) /bin/bash