From 2ba065cbff7a194bbd773598a3d70d7dd793a289 Mon Sep 17 00:00:00 2001 From: zhangzujian Date: Tue, 26 Mar 2024 06:36:32 +0000 Subject: [PATCH] compile binaries with debug symbols for debug images Signed-off-by: zhangzujian --- .github/workflows/build-arm64-image.yaml | 2 +- Makefile | 48 +++++++++++++++--------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build-arm64-image.yaml b/.github/workflows/build-arm64-image.yaml index 366657a1a83..fca8e790e3e 100644 --- a/.github/workflows/build-arm64-image.yaml +++ b/.github/workflows/build-arm64-image.yaml @@ -52,7 +52,7 @@ jobs: restore-keys: ${{ runner.os }}-${{ env.GO_FULL_VER }}-arm64- - name: Build - run: make release-arm || make release-arm + run: make release-arm - name: Push if: github.ref_name == github.event.repository.default_branch || startsWith(github.ref_name, 'release-') diff --git a/Makefile b/Makefile index c935a0105b9..5eb09d71292 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,13 @@ DEBUG_TAG = $(shell cat VERSION)-debug VERSION = $(shell echo $${VERSION:-$(RELEASE_TAG)}) COMMIT = git-$(shell git rev-parse --short HEAD) DATE = $(shell date +"%Y-%m-%d_%H:%M:%S") -GOLDFLAGS = "-w -s -extldflags '-z now' -X github.com/kubeovn/kube-ovn/versions.COMMIT=$(COMMIT) -X github.com/kubeovn/kube-ovn/versions.VERSION=$(RELEASE_TAG) -X github.com/kubeovn/kube-ovn/versions.BUILDDATE=$(DATE)" + +GOLDFLAGS = -extldflags '-z now' -X github.com/kubeovn/kube-ovn/versions.COMMIT=$(COMMIT) -X github.com/kubeovn/kube-ovn/versions.VERSION=$(RELEASE_TAG) -X github.com/kubeovn/kube-ovn/versions.BUILDDATE=$(DATE) +ifdef DEBUG +GO_BUILD_FLAGS = -ldflags "$(GOLDFLAGS)" +else +GO_BUILD_FLAGS = -trimpath -ldflags "-w -s $(GOLDFLAGS)" +endif OS_LINUX = 0 ifneq ($(OS),Windows_NT) @@ -80,7 +86,7 @@ VPC_NAT_GW_IMG = $(REGISTRY)/vpc-nat-gateway:$(VERSION) E2E_NETWORK = bridge ifneq ($(VLAN_ID),) - E2E_NETWORK = kube-ovn-vlan +E2E_NETWORK = kube-ovn-vlan endif # ARCH could be amd64,arm64 @@ -89,27 +95,26 @@ ARCH = amd64 .PHONY: build-go build-go: go mod tidy - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -o $(CURDIR)/dist/images/kube-ovn -ldflags $(GOLDFLAGS) -v ./cmd/cni - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-cmd -ldflags $(GOLDFLAGS) -v ./cmd - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-webhook -ldflags $(GOLDFLAGS) -v ./cmd/webhook - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -o $(CURDIR)/dist/images/test-server -ldflags $(GOLDFLAGS) -v ./test/server + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(GO_BUILD_FLAGS) -o $(CURDIR)/dist/images/kube-ovn -v ./cmd/cni + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(GO_BUILD_FLAGS) -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-cmd -v ./cmd + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(GO_BUILD_FLAGS) -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-webhook -v ./cmd/webhook + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(GO_BUILD_FLAGS) -o $(CURDIR)/dist/images/test-server -v ./test/server .PHONY: build-go-windows build-go-windows: go mod tidy - CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath -o $(CURDIR)/dist/windows/kube-ovn.exe -ldflags $(GOLDFLAGS) -v ./cmd/cni - CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath -buildmode=pie -o $(CURDIR)/dist/windows/kube-ovn-daemon.exe -ldflags $(GOLDFLAGS) -v ./cmd/windows/daemon + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build $(GO_BUILD_FLAGS) -o $(CURDIR)/dist/windows/kube-ovn.exe -v ./cmd/cni + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build $(GO_BUILD_FLAGS) -buildmode=pie -o $(CURDIR)/dist/windows/kube-ovn-daemon.exe -v ./cmd/windows/daemon .PHONY: build-go-arm build-go-arm: - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -o $(CURDIR)/dist/images/kube-ovn -ldflags $(GOLDFLAGS) -v ./cmd/cni - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-cmd -ldflags $(GOLDFLAGS) -v ./cmd - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-webhook -ldflags $(GOLDFLAGS) -v ./cmd/webhook + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(GO_BUILD_FLAGS) -o $(CURDIR)/dist/images/kube-ovn -v ./cmd/cni + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(GO_BUILD_FLAGS) -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-cmd -v ./cmd + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(GO_BUILD_FLAGS) -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-webhook -v ./cmd/webhook .PHONY: build-kube-ovn -build-kube-ovn: build-go +build-kube-ovn: build-debug build-go docker build -t $(REGISTRY)/kube-ovn:$(RELEASE_TAG) --build-arg VERSION=$(RELEASE_TAG) -f dist/images/Dockerfile dist/images/ - docker build -t $(REGISTRY)/kube-ovn:$(DEBUG_TAG) --build-arg BASE_TAG=$(DEBUG_TAG) -f dist/images/Dockerfile dist/images/ .PHONY: build-kube-ovn-dpdk build-kube-ovn-dpdk: build-go @@ -120,7 +125,8 @@ build-dev: build-go docker build -t $(REGISTRY)/kube-ovn:$(DEV_TAG) --build-arg VERSION=$(RELEASE_TAG) -f dist/images/Dockerfile dist/images/ .PHONY: build-debug -build-debug: build-go +build-debug: + @DEBUG=1 $(MAKE) build-go docker build -t $(REGISTRY)/kube-ovn:$(DEBUG_TAG) --build-arg BASE_TAG=$(DEBUG_TAG) -f dist/images/Dockerfile dist/images/ .PHONY: build-dpdk @@ -142,8 +148,12 @@ base-arm64: docker buildx build --platform linux/arm64 --build-arg ARCH=arm64 --build-arg DEBUG=true -t $(REGISTRY)/kube-ovn-base:$(DEBUG_TAG)-arm64 -o type=docker -f dist/images/Dockerfile.base dist/images/ .PHONY: image-kube-ovn -image-kube-ovn: build-go +image-kube-ovn: image-kube-ovn-debug build-go docker buildx build --platform linux/amd64 -t $(REGISTRY)/kube-ovn:$(RELEASE_TAG) --build-arg VERSION=$(RELEASE_TAG) -o type=docker -f dist/images/Dockerfile dist/images/ + +.PHONY: image-kube-ovn-debug +image-kube-ovn-debug: + @DEBUG=1 $(MAKE) build-go docker buildx build --platform linux/amd64 -t $(REGISTRY)/kube-ovn:$(DEBUG_TAG) --build-arg BASE_TAG=$(DEBUG_TAG) -o type=docker -f dist/images/Dockerfile dist/images/ .PHONY: image-kube-ovn-dpdk @@ -162,11 +172,15 @@ image-test: build-go release: lint image-kube-ovn image-vpc-nat-gateway .PHONY: release-arm -release-arm: build-go-arm +release-arm: release-arm-debug build-go-arm docker buildx build --platform linux/arm64 -t $(REGISTRY)/kube-ovn:$(RELEASE_TAG) --build-arg VERSION=$(RELEASE_TAG) -o type=docker -f dist/images/Dockerfile dist/images/ - docker buildx build --platform linux/arm64 -t $(REGISTRY)/kube-ovn:$(DEBUG_TAG) --build-arg BASE_TAG=$(DEBUG_TAG) -o type=docker -f dist/images/Dockerfile dist/images/ docker buildx build --platform linux/arm64 -t $(REGISTRY)/vpc-nat-gateway:$(RELEASE_TAG) -o type=docker -f dist/images/vpcnatgateway/Dockerfile dist/images/vpcnatgateway +.PHONY: release-arm-debug +release-arm-debug: + @DEBUG=1 $(MAKE) build-go-arm + docker buildx build --platform linux/arm64 -t $(REGISTRY)/kube-ovn:$(DEBUG_TAG) --build-arg BASE_TAG=$(DEBUG_TAG) -o type=docker -f dist/images/Dockerfile dist/images/ + .PHONY: push-dev push-dev: docker push $(REGISTRY)/kube-ovn:$(DEV_TAG)