From ba522e8f3ca182d82907aa146ce1d99ef3551231 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 24 Nov 2022 17:12:22 +0100 Subject: [PATCH] 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 --- Makefile | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index bcbe37e912..8e63f8ab13 100644 --- a/Makefile +++ b/Makefile @@ -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