问题描述
这是.
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
.
Essentially, build
calls all image
targets (base
being the first one), and runs docker build
with --no-cache=true
for each one.
我希望有一个rebuild
目标,该目标可以使用--no-cache=false
而不是--no-cache=true
运行所有image
目标,而无需复制代码.我猜想正确的方法是在rebuild
和build
中设置一个变量,其范围将覆盖诸如images
中任何一个的依赖目标.
I would like to have a rebuild
target which runs all image
targets with --no-cache=false
rather than --no-cache=true
, without duplicating the code. I guess that the right way is to set a variable in rebuild
and build
whose scope would cover dependent targets like any of the images
.
如何在目标范围内涵盖所有相关目标的变量中定义变量?
How do I define a variable in a target whose scope covers all dependent targets?
推荐答案
非常相似,例如提到的问题:
Quite similar, like in mentioned question:
images := base web proxy lb users api
$(images):
@echo $@ docker --no-cache=$(NO_CACHE)
build: NO_CACHE=true
rebuild: NO_CACHE=false
rebuild build: $(images)
例如,如果您想调用make base
,则可能要为NO_CACHE
设置默认值.
You may want to set a default value for NO_CACHE
in case you would like to call make base
for example.
这篇关于Makefile:将变量传播到从属目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!