假设我的源文件位于
中~/dev/root
内部~/dev/root
是许多项目。
e.g。
~/dev/root/libraries/libx
~/dev/root/apps/app/appy
~/dev/root/docker/appy
我使用的构建工具名为tundra2,并从根级别调用。
因此,如果我运行tundra2 production appy,它会将它的输出产生到
~/dev/root/t2-output/linux64-gcc-production-default
二进制文件直接位于该目录下方。还有位于该目录中子目录内的中间文件。
现在烦人的一点。无论出于何种原因,docker build都使用一个守护进程,它将所有正在运行的目录中的所有内容复制到一个临时目录中。然后它从那里产生它的图像。我还没有花时间尝试扩展tundra2以应对docker所以我一直在使用Makefile。
所以在docker / appy目录里面我有我的Dockerfile。我还有一个makefile。想法是进入该目录并运行make。 如果一切都构建完毕,它应该将输出从t2-output复制到docker / appy目录并运行docker build。
到目前为止,我已经指定了构建目标,如:
T2OUT=../../t2-output/linux64-gcc-production-default
TAG = "appy"
all: $(T2OUT)/appy
$(T2OUT)/appy:
cd $(T2OUT) && tundra2 production appy
cp $< .
docker build -t $(TAG) .
等
以上是非常麻烦的。所以我尝试使用VPATH进行下面的实验,但这不起作用。 make --debug=v
确认了这一点。你能建议一个替代方案吗? (我甚至可以考虑另一种构建工具,前提是它不是基于npm的)
VPATH = .. / .. / T2输出/ LINUX64-GCC-生产默认 %。所以: ...
有时我直接从〜/ dev / root
运行tundra2 build所以我想要做的就是检测那个appy和复制的appy是不同的。
即。如果~/dev/root/t2-output/linux64-gcc-production-default/appy
与:~/dev/root/cluster/docker/appy/appy
然后将~/dev/root/t2-output/linux64-gcc-production-default/appy
复制到~/dev/root/cluster/docker/appy/appy
如果~/dev/root/t2-output/linux64-gcc-production-default/appy
不存在,即使~/dev/root/cluster/docker/appy/appy
确实存在,我们也应该去../../ ..运行tundra2并将输出复制到docker / appy目录,以便我们可以运行docker build
答案 0 :(得分:0)
经过大量的实验,我发现这很有效。它非常通用。所以我只需要确保,BUILDROOT适合makefile的位置,而且服务是正确的。我可以在我的环境中设置BUILDROOT。
BUILDROOT=../../..
T2OUT=$(BUILDROOT)/t2-output/linux64-gcc-production-default
TUNDRA2=cd $(BUILDROOT); tundra2 production
DOCKER_TAG=remoteregistry.example.com/path/appy
SERVICES=appy
all: $(SERVICES)
docker build -t $(DOCKER_TAG) .
# For some libraries the build target is different so I had to specify the
# build dependancy
$(T2OUT)/lib.so:
$(TUNDRA2) target
$(T2OUT)/%:
$(TUNDRA2) $*
%: $(T2OUT)/%
cp $< $@
clean: $(SERVICES)
rm -f $(SERVICES)
.PHONY: all clean