Skip to content

Commit d3c95f1

Browse files
committed
Improve build scripts
1 parent 2e7d26c commit d3c95f1

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

Dockerfile.dev

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
FROM golang:1.19
1+
ARG BASE_IMAGE
2+
FROM ${BASE_IMAGE}
23

3-
RUN apt-get update && apt-get install ruby vim-common -y
4+
RUN apk add --no-cache \
5+
gcc \
6+
g++ \
7+
make \
8+
linux-headers \
9+
bison \
10+
flex \
11+
git \
12+
wget
413

5-
RUN apt-get install flex bison -y
614
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
715

816
WORKDIR /go/src/github.com/buger/goreplay/

Makefile

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@ BENCHMARK = BenchmarkRAWInput
1111
TEST = TestRawListenerBench
1212
BIN_NAME = gor
1313
VERSION := DEV-$(shell date +%s)
14+
CUSTOM_TAGS := --tags "ngo$(if $(CUSTOM_BUILD_TAGS), $(CUSTOM_BUILD_TAGS),)"
1415
LDFLAGS = -ldflags "-X main.VERSION=$(VERSION) -extldflags \"-static\" -X main.DEMO=$(DEMO)"
1516
MAC_LDFLAGS = -ldflags "-X main.VERSION=$(VERSION) -X main.DEMO=$(DEMO)"
1617
DOCKER_FPM_CMD := docker run --rm -t -v `pwd`:/src -w /src fleetdm/fpm
1718

1819
FPM_COMMON= \
19-
--name $(PROJECT_NAME) \
20-
--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." \
21-
-v $(VERSION) \
22-
--vendor "Leonid Bugaev" \
23-
24-
--url "https://goreplay.org" \
25-
-s dir
20+
--name $(PROJECT_NAME) \
21+
--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." \
22+
-v $(VERSION) \
23+
--vendor "Leonid Bugaev" \
24+
25+
--url "https://goreplay.org" \
26+
-s dir
2627

2728
release: clean release-linux-amd64 release-linux-arm64 release-mac-amd64 release-mac-arm64 release-windows
2829

@@ -31,19 +32,19 @@ vendor:
3132
go mod vendor
3233

3334
release-bin-linux-amd64: vendor
34-
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/
35+
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/
3536

3637
release-bin-linux-arm64: vendor
37-
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/
38+
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/
3839

3940
release-bin-mac-amd64: vendor
40-
GOOS=darwin go build -mod=vendor -o $(BIN_NAME) $(MAC_LDFLAGS) ./cmd/gor/
41+
GOOS=darwin go build -mod=vendor -o $(BIN_NAME) $(CUSTOM_TAGS) $(MAC_LDFLAGS) ./cmd/gor/
4142

4243
release-bin-mac-arm64: vendor
43-
GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build -mod=vendor -o $(BIN_NAME) $(MAC_LDFLAGS)
44+
GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build -mod=vendor -o $(BIN_NAME) $(CUSTOM_TAGS) $(MAC_LDFLAGS)
4445

4546
release-bin-windows: vendor
46-
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/
47+
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/
4748
mv $(BIN_NAME) "$(BIN_NAME).exe"
4849

4950
release-linux-amd64: dist release-bin-linux-amd64
@@ -78,18 +79,18 @@ clean:
7879
rm -rf $(DIST_PATH)
7980

8081
build:
81-
go build -mod=vendor -o $(BIN_NAME) $(LDFLAGS)
82+
go build -mod=vendor -o $(BIN_NAME) $(CUSTOM_TAGS) $(LDFLAGS)
8283

8384
install:
84-
go install $(MAC_LDFLAGS)
85+
go install $(CUSTOM_TAGS) $(MAC_LDFLAGS)
8586

8687
build-env: build-amd64-env build-arm64-env
8788

8889
build-amd64-env:
89-
docker buildx build --platform linux/amd64 -t $(CONTAINER_AMD) -f Dockerfile.dev .
90+
docker buildx build --build-arg BASE_IMAGE=golang:1.22-alpine --platform linux/amd64 -t $(CONTAINER_AMD) -f Dockerfile.dev --load .
9091

9192
build-arm64-env:
92-
docker buildx build --platform linux/arm64 -t $(CONTAINER_ARM) -f Dockerfile.dev .
93+
docker buildx build --build-arg BASE_IMAGE=arm64v8/golang:1.22-alpine --platform linux/arm64 -t $(CONTAINER_ARM) -f Dockerfile.dev --load .
9394

9495
build-docker:
9596
docker build -t gor-dev -f Dockerfile .
@@ -104,13 +105,13 @@ race:
104105
$(RUN) go test ./... $(ARGS) -v -race -timeout 15s
105106

106107
test:
107-
$(RUN) go test ./. -timeout 120s $(LDFLAGS) $(ARGS) -v
108+
$(RUN) go test ./. -timeout 120s $(CUSTOM_TAGS) $(LDFLAGS) $(ARGS) -v
108109

109110
test_all:
110-
$(RUN) go test ./... -timeout 120s $(LDFLAGS) $(ARGS) -v
111+
$(RUN) go test ./... -timeout 120s $(CUSTOM_TAGS) $(LDFLAGS) $(ARGS) -v
111112

112113
testone:
113-
$(RUN) go test ./. -timeout 60s $(LDFLAGS) -run $(TEST) $(ARGS) -v
114+
$(RUN) go test ./. -timeout 60s $(CUSTOM_TAGS) $(LDFLAGS) -run $(TEST) $(ARGS) -v
114115

115116
cover:
116117
$(RUN) go test $(ARGS) -race -v -timeout 15s -coverprofile=coverage.out
@@ -123,36 +124,36 @@ vet:
123124
$(RUN) go vet
124125

125126
bench:
126-
$(RUN) go test $(LDFLAGS) -v -run NOT_EXISTING -bench $(BENCHMARK) -benchtime 5s
127+
$(RUN) go test $(CUSTOM_TAGS) $(LDFLAGS) -v -run NOT_EXISTING -bench $(BENCHMARK) -benchtime 5s
127128

128129
profile_test:
129-
$(RUN) go test $(LDFLAGS) -run $(TEST) ./capture/. $(ARGS) -memprofile mem.mprof -cpuprofile cpu.out
130-
$(RUN) go test $(LDFLAGS) -run $(TEST) ./capture/. $(ARGS) -c
130+
$(RUN) go test $(CUSTOM_TAGS) $(LDFLAGS) -run $(TEST) ./capture/. $(ARGS) -memprofile mem.mprof -cpuprofile cpu.out
131+
$(RUN) go test $(CUSTOM_TAGS) $(LDFLAGS) -run $(TEST) ./capture/. $(ARGS) -c
131132

132133
# Used mainly for debugging, because docker container do not have access to parent machine ports
133134
run:
134-
$(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
135+
$(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
135136

136137
run-2:
137-
$(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
138+
$(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
138139

139140
run-3:
140-
sudo -E go run $(SOURCE) --input-tcp :27001 --output-stdout
141+
sudo -E go run $(CUSTOM_TAGS) $(SOURCE) --input-tcp :27001 --output-stdout
141142

142143
run-arg:
143-
sudo -E go run $(SOURCE) $(ARGS)
144+
sudo -E go run $(CUSTOM_TAGS) $(SOURCE) $(ARGS)
144145

145146
file-server:
146-
go run $(SOURCE) file-server $(FADDR)
147+
go run $(CUSTOM_TAGS) $(SOURCE) file-server $(FADDR)
147148

148149
readpcap:
149-
go run $(SOURCE) --input-raw $(FILE) --input-raw-track-response --input-raw-engine pcap_file --output-stdout
150+
go run $(CUSTOM_TAGS) $(SOURCE) --input-raw $(FILE) --input-raw-track-response --input-raw-engine pcap_file --output-stdout
150151

151152
record:
152-
$(RUN) go run $(SOURCE) --input-dummy=0 --output-file=requests.gor --verbose --debug
153+
$(RUN) go run $(CUSTOM_TAGS) $(SOURCE) --input-dummy=0 --output-file=requests.gor --verbose --debug
153154

154155
replay:
155-
$(RUN) go run $(SOURCE) --input-file=requests.bin --output-tcp=:9000 --verbose -h
156+
$(RUN) go run $(CUSTOM_TAGS) $(SOURCE) --input-file=requests.bin --output-tcp=:9000 --verbose -h
156157

157158
bash:
158159
$(RUN) /bin/bash

0 commit comments

Comments
 (0)