Skip to content

Commit

Permalink
docs: update instructions for building kubectl-retina (#143)
Browse files Browse the repository at this point in the history
I previously removed the kubectl-retina container and
kubectl-retina-image Make targets in #112, which transitioned to
building kubectl-retina artifacts with GoReleaser and attaching tarballs
to the GitHub releases instead of publishing images.
 
That change was made for Krew #108.

This change updates the docs for building kubectl-retina to show how to
simply build it with `go build`. Explanation was also added describing
how to build for all supported platforms with GoReleaser.

Signed-off-by: Evan Baker <[email protected]>
  • Loading branch information
rbtr authored Mar 26, 2024
1 parent b48ca3c commit 99540a5
Show file tree
Hide file tree
Showing 7 changed files with 972 additions and 241 deletions.
74 changes: 0 additions & 74 deletions .github/workflows/integration.yaml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ hack/tools/bin
.vscode/

dist/
bin/
57 changes: 18 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
RMDIR := rm -rf

## Globals
GIT_CURRENT_BRANCH_NAME := $(shell git rev-parse --abbrev-ref HEAD)

REPO_ROOT = $(shell git rev-parse --show-toplevel)
ifndef TAG
Expand All @@ -13,7 +14,6 @@ OUTPUT_DIR = $(REPO_ROOT)/output
BUILD_DIR = $(OUTPUT_DIR)/$(GOOS)_$(GOARCH)
RETINA_BUILD_DIR = $(BUILD_DIR)/retina
RETINA_DIR = $(REPO_ROOT)/controller
KUBECTL_RETINA_BUILD_DIR = $(OUTPUT_DIR)/kubectl-retina
OPERATOR_DIR=$(REPO_ROOT)/operator
CAPTURE_WORKLOAD_DIR = $(REPO_ROOT)/captureworkload

Expand Down Expand Up @@ -63,15 +63,16 @@ help: ## Display this help

##@ Tools

TOOLS_DIR = $(REPO_ROOT)/hack/tools
TOOLS_BIN_DIR = $(TOOLS_DIR)/bin
GOFUMPT := $(TOOLS_BIN_DIR)/gofumpt
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
GINKGO := $(TOOLS_BIN_DIR)/ginkgo
MOCKGEN := $(TOOLS_BIN_DIR)/mockgen
ENVTEST := $(TOOLS_BIN_DIR)/setup-envtest
GIT_CURRENT_BRANCH_NAME := $(shell git rev-parse --abbrev-ref HEAD)
TOOLS_DIR = $(REPO_ROOT)/hack/tools
TOOLS_BIN_DIR = $(TOOLS_DIR)/bin

GOFUMPT = $(TOOLS_BIN_DIR)/gofumpt
GOLANGCI_LINT = $(TOOLS_BIN_DIR)/golangci-lint
GORELEASER = $(TOOLS_BIN_DIR)/goreleaser
CONTROLLER_GEN = $(TOOLS_BIN_DIR)/controller-gen
GINKGO = $(TOOLS_BIN_DIR)/ginkgo
MOCKGEN = $(TOOLS_BIN_DIR)/mockgen
ENVTEST = $(TOOLS_BIN_DIR)/setup-envtest

$(TOOLS_DIR)/go.mod:
cd $(TOOLS_DIR); go mod init && go mod tidy
Expand All @@ -89,6 +90,11 @@ golangci-lint: $(GOLANGCI_LINT) ## Build golangci-lint
$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR); go mod download; go build -tags=tools -o bin/controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen

goreleaser: $(GORELEASER) ## Build goreleaser

$(GORELEASER): $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR); go mod download; go build -tags=tools -o bin/goreleaser github.com/goreleaser/goreleaser

controller-gen: $(CONTROLLER_GEN) ## Build controller-gen

$(GINKGO): $(TOOLS_DIR)/go.mod
Expand Down Expand Up @@ -140,23 +146,14 @@ clean: ## clean build artifacts

##@ Build Binaries

retina: ## builds both retina and kapctl binaries
$(MAKE) retina-binary kubectl-retina
retina: ## builds retina binary
$(MAKE) retina-binary

retina-binary: ## build the Retina binary
go generate ./...
export CGO_ENABLED=0
go build -v -o $(RETINA_BUILD_DIR)/retina$(EXE_EXT) -gcflags="-dwarflocationlists=true" -ldflags "-X main.version=$(TAG) -X main.applicationInsightsID=$(APP_INSIGHTS_ID)" $(RETINA_DIR)/main.go

kubectl-retina-binary-%: ## build kubectl plugin locally.
export CGO_ENABLED=0 && \
export GOOS=$(shell echo $* |cut -f1 -d-) GOARCH=$(shell echo $* |cut -f2 -d-) && \
go build -v \
-o $(KUBECTL_RETINA_BUILD_DIR)/kubectl-retina-$${GOOS}-$${GOARCH} \
-gcflags="-dwarflocationlists=true" \
-ldflags "-X github.com/microsoft/retina/cli/cmd.Version=$(TAG)" \
github.com/microsoft/retina/cli

retina-capture-workload: ## build the Retina capture workload
cd $(CAPTURE_WORKLOAD_DIR) && CGO_ENABLED=0 go build -v -o $(RETINA_BUILD_DIR)/captureworkload$(EXE_EXT) -gcflags="-dwarflocationlists=true" -ldflags "-X main.version=$(TAG)"

Expand Down Expand Up @@ -268,18 +265,6 @@ retina-operator-image: ## build the retina linux operator image.
APP_INSIGHTS_ID=$(APP_INSIGHTS_ID) \
CONTEXT_DIR=$(REPO_ROOT)

kubectl-retina-image: ## build the kubectl-retina image.
echo "Building for $(PLATFORM)"
$(MAKE) container-$(CONTAINER_BUILDER) \
PLATFORM=$(PLATFORM) \
DOCKERFILE=cli/Dockerfile.kubectl-retina \
REGISTRY=$(IMAGE_REGISTRY) \
IMAGE=$(KUBECTL_RETINA_IMAGE) \
VERSION=$(TAG) \
TAG=$(RETINA_PLATFORM_TAG) \
APP_INSIGHTS_ID=$(APP_INSIGHTS_ID) \
CONTEXT_DIR=$(REPO_ROOT)

proto-gen: ## generate protobuf code
docker build --platform=linux/amd64 \
-t $(IMAGE_REGISTRY)/$(RETINA_PROTO_IMAGE):$(RETINA_PLATFORM_TAG) \
Expand Down Expand Up @@ -311,18 +296,12 @@ manifest-operator-image: ## create a multiplatform manifest for the operator ima
$(eval FULL_IMAGE_NAME=$(IMAGE_REGISTRY)/$(RETINA_OPERATOR_IMAGE):$(TAG))
docker buildx imagetools create -t $(FULL_IMAGE_NAME) $(foreach platform,linux/amd64, $(FULL_IMAGE_NAME)-$(subst /,-,$(platform)))

manifest-kubectl-retina-image: ## create a multiplatform manifest for the kubectl-retina image
$(eval FULL_IMAGE_NAME=$(IMAGE_REGISTRY)/$(KUBECTL_RETINA_IMAGE):$(TAG))
docker buildx imagetools create -t $(FULL_IMAGE_NAME) $(foreach platform,linux/amd64 linux/arm64, $(FULL_IMAGE_NAME)-$(subst /,-,$(platform)))

manifest:
echo "Building for $(COMPONENT)"
if [ "$(COMPONENT)" = "retina" ]; then \
$(MAKE) manifest-retina-image; \
elif [ "$(COMPONENT)" = "operator" ]; then \
$(MAKE) manifest-operator-image; \
elif [ "$(COMPONENT)" = "kubectl-retina" ]; then \
$(MAKE) manifest-kubectl-retina-image; \
fi

##@ Tests
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ Prerequisites: Go, Helm

1. Clone the repo, then install Retina on your Kubernetes cluster

```bash
make helm-install
```
```bash
make helm-install
```

2. Follow steps in [Using Prometheus and Grafana](https://retina.sh/docs/installation/prometheus-unmanaged) to set up metrics collection and visualization.

Expand All @@ -55,22 +55,23 @@ Currently, Retina CLI only supports Linux.

- Option 1: Download from Release

Download `kubectl-retina` from the latest [Retina release](https://github.com/microsoft/retina/releases).
Download the correct `kubectl-retina` package for your platform from the latest [Retina release](https://github.com/microsoft/retina/releases).
Feel free to move the binary to `/usr/local/bin/`, or add it to your `PATH` otherwise.

- Option 2: Build from source

Requirements:

- go 1.21 or newer
- GNU make

Clone the Retina repo and execute:

```shell
make install-kubectl-retina
go build -o bin/kubectl-retina cli/main.go
```

and move bin/kubectl-retina in to your $PATH.

Execute Retina:

```shell
Expand All @@ -85,15 +86,15 @@ Prerequisites: Go, Helm

1. Clone the repo, then install Retina with Capture operator support on your Kubernetes cluster

```bash
make helm-install-with-operator
```
```bash
make helm-install-with-operator
```

2. Follow steps in [Capture CRD](https://retina.sh/docs/captures/#option-2-capture-crd-custom-resource-definition) for documentation of the CRD and examples for setting up Captures.

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit <https://cla.opensource.microsoft.com>.

Expand Down Expand Up @@ -130,7 +131,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope

For bugs or feature requests, open an [issue](https://github.com/microsoft/retina/issues).
For security or vulnerability concerns, see [SECURITY.md](SECURITY.md).
For other communication, contact the maintainers at <[email protected]>
For other communication, contact the maintainers at <[email protected]>

[goreport-img]: https://goreportcard.com/badge/github.com/microsoft/retina
[goreport]: https://goreportcard.com/report/github.com/microsoft/retina
Expand Down
17 changes: 10 additions & 7 deletions docs/installation/cli.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CLI Setup

Currently, Retina CLI only supports Linux.
Currently, Retina CLI supports Linux, Windows, and MacOS on x86_64 and ARM64 platforms.

For CLI usage, see [Capture with Retina CLI](../captures/cli.md).

Expand All @@ -11,13 +11,16 @@ Feel free to move the binary to `/usr/local/bin/`, or add it to your `PATH` othe

## Option 2: Build from source

Clone the Retina repo and execute:
Building the CLI requires go1.21 or greater.

```shell
make install-kubectl-retina
To build the CLI simply with Go:

```bash
go build -o bin/kubectl-retina cli/main.go
```

Requirements:
To cross-compile for all supported platforms, use [GoReleaser](https://goreleaser.com/):

- go 1.21 or newer
- GNU make
```bash
goreleaser build --snapshot --clean
```
Loading

0 comments on commit 99540a5

Please sign in to comment.