Add validate-in-container target

This change adds a validate-in-container make target that can be used to run
the make validate target in a container instead of requiring the dependencies
to be available on the system. This mirrors what is already done for the vendor
target and allows additional targets to be added.

A PODMANCMD make variable is also added to allow for the podman binary to be
overridden in cases where this is not available.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar
2022-11-24 17:12:22 +01:00
parent 34cc61d167
commit ba522e8f3c

@ -289,13 +289,21 @@ vendor:
$(GO) mod vendor
$(GO) mod verify
.PHONY: vendor-in-container
vendor-in-container:
podman run --rm --env HOME=/root \
# We define *-in-container targets for the following make targets. This allow the targets to be run in a container.
# Note that the PODMANCMD can also be overridden to allow a different container CLI to be used on systems where podman is not already available.
IN_CONTAINER_TARGETS = vendor validate
PODMANCMD ?= podman
IN_CONTAINER = $(patsubst %,%-in-container,$(IN_CONTAINER_TARGETS))
.PHONY: $(IN_CONTAINER)
$(IN_CONTAINER): %-in-container:
$(PODMANCMD) run --rm --env HOME=/root \
-v $(CURDIR):/src -w /src \
--security-opt label=disable \
docker.io/library/golang:1.17 \
make vendor
make $(*)
###
### Primary binary-build targets