8000 Organize Makefiles; Add compression option: by jacobweinstock · Pull Request #24 · tinkerbell/tinkerbell · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Organize Makefiles; Add compression option: #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 54 additions & 63 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,115 +4,106 @@
SHELL := bash
.SHELLFLAGS := -o pipefail -euc

CGO_ENABLED := 0
export CGO_ENABLED
COMPRESS := false
UPX_BASEDIR := $(PWD)/build
LOCAL_ARCH := $(shell uname -m)
LOCAL_ARCH_ALT :=
ifeq ($(LOCAL_ARCH),x86_64)
LOCAL_ARCH_ALT := amd64
else ifeq ($(LOCAL_ARCH),aarch64)
LOCAL_ARCH_ALT := arm64
endif

all: help

-include lint.mk
-include build/tools.mk
-include build/lint.mk

CGO_ENABLED := 0
export CGO_ENABLED
help: ## Print this help
@grep --no-filename -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sed 's/:.*##/·/' | sort | column -ts '·' -c 120

build: out/tinkerbell ## Build the binary
build: out/tinkerbell ## Build the Tinkerbell binary
build-agent: out/tink-agent ## Build the Tink Agent binary

.PHONY: test
test: ## Run go test
CGO_ENABLED=1 go test -race -coverprofile=coverage.txt -covermode=atomic -v ${TEST_ARGS} ./...

.PHONY: vet
vet: ## Run go vet
go vet ./...

.PHONY: fmt
fmt: $(GOIMPORTS_FQP) ## Run go fmt
go fmt ./...
$(GOIMPORTS_FQP) -w .

.PHONY: coverage
coverage: test ## Show test coverage
go tool cover -func=coverage.txt

ci-checks: .github/workflows/ci-checks.sh
.PHONY: ci-checks
ci-checks: .github/workflows/ci-checks.sh ## Run the ci-checks.sh script
./.github/workflows/ci-checks.sh

.PHONY: ci
ci: ci-checks coverage lint vet ## Runs all the same validations and tests that run in CI

help: ## Print this help
@grep --no-filename -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sed 's/:.*##/·/' | sort | column -ts '·' -c 120

crossbinaries := out/tinkerbell-linux-amd64 out/tinkerbell-linux-arm64
out/tinkerbell-linux-amd64: FLAGS=GOARCH=amd64
out/tinkerbell-linux-arm64: FLAGS=GOARCH=arm64
out/tinkerbell-linux-amd64 out/tinkerbell-linux-arm64: cleanup
out/tinkerbell-linux-amd64 out/tinkerbell-linux-arm64: clean
${FLAGS} CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -v -o $@ ./cmd/tinkerbell
if [ "${COMPRESS}" = "true" ]; then $(MAKE) $(UPX_FQP) && $(UPX_FQP) --best --lzma $@; fi

out/tinkerbell: cleanup
out/tinkerbell: clean ## Compile Tinkerbell for the current architecture
${FLAGS} CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -v -o $@ ./cmd/tinkerbell
if [ "${COMPRESS}" = "true" ]; then $(MAKE) $(UPX_FQP) && $(UPX_FQP) --best --lzma $@; fi

crosscompile: $(crossbinaries) ## Compile for all architectures

cleanup:
rm -f out/tinkerbell out/tinkerbell-linux-amd64 out/tinkerbell-linux-arm64

crossbinaries-agent := out/tink-agent-linux-amd64 out/tink-agent-linux-arm64
out/tink-agent-linux-amd64: FLAGS=GOARCH=amd64
out/tink-agent-linux-arm64: FLAGS=GOARCH=arm64
out/tink-agent-linux-amd64 out/tink-agent-linux-arm64: cleanup-agent
out/tink-agent-linux-amd64 out/tink-agent-linux-arm64:: clean-agent
${FLAGS} CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -v -o $@ ./cmd/agent
if [ "${COMPRESS}" = "true" ]; then $(MAKE) $(UPX_FQP) && $(UPX_FQP) --best --lzma $@; fi

out/tink-agent: cleanup-agent
out/tink-agent: clean-agent ## Compile Tink Agent for the current architecture
${FLAGS} CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -v -o $@ ./cmd/agent
if [ "${COMPRESS}" = "true" ]; then $(MAKE) $(UPX_FQP) && $(UPX_FQP) --best --lzma $@; fi

crosscompile-agent: $(crossbinaries-agent) ## Compile Tink Agent for all architectures

cleanup-agent:
rm -f out/tink-agent out/tink-agent-linux-amd64 out/tink-agent-linux-arm64
.PHONY: generate-proto
generate-proto: $(BUF_FQP) $(PROTOC_GEN_GO_GRPC_FQP) $(PROTOC_GEN_GO_FQP) ## Generate code from proto files.
$(BUF_FQP) generate
$(MAKE) fmt

# Kubernetes CRD generation
# Define the directory tools are installed to.
TOOLS_DIR := $(PWD)/out/tools

CONTROLLER_GEN_VERSION := v0.17.1

CONTROLLER_GEN = $(TOOLS_DIR)/controller-gen
.PHONY: controller-gen
controller-gen: ## Download controller-gen locally.
GOBIN=$(TOOLS_DIR) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION)

GOIMPORTS = $(TOOLS_DIR)/goimports
.PHONY: goimports
goimports: ## Download goimports locally.
GOBIN=$(TOOLS_DIR) go install golang.org/x/tools/cmd/goimports@latest

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
manifests: $(CONTROLLER_GEN_FQP) ## Generate WebhookConfiguration and CustomResourceDefinition objects.
$(CONTROLLER_GEN_FQP) crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(MAKE) fmt

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="config/boilerplate.go.txt" paths="./..."
generate: $(CONTROLLER_GEN_FQP) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN_FQP) object:headerFile="config/boilerplate.go.txt" paths="./..."
$(MAKE) fmt

.PHONY: fmt
fmt: goimports ## Run go fmt against code.
go fmt ./...
$(GOIMPORTS) -w .

# Protocol Buffer code generation
BUF_VERSION := v1.50.0
PROTOC_GEN_GO_GRPC_VER := v1.5.1
PROTOC_GEN_GO_VER := v1.36.5

$(TOOLS_DIR)/protoc-gen-go-grpc-$(PROTOC_GEN_GO_GRPC_VER):
GOBIN=$(TOOLS_DIR) go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@$(PROTOC_GEN_GO_GRPC_VER)
@mv $(TOOLS_DIR)/protoc-gen-go-grpc $(TOOLS_DIR)/protoc-gen-go-grpc-$(PROTOC_GEN_GO_GRPC_VER)

$(TOOLS_DIR)/protoc-gen-go-$(PROTOC_GEN_GO_VER):
GOBIN=$(TOOLS_DIR) go install google.golang.org/protobuf/cmd/protoc-gen-go@$(PROTOC_GEN_GO_VER)
@mv $(TOOLS_DIR)/protoc-gen-go $(TOOLS_DIR)/protoc-gen-go-$(PROTOC_GEN_GO_VER)


$(TOOLS_DIR)/buf-$(BUF_VERSION):
GOBIN=$(TOOLS_DIR) go install github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION)
@mv $(TOOLS_DIR)/buf $(TOOLS_DIR)/buf-$(BUF_VERSION)
.PHONY: clean
clean: ## Remove all Tinkerbell binaries
rm -f out/tinkerbell out/tinkerbell-linux-amd64 out/tinkerbell-linux-arm64

.PHONY: generate-proto
generate-proto: $(TOOLS_DIR)/buf-$(BUF_VERSION) $(TOOLS_DIR)/protoc-gen-go-grpc-$(PROTOC_GEN_GO_GRPC_VER) $(TOOLS_DIR)/protoc-gen-go-$(PROTOC_GEN_GO_VER) ## Generate code from proto files.
$(TOOLS_DIR)/buf-$(BUF_VERSION) generate
$(MAKE) fmt
.PHONY: clean-agent
clean-agent: ## Remove all Tink Agent binaries
rm -f out/tink-agent out/tink-agent-linux-amd64 out/tink-agent-linux-arm64

.PHONY: clean-tools
clean-tools: ## Remove all tools.
clean-tools: ## Remove all tools
rm -rf $(TOOLS_DIR)

.PHONY: clean-all
clean-all: clean clean-agent clean-tools ## Remove all binaries and tools
File renamed without changes.
46 changes: 46 additions & 0 deletions build/tools.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Tool versions
GOIMPORT_VER := latest
CONTROLLER_GEN_VERSION := v0.17.1
BUF_VERSION := v1.50.0
PROTOC_GEN_GO_GRPC_VER := v1.5.1
PROTOC_GEN_GO_VER := v1.36.5
UPX_VER := 4.2.4

# Tool fully qualified paths
TOOLS_DIR := $(PWD)/out/tools
GOIMPORTS_FQP := $(TOOLS_DIR)/goimports-$(GOIMPORT_VER)
CONTROLLER_GEN_FQP := $(TOOLS_DIR)/controller-gen-$(CONTROLLER_GEN_VERSION)
BUF_FQP := $(TOOLS_DIR)/buf-$(BUF_VERSION)
PROTOC_GEN_GO_GRPC_FQP := $(TOOLS_DIR)/protoc-gen-go-grpc-$(PROTOC_GEN_GO_GRPC_VER)
PROTOC_GEN_GO_FQP := $(TOOLS_DIR)/protoc-gen-go-$(PROTOC_GEN_GO_VER)
UPX_FQP := $(TOOLS_DIR)/upx-$(UPX_VER)-$(LOCAL_ARCH)

$(GOIMPORTS_FQP):
GOBIN=$(TOOLS_DIR) go install golang.org/x/tools/cmd/goimports@$(GOIMPORT_VER)
@mv $(TOOLS_DIR)/goimports $(GOIMPORTS_FQP)

$(CONTROLLER_GEN_FQP):
GOBIN=$(TOOLS_DIR) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION)
@mv $(TOOLS_DIR)/controller-gen $(CONTROLLER_GEN_FQP)

$(PROTOC_GEN_GO_GRPC_FQP):
GOBIN=$(TOOLS_DIR) go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@$(PROTOC_GEN_GO_GRPC_VER)
@mv $(TOOLS_DIR)/protoc-gen-go-grpc $(PROTOC_GEN_GO_GRPC_FQP)

$(PROTOC_GEN_GO_FQP):
GOBIN=$(TOOLS_DIR) go install google.golang.org/protobuf/cmd/protoc-gen-go@$(PROTOC_GEN_GO_VER)
@mv $(TOOLS_DIR)/protoc-gen-go $(PROTOC_GEN_GO_FQP)

$(BUF_FQP):
GOBIN=$(TOOLS_DIR) go install github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION)
@mv $(TOOLS_DIR)/buf $(BUF_FQP)

$(UPX_FQP):
mkdir -p $(TOOLS_DIR)
(cd $(TOOLS_DIR); curl -sSfLO https://github.com/upx/upx/releases/download/v$(UPX_VER)/upx-$(UPX_VER)-$(LOCAL_ARCH_ALT)_linux.tar.xz)
(cd $(TOOLS_DIR); tar -xvf upx-$(UPX_VER)-$(LOCAL_ARCH_ALT)_linux.tar.xz)
@mv $(TOOLS_DIR)/upx-$(UPX_VER)-$(LOCAL_ARCH_ALT)_linux/upx $(UPX_FQP)
@rm -rf $(TOOLS_DIR)/upx-$(UPX_VER)-$(LOCAL_ARCH_ALT)_linux*

.PHONY: tools
tools: $(GOIMPORTS_FQP) $(CONTROLLER_GEN_FQP) $(PROTOC_GEN_GO_GRPC_FQP) $(PROTOC_GEN_GO_FQP) $(BUF_FQP) $(UPX_FQP) ## Install all tools
0