From a7f3398a68a443461adb398acdaa832fb004e979 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 30 Jun 2021 14:08:06 +0200 Subject: [PATCH] Update makefile with Development docker image Signed-off-by: Evan Lezar --- Makefile | 81 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 72 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 7ff8edba..33a923ce 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# Copyright (c) 2017-2021, NVIDIA CORPORATION. All rights reserved. +# Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -27,14 +27,39 @@ MODULE := github.com/NVIDIA/nvidia-container-toolkit docker-native: include $(CURDIR)/docker/docker.mk +ifeq ($(IMAGE),) +REGISTRY ?= nvidia +IMAGE=$(REGISTRY)/container-toolkit +endif +IMAGE_TAG ?= $(GOLANG_VERSION) +BUILDIMAGE ?= $(IMAGE):$(IMAGE_TAG)-devel + +EXAMPLES := $(patsubst ./examples/%/,%,$(sort $(dir $(wildcard ./examples/*/)))) +EXAMPLE_TARGETS := $(patsubst %,example-%, $(EXAMPLES)) + +MAKE_TARGETS := binary build all check fmt assert-fmt lint lint-internal vet test examples coverage generate + +TARGETS := $(MAKE_TARGETS) $(EXAMPLE_TARGETS) + +DOCKER_TARGETS := $(patsubst %,docker-%, $(TARGETS)) +.PHONY: $(TARGETS) $(DOCKER_TARGETS) + GOOS ?= linux binary: GOOS=$(GOOS) go build -ldflags "-s -w" -o "$(LIB_NAME)" $(MODULE)/cmd/$(LIB_NAME) -# Define the check targets for the Golang codebase -.PHONY: check fmt assert-fmt ineffassign lint misspell vet -check: assert-fmt lint misspell vet +build: + GOOS=$(GOOS) go build ./... + +examples: $(EXAMPLE_TARGETS) +$(EXAMPLE_TARGETS): example-%: + GOOS=$(GOOS) go build ./examples/$(*) + +all: check test build binary +check: assert-fmt lint vet + +# Apply go fmt to the codebase fmt: go list -f '{{.Dir}}' $(MODULE)/... \ | xargs gofmt -s -l -w @@ -55,8 +80,12 @@ ineffassign: ineffassign $(MODULE)/... lint: - # We use `go list -f '{{.Dir}}' $(GOLANG_PKG_PATH)/...` to skip the `vendor` folder. - go list -f '{{.Dir}}' $(MODULE)/... | xargs golint -set_exit_status +# We use `go list -f '{{.Dir}}' $(MODULE)/...` to skip the `vendor` folder. + go list -f '{{.Dir}}' $(MODULE)/... | grep -v /internal/ | xargs golint -set_exit_status + +lint-internal: +# We use `go list -f '{{.Dir}}' $(MODULE)/...` to skip the `vendor` folder. + go list -f '{{.Dir}}' $(MODULE)/internal/... | xargs golint -set_exit_status misspell: misspell $(MODULE)/... @@ -65,8 +94,42 @@ vet: go vet $(MODULE)/... COVERAGE_FILE := coverage.out -test: - go test -coverprofile=$(COVERAGE_FILE) $(MODULE)/... +test: build + go test -v -coverprofile=$(COVERAGE_FILE) $(MODULE)/... coverage: test - go tool cover -func=$(COVERAGE_FILE) + cat $(COVERAGE_FILE) | grep -v "_mock.go" > $(COVERAGE_FILE).no-mocks + go tool cover -func=$(COVERAGE_FILE).no-mocks + +generate: + go generate $(MODULE)/... + +# Generate an image for containerized builds +# Note: This image is local only +.PHONY: .build-image .pull-build-image .push-build-image +.build-image: docker/Dockerfile.devel + if [ x"$(SKIP_IMAGE_BUILD)" = x"" ]; then \ + $(DOCKER) build \ + --progress=plain \ + --build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \ + --tag $(BUILDIMAGE) \ + -f $(^) \ + docker; \ + fi + +.pull-build-image: + $(DOCKER) pull $(BUILDIMAGE) + +.push-build-image: + $(DOCKER) push $(BUILDIMAGE) + +$(DOCKER_TARGETS): docker-%: .build-image + @echo "Running 'make $(*)' in docker container $(BUILDIMAGE)" + $(DOCKER) run \ + --rm \ + -e GOCACHE=/tmp/.cache \ + -v $(PWD):$(PWD) \ + -w $(PWD) \ + --user $$(id -u):$$(id -g) \ + $(BUILDIMAGE) \ + make $(*)