|
| 1 | +# Makefile for building and pushing Docker images |
| 2 | + |
| 3 | +COMMIT = git-$(shell git rev-parse --short HEAD) |
| 4 | +DATE = $(shell date +"%Y-%m-%d_%H:%M:%S") |
| 5 | + |
| 6 | +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) |
| 7 | +ifdef DEBUG |
| 8 | +GO_BUILD_FLAGS = -ldflags "$(GOLDFLAGS)" |
| 9 | +else |
| 10 | +GO_BUILD_FLAGS = -trimpath -ldflags "-w -s $(GOLDFLAGS)" |
| 11 | +endif |
| 12 | + |
| 13 | +.PHONY: build-go |
| 14 | +build-go: |
| 15 | + go mod tidy |
| 16 | + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(GO_BUILD_FLAGS) -o $(CURDIR)/dist/images/kube-ovn -v ./cmd/cni |
| 17 | + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(GO_BUILD_FLAGS) -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-cmd -v ./cmd |
| 18 | + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(GO_BUILD_FLAGS) -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-daemon -v ./cmd/daemon |
| 19 | + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(GO_BUILD_FLAGS) -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-controller -v ./cmd/controller |
| 20 | + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(GO_BUILD_FLAGS) -o $(CURDIR)/dist/images/test-server -v ./test/server |
| 21 | + |
| 22 | +.PHONY: build-go-windows |
| 23 | +build-go-windows: |
| 24 | + go mod tidy |
| 25 | + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build $(GO_BUILD_FLAGS) -o $(CURDIR)/dist/windows/kube-ovn.exe -v ./cmd/cni |
| 26 | + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build $(GO_BUILD_FLAGS) -buildmode=pie -o $(CURDIR)/dist/windows/kube-ovn-daemon.exe -v ./cmd/daemon |
| 27 | + |
| 28 | +.PHONY: build-go-arm |
| 29 | +build-go-arm: |
| 30 | + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(GO_BUILD_FLAGS) -o $(CURDIR)/dist/images/kube-ovn -v ./cmd/cni |
| 31 | + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(GO_BUILD_FLAGS) -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-cmd -v ./cmd |
| 32 | + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(GO_BUILD_FLAGS) -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-daemon -v ./cmd/daemon |
| 33 | + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(GO_BUILD_FLAGS) -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-controller -v ./cmd/controller |
| 34 | + |
| 35 | +.PHONY: build-kube-ovn |
| 36 | +build-kube-ovn: build-debug build-go |
| 37 | + docker build -t $(REGISTRY)/kube-ovn:$(RELEASE_TAG) --build-arg VERSION=$(RELEASE_TAG) -f dist/images/Dockerfile dist/images/ |
| 38 | + docker build -t $(REGISTRY)/kube-ovn:$(LEGACY_TAG) --build-arg VERSION=$(LEGACY_TAG) -f dist/images/Dockerfile dist/images/ |
| 39 | + |
| 40 | +.PHONY: build-kube-ovn-dpdk |
| 41 | +build-kube-ovn-dpdk: build-go |
| 42 | + docker build -t $(REGISTRY)/kube-ovn:$(RELEASE_TAG)-dpdk --build-arg BASE_TAG=$(RELEASE_TAG)-dpdk -f dist/images/Dockerfile dist/images/ |
| 43 | + |
| 44 | +.PHONY: build-dev |
| 45 | +build-dev: build-go |
| 46 | + docker build -t $(REGISTRY)/kube-ovn:$(DEV_TAG) --build-arg VERSION=$(RELEASE_TAG) -f dist/images/Dockerfile dist/images/ |
| 47 | + |
| 48 | +.PHONY: build-debug |
| 49 | +build-debug: |
| 50 | + @DEBUG=1 $(MAKE) build-go |
| 51 | + docker build -t $(REGISTRY)/kube-ovn:$(DEBUG_TAG) --build-arg BASE_TAG=$(DEBUG_TAG) -f dist/images/Dockerfile dist/images/ |
| 52 | + |
| 53 | +.PHONY: base-amd64 |
| 54 | +base-amd64: |
| 55 | + docker buildx build --platform linux/amd64 --build-arg ARCH=amd64 --build-arg GO_VERSION --build-arg TRIVY_DB_REPOSITORY -t $(REGISTRY)/kube-ovn-base:$(RELEASE_TAG)-amd64 -o type=docker -f dist/images/Dockerfile.base dist/images/ |
| 56 | + docker buildx build --platform linux/amd64 --build-arg ARCH=amd64 --build-arg GO_VERSION --build-arg TRIVY_DB_REPOSITORY --build-arg LEGACY=true -t $(REGISTRY)/kube-ovn-base:$(LEGACY_TAG) -o type=docker -f dist/images/Dockerfile.base dist/images/ |
| 57 | + docker buildx build --platform linux/amd64 --build-arg ARCH=amd64 --build-arg GO_VERSION --build-arg TRIVY_DB_REPOSITORY --build-arg DEBUG=true -t $(REGISTRY)/kube-ovn-base:$(DEBUG_TAG)-amd64 -o type=docker -f dist/images/Dockerfile.base dist/images/ |
| 58 | + |
| 59 | +.PHONY: base-amd64-dpdk |
| 60 | +base-amd64-dpdk: |
| 61 | + docker buildx build --platform linux/amd64 --build-arg ARCH=amd64 -t $(REGISTRY)/kube-ovn-base:$(RELEASE_TAG)-amd64-dpdk -o type=docker -f dist/images/Dockerfile.base-dpdk dist/images/ |
| 62 | + |
| 63 | +.PHONY: base-arm64 |
| 64 | +base-arm64: |
| 65 | + docker buildx build --platform linux/arm64 --build-arg ARCH=arm64 --build-arg GO_VERSION --build-arg TRIVY_DB_REPOSITORY -t $(REGISTRY)/kube-ovn-base:$(RELEASE_TAG)-arm64 -o type=docker -f dist/images/Dockerfile.base dist/images/ |
| 66 | + docker buildx build --platform linux/arm64 --build-arg ARCH=arm64 --build-arg GO_VERSION --build-arg TRIVY_DB_REPOSITORY --build-arg DEBUG=true -t $(REGISTRY)/kube-ovn-base:$(DEBUG_TAG)-arm64 -o type=docker -f dist/images/Dockerfile.base dist/images/ |
| 67 | + |
| 68 | +.PHONY: build-kit |
| 69 | +build-kit: build-go |
| 70 | + DOCKER_BUILDKIT=1 docker build -t $(REGISTRY)/kube-ovn:$(RELEASE_TAG) --build-arg VERSION=$(RELEASE_TAG) -o type=docker -f dist/images/Dockerfile dist/images/ |
| 71 | + |
| 72 | +.PHONY: image-kube-ovn |
| 73 | +image-kube-ovn: image-kube-ovn-debug build-go |
| 74 | + 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/ |
| 75 | + docker buildx build --platform linux/amd64 -t $(REGISTRY)/kube-ovn:$(LEGACY_TAG) --build-arg VERSION=$(LEGACY_TAG) -o type=docker -f dist/images/Dockerfile dist/images/ |
| 76 | + |
| 77 | +.PHONY: image-kube-ovn-arm64 |
| 78 | +image-kube-ovn-arm64: build-go-arm |
| 79 | + 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/ |
| 80 | + |
| 81 | +.PHONY: image-kube-ovn-debug |
| 82 | +image-kube-ovn-debug: |
| 83 | + @DEBUG=1 $(MAKE) build-go |
| 84 | + 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/ |
| 85 | + |
| 86 | +.PHONY: image-kube-ovn-dpdk |
| 87 | +image-kube-ovn-dpdk: build-go |
| 88 | + docker buildx build --platform linux/amd64 -t $(REGISTRY)/kube-ovn:$(RELEASE_TAG)-dpdk --build-arg VERSION=$(RELEASE_TAG) --build-arg BASE_TAG=$(RELEASE_TAG)-dpdk -o type=docker -f dist/images/Dockerfile dist/images/ |
| 89 | + |
| 90 | +.PHONY: image-vpc-nat-gateway |
| 91 | +image-vpc-nat-gateway: |
| 92 | + docker buildx build --platform linux/amd64 -t $(REGISTRY)/vpc-nat-gateway:$(RELEASE_TAG) -o type=docker -f dist/images/vpcnatgateway/Dockerfile dist/images/vpcnatgateway |
| 93 | + |
| 94 | +.PHOONY: image-test |
| 95 | +image-test: build-go |
| 96 | + docker buildx build --platform linux/amd64 -t $(REGISTRY)/test:$(RELEASE_TAG) -o type=docker -f dist/images/Dockerfile.test dist/images/ |
| 97 | + |
| 98 | +.PHONY: release |
| 99 | +release: lint image-kube-ovn image-vpc-nat-gateway |
| 100 | + |
| 101 | +.PHONY: release-arm |
| 102 | +release-arm: release-arm-debug image-kube-ovn-arm64 |
| 103 | + docker buildx build --platform linux/arm64 -t $(REGISTRY)/vpc-nat-gateway:$(RELEASE_TAG) -o type=docker -f dist/images/vpcnatgateway/Dockerfile dist/images/vpcnatgateway |
| 104 | + |
| 105 | +.PHONY: release-arm-debug |
| 106 | +release-arm-debug: |
| 107 | + @DEBUG=1 $(MAKE) build-go-arm |
| 108 | + 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/ |
| 109 | + |
| 110 | +.PHONY: push-dev |
| 111 | +push-dev: |
| 112 | + docker push $(REGISTRY)/kube-ovn:$(DEV_TAG) |
| 113 | + |
| 114 | +.PHONY: push-release |
| 115 | +push-release: release |
| 116 | + docker push $(REGISTRY)/kube-ovn:$(RELEASE_TAG) |
| 117 | + |
| 118 | +.PHONY: tar-kube-ovn |
| 119 | +tar-kube-ovn: |
| 120 | + docker save $(REGISTRY)/kube-ovn:$(RELEASE_TAG) $(REGISTRY)/kube-ovn:$(LEGACY_TAG) $(REGISTRY)/kube-ovn:$(DEBUG_TAG) -o kube-ovn.tar |
| 121 | + |
| 122 | +.PHONY: tar-kube-ovn-dpdk |
| 123 | +tar-kube-ovn-dpdk: |
| 124 | + docker save $(REGISTRY)/kube-ovn:$(RELEASE_TAG)-dpdk -o kube-ovn-dpdk.tar |
| 125 | + |
| 126 | +.PHONY: tar-vpc-nat-gateway |
| 127 | +tar-vpc-nat-gateway: |
| 128 | + docker save $(REGISTRY)/vpc-nat-gateway:$(RELEASE_TAG) -o vpc-nat-gateway.tar |
| 129 | + |
| 130 | +.PHONY: tar |
| 131 | +tar: tar-kube-ovn tar-vpc-nat-gateway |
| 132 | + |
| 133 | +.PHONY: base-tar-amd64 |
| 134 | +base-tar-amd64: |
| 135 | + docker save $(REGISTRY)/kube-ovn-base:$(RELEASE_TAG)-amd64 $(REGISTRY)/kube-ovn-base:$(LEGACY_TAG) $(REGISTRY)/kube-ovn-base:$(DEBUG_TAG)-amd64 -o image-amd64.tar |
| 136 | + |
| 137 | +.PHONY: base-tar-amd64-dpdk |
| 138 | +base-tar-amd64-dpdk: |
| 139 | + docker save $(REGISTRY)/kube-ovn-base:$(RELEASE_TAG)-amd64-dpdk -o image-amd64-dpdk.tar |
| 140 | + |
| 141 | +.PHONY: base-tar-arm64 |
| 142 | +base-tar-arm64: |
| 143 | + docker save $(REGISTRY)/kube-ovn-base:$(RELEASE_TAG)-arm64 $(REGISTRY)/kube-ovn-base:$(DEBUG_TAG)-arm64 -o image-arm64.tar |
| 144 | + |
| 145 | +.PHONY: lint |
| 146 | +lint: |
| 147 | + ifeq ($(CI),true) |
| 148 | + @echo "Running in GitHub Actions" |
| 149 | + golangci-lint run -v |
| 150 | + else |
| 151 | + @echo "Running in local environment" |
| 152 | + golangci-lint run -v --fix |
| 153 | + endif |
| 154 | + |
| 155 | +.PHONY: lint-windows |
| 156 | +lint-windows: |
| 157 | + @GOOS=windows go vet ./cmd/windows/... |
| 158 | + @GOOS=windows gosec ./pkg/util |
| 159 | + @GOOS=windows gosec ./pkg/request |
| 160 | + @GOOS=windows gosec ./cmd/cni |
| 161 | + |
| 162 | +.PHONY: scan |
| 163 | +scan: |
| 164 | + trivy image --exit-code=1 --ignore-unfixed --scanners vuln $(REGISTRY)/kube-ovn:$(RELEASE_TAG) |
| 165 | + trivy image --exit-code=1 --ignore-unfixed --scanners vuln $(REGISTRY)/vpc-nat-gateway:$(RELEASE_TAG) |
0 commit comments