【发布时间】:2017-06-11 21:27:14
【问题描述】:
这是Makefile: run the same command with different arguments on different targets的延续。
代码
COMMIT := $(shell git rev-parse HEAD)
images := base web proxy lb users api
$(images): base
@echo "Building $@"
docker build -f Dockerfile.$@ --no-cache=true -t $@:$(COMMIT) .
build: $(images)
rebuild: $(images) # I want this to run with --no-cache=true
基本上,build 调用所有image 目标(base 是第一个目标),并为每个目标运行docker build 和--no-cache=true。
问题
我想要一个rebuild 目标,它运行所有image 目标与--no-cache=false 而不是--no-cache=true,而不复制代码。我想正确的方法是在rebuild 和build 中设置一个变量,其范围将涵盖像任何images 这样的依赖目标。
我的问题
如何在范围涵盖所有依赖目标的目标中定义变量?
【问题讨论】:
-
查看my answer to your first question 并完全摆脱特定于目标的变量。
-
不,特定于目标的变量会自动执行此操作,正如 Artur 的回答所示。 IMO,它们比使用
call好得多。
标签: makefile