From 0a0af13bea5a2e9b7c4cfac82a3ce89c54182214 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Fri, 10 Jun 2022 16:21:31 +0300 Subject: [PATCH] [#159] Unify docker targets for binary building Signed-off-by: Alex Vanin --- Makefile | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 52776f1..a0a5ba0 100644 --- a/Makefile +++ b/Makefile @@ -14,20 +14,11 @@ BINDIR = bin DIRS = $(BINDIR) BINS = $(BINDIR)/neofs-http-gw -.PHONY: all docker/all $(BINS) $(DIRS) docker/$(BINS) dep test cover fmt image image-push dirty-image lint docker/lint version clean +.PHONY: all $(BINS) $(DIRS) dep docker/ test cover fmt image image-push dirty-image lint docker/lint version clean # Make all binaries all: $(BINS) -docker/all: - @echo "=> Building binary using clean Docker environment" - @docker run --rm -t \ - -v `pwd`:/src \ - -w /src \ - -u "$$(id -u):$$(id -g)" \ - --env HOME=/src \ - golang:$(GO_VERSION) make all - $(BINS): $(DIRS) dep @echo "⇒ Build $@" CGO_ENABLED=0 \ @@ -40,15 +31,6 @@ $(DIRS): @echo "⇒ Ensure dir: $@" @mkdir -p $@ -docker/$(BINS): - @echo "=> Building binary using clean Docker environment" - @docker run --rm -t \ - -v `pwd`:/src \ - -w /src \ - -u "$$(id -u):$$(id -g)" \ - --env HOME=/src \ - golang:$(GO_VERSION) make $(BINS) - # Pull go dependencies dep: @printf "⇒ Download requirements: " @@ -60,6 +42,17 @@ dep: GO111MODULE=on \ go mod tidy -v && echo OK +docker/%: + $(if $(filter $*,all $(BINS)), \ + @echo "=> Running 'make $*' in clean Docker environment" && \ + docker run --rm -t \ + -v `pwd`:/src \ + -w /src \ + -u `stat -c "%u:%g" .` \ + --env HOME=/src \ + golang:$(GO_VERSION) make $*,\ + @echo "supported docker targets: all $(BINS) lint") + # Run tests test: @go test ./... -cover