Skip to content

Commit

Permalink
Feat makefile help (sustainable-computing-io#1332)
Browse files Browse the repository at this point in the history
* Makefile: Add usage and more image build options

This change introduces a helpful message for a user
that issues a `make help` command. It also adds options
to build the container images with/without dcgm explicitly.
This will help improve build time for developers that
aren't using dcgm.

Signed-off-by: Maryam Tahhan <[email protected]>

* Dockerfile: remove trailing whitespace

Signed-off-by: Maryam Tahhan <[email protected]>

* Docker: fix build-arg INSTALL_DCGM=false

The dockerfile was only checking that the INSTALL_DCGM
build argument was set and not it's value. So if
INSTALL_DCGM=false was being passed, it considered the
build argument as set. This change explicitly checks
the value as true.

Signed-off-by: Maryam Tahhan <[email protected]>

---------

Signed-off-by: Maryam Tahhan <[email protected]>
  • Loading branch information
maryamtahhan authored Apr 8, 2024
1 parent c6080eb commit 3d1d7ab
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 40 deletions.
93 changes: 57 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@ all: kepler

include bpfassets/libbpf/Makefile

##@ Help

# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)


### env define ###
export BIN_TIMESTAMP ?=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
export TIMESTAMP ?=$(shell echo $(BIN_TIMESTAMP) | tr -d ':' | tr 'T' '-' | tr -d 'Z')
Expand Down Expand Up @@ -68,83 +86,85 @@ ifndef GOBIN
GOBIN := $(GOPATH)/bin
endif

# NOTE: project related tools get installed to tmp dir which is ignored by
# NOTE: project related tools get installed to tmp dir which is ignored by
PROJECT_DIR := $(shell dirname $(abspath $(firstword $(MAKEFILE_LIST))))
TOOLS_DIR=$(PROJECT_DIR)/tmp/bin
KUSTOMIZE = $(TOOLS_DIR)/kustomize
GOVULNCHECK = $(TOOLS_DIR)/govulncheck

base_dir := $(patsubst %/,%,$(dir $(realpath $(firstword $(MAKEFILE_LIST)))))

### Default ###
kepler: build_containerized
##@ Default
kepler: build_containerized ## Build Kepler.
.PHONY: kepler

clean: clean-cross-build
.PHONY: clean

### build container ###
build_containerized: tidy-vendor format
##@ Container build.
image_builder_check:
@if [ -z '$(CTR_CMD)' ] ; then echo '!! ERROR: containerized builds require podman||docker CLI, none found $$PATH' >&2 && exit 1; fi
echo BIN_TIMESTAMP==$(BIN_TIMESTAMP)

build_image: image_builder_check ## Build image without DCGM.
# build kepler without dcgm
$(CTR_CMD) build -t $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_BUILD_TAG) \
-f $(DOCKERFILE) \
--network host \
--build-arg BIN_TIMESTAMP=$(BIN_TIMESTAMP) \
--build-arg INSTALL_DCGM="false" \
--build-arg VERSION=$(VERSION) \
--platform="linux/$(GOARCH)" \
.

$(CTR_CMD) tag $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_BUILD_TAG) $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_TAG)
.PHONY: build_image

build_image_dcgm: image_builder_check ## Build image with DCGM.
# build kepler with dcgm
$(CTR_CMD) build -t $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_BUILD_TAG)-"dcgm" \
-f $(DOCKERFILE) \
--network host \
--build-arg BIN_TIMESTAMP=$(BIN_TIMESTAMP) \
--build-arg INSTALL_DCGM="true" \
--build-arg VERSION=$(VERSION) \
--platform="linux/$(GOARCH)" \
.

$(CTR_CMD) tag $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_BUILD_TAG)-dcgm $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_TAG)-dcgm
.PHONY: build_image_dcgm

build_containerized: tidy-vendor format build_image build_image_dcgm ## Build ALL container images.
.PHONY: build_containerized

save-image:
save-image: ## Save container image.
@mkdir -p _output
$(CTR_CMD) save $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_TAG) | gzip > "${IMAGE_OUTPUT_PATH}"
.PHONY: save-image

load-image:
load-image: ## Load container image.
$(CTR_CMD) load -i "${INPUT_PATH}"
.PHONY: load-image

image-prune:
image-prune: ## Image prune.
$(CTR_CMD) image prune -a -f || true
.PHONY: image-prune

push-image:
push-image: ## Push image.
$(CTR_CMD) push $(CTR_CMD_PUSH_OPTIONS) $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_TAG)
.PHONY: push-image

##@ General build
clean-cross-build:
$(RM) -r '$(CROSS_BUILD_BINDIR)'
$(RM) -rf $(OUTPUT_DIR)/staging
if [ -d '$(OUTPUT_DIR)' ]; then rmdir --ignore-fail-on-non-empty '$(OUTPUT_DIR)'; fi
.PHONY: clean-cross-build

### build binary ###
build: clean_build_local _build_local copy_build_local
build: clean_build_local _build_local copy_build_local ## Build binary and copy to $(OUTPUT_DIR)/bin
.PHONY: build

_build_local: genlibbpf
_build_local: genlibbpf ## Build Kepler binary locally.
@echo TAGS=$(GO_BUILD_TAGS)
@mkdir -p "$(CROSS_BUILD_BINDIR)/$(GOOS)_$(GOARCH)"
+@$(GOENV) go build -v -tags ${GO_BUILD_TAGS} -o $(CROSS_BUILD_BINDIR)/$(GOOS)_$(GOARCH)/kepler -ldflags $(LDFLAGS) ./cmd/exporter/exporter.go

container_build:
container_build: ## Run a container and build Kepler inside it.
$(CTR_CMD) run --rm \
-v $(base_dir):/kepler:Z -w /kepler \
--user $(shell id -u):$(shell id -g) \
Expand All @@ -153,13 +173,14 @@ container_build:
$(BUILDER_IMAGE) \
git config --add safe.directory /kepler && make build

build_rpm:
##@ RPM build
build_rpm: ## Build the Kepler Binary RPM.
rpmbuild packaging/rpm/kepler.spec --build-in-place -bb

build_container_rpm:
build_container_rpm: ## Build the Containerized Kepler RPM.
rpmbuild packaging/rpm/container-kepler.spec --build-in-place -bb

containerized_build_rpm:
containerized_build_rpm: ## Build the Kepler Binary RPM inside a container.
@mkdir -p $(base_dir)/$(OUTPUT_DIR)/rpmbuild
$(CTR_CMD) run --rm \
-v $(base_dir):/kepler:Z -w /kepler -v $(base_dir)/$(OUTPUT_DIR)/rpmbuild:/opt/app-root/src/rpmbuild \
Expand All @@ -169,7 +190,7 @@ containerized_build_rpm:
$(BUILDER_IMAGE) \
make build_rpm

containerized_build_container_rpm:
containerized_build_container_rpm: ## Build the Containerized Kepler RPM inside a container.
@mkdir -p $(base_dir)/$(OUTPUT_DIR)/rpmbuild
$(CTR_CMD) run --rm \
-v $(base_dir):/kepler:Z -w /kepler -v $(base_dir)/$(OUTPUT_DIR)/rpmbuild:/opt/app-root/src/rpmbuild \
Expand All @@ -195,10 +216,10 @@ cross-build-linux-s390x:
+$(MAKE) _build_local GOOS=linux GOARCH=s390x
.PHONY: cross-build-linux-s390x

cross-build: clean_build_local cross-build-linux-amd64 cross-build-linux-arm64 cross-build-linux-s390x copy_build_local
cross-build: clean_build_local cross-build-linux-amd64 cross-build-linux-arm64 cross-build-linux-s390x copy_build_local ## Build Kepler for multiple archs.
.PHONY: cross-build

### toolkit ###
## toolkit ###
tidy-vendor:
go mod tidy -v
go mod vendor
Expand Down Expand Up @@ -246,7 +267,7 @@ test-container-verbose: ginkgo-set tidy-vendor
-covermode=atomic -coverprofile=coverage.out \
-v $$(go list ./... | grep pkg | grep -v bpfassets) \
--race -cover --count=1 --vet=all

test-mac-verbose: ginkgo-set
@echo TAGS=$(GO_TEST_TAGS)
@go test $$(go list ./... | grep pkg | grep -v bpfassets) --race --bench=. -cover --count=1 --vet=all
Expand Down Expand Up @@ -288,56 +309,56 @@ build-manifest: kustomize
./hack/build-manifest.sh "${OPTS}"
.PHONY: build-manifest

##@ Development env
##@ Development Env
CLUSTER_PROVIDER ?= kind
LOCAL_DEV_CLUSTER_VERSION ?= main
KIND_WORKER_NODES ?=2

cluster-clean: build-manifest
cluster-clean: build-manifest ## Undeploy Kepler in the cluster.
./hack/cluster-clean.sh
.PHONY: cluster-clean

cluster-deploy:
cluster-deploy: ## Deploy Kepler in the cluster.
./hack/cluster-deploy.sh
.PHONY: cluster-deploy

cluster-up:
cluster-up: ## Create the Kind cluster
CLUSTER_PROVIDER=$(CLUSTER_PROVIDER) \
LOCAL_DEV_CLUSTER_VERSION=$(LOCAL_DEV_CLUSTER_VERSION) \
KIND_WORKER_NODES=$(KIND_WORKER_NODES) \
./hack/cluster.sh up
.PHONY: cluster-up

cluster-down:
cluster-down: ## Delete the Kind cluster.
CLUSTER_PROVIDER=$(CLUSTER_PROVIDER) \
LOCAL_DEV_CLUSTER_VERSION=$(LOCAL_DEV_CLUSTER_VERSION) \
KIND_WORKER_NODES=$(KIND_WORKER_NODES) \
./hack/cluster.sh down
.PHONY: cluster-down

cluster-restart:
cluster-restart: ## Restart the Kind cluster.
CLUSTER_PROVIDER=$(CLUSTER_PROVIDER) \
LOCAL_DEV_CLUSTER_VERSION=$(LOCAL_DEV_CLUSTER_VERSION) \
KIND_WORKER_NODES=$(KIND_WORKER_NODES) \
./hack/cluster.sh restart
.PHONY: cluster-restart

e2e:
e2e: # Run E2E integration tests.
./hack/verify.sh integration
.PHONY: e2e

### platform-validation ###
##@ platform-validation

VALIDATION_DOCKERFILE := $(SRC_ROOT)/build/Dockerfile.kepler-validator

build-validator: tidy-vendor format
build-validator: tidy-vendor format ## Build Validator.
@echo TAGS=$(GO_BUILD_TAGS)
@mkdir -p "$(CROSS_BUILD_BINDIR)/$(GOOS)_$(GOARCH)"
+@$(GOENV) go build -v -tags ${GO_BUILD_TAGS} -o $(CROSS_BUILD_BINDIR)/$(GOOS)_$(GOARCH)/validator -ldflags $(LDFLAGS) ./cmd/validator/validator.go
cp $(CROSS_BUILD_BINDIR)/$(GOOS)_$(GOARCH)/validator $(CROSS_BUILD_BINDIR)
.PHONY: build-validator

build-validation-container:
build-validation-container: ## Build validation Container.
$(CTR_CMD) build -t $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_TAG) \
-f $(VALIDATION_DOCKERFILE) .
.PHONY: build-validation-container
Expand All @@ -350,7 +371,7 @@ get-env:
$(CTR_CMD) run -i --rm -v $(SRC_ROOT)/e2e/platform-validation:/output $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_TAG) /usr/bin/validator -gen-env=true
.PHONY: get-env

platform-validation: ginkgo-set get-env
platform-validation: ginkgo-set get-env ## Run Kepler platform validation.
./hack/verify.sh platform
.PHONY: platform-validation

Expand Down
8 changes: 4 additions & 4 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ RUN yum -y update

ENV NVIDIA_VISIBLE_DEVICES=all
ENV NVIDIA_DRIVER_CAPABILITIES=utility
ENV NVIDIA_MIG_CONFIG_DEVICES=all
ENV NVIDIA_MIG_MONITOR_DEVICES=all
ENV NVIDIA_MIG_CONFIG_DEVICES=all
ENV NVIDIA_MIG_MONITOR_DEVICES=all

RUN INSTALL_PKGS=" \
libbpf \
" && \
yum install -y $INSTALL_PKGS
yum install -y $INSTALL_PKGS

RUN if [ "$TARGETARCH" == "amd64" ]; then \
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm; \
yum install -y cpuid; \
if [[ ! -z "$INSTALL_DCGM" ]]; then \
if [[ ! -z "$INSTALL_DCGM" && "$INSTALL_DCGM" == "true" ]]; then \
dnf config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel9/x86_64/cuda-rhel9.repo; \
yum install -y datacenter-gpu-manager; \
fi; \
Expand Down

0 comments on commit 3d1d7ab

Please sign in to comment.