Skip to content

Commit c242f61

Browse files
committed
[BUILD] Make docker-image building more reliable
We need to create a tighter coupling between the build system and the resulting docker images to prevent make from over-optimizing steps away. Fixes FAB-1145 Change-Id: I50c7cdf98e173c88ff6722d6c28aeade7395428e Signed-off-by: Greg Haskins <[email protected]>
1 parent c0bc726 commit c242f61

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

Makefile

+10-10
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,20 @@ membersrvc-image:
8989

9090
.PHONY: peer
9191
peer: build/bin/peer
92-
peer-docker: build/image/peer/.dummy
92+
peer-docker: build/image/peer/$(DUMMY)
9393

9494
.PHONY: orderer
9595
orderer: build/bin/orderer
96-
orderer-docker: build/image/orderer/.dummy
96+
orderer-docker: build/image/orderer/$(DUMMY)
9797

98-
testenv: build/image/testenv/.dummy
98+
testenv: build/image/testenv/$(DUMMY)
9999

100100
unit-test: peer-docker testenv
101101
cd unit-test && docker-compose up --abort-on-container-exit --force-recreate && docker-compose down
102102

103103
unit-tests: unit-test
104104

105-
docker: $(patsubst %,build/image/%/.dummy, $(IMAGES))
105+
docker: $(patsubst %,build/image/%/$(DUMMY), $(IMAGES))
106106
native: peer orderer
107107

108108
behave-deps: docker peer build/bin/block-listener
@@ -152,12 +152,12 @@ build/docker/busybox:
152152
make -f busybox/Makefile install BINDIR=$(@D)
153153

154154
# Both peer and peer-docker depend on ccenv and javaenv (all docker env images it supports).
155-
build/bin/peer: build/image/ccenv/.dummy build/image/javaenv/.dummy
156-
build/image/peer/.dummy: build/image/ccenv/.dummy build/image/javaenv/.dummy
155+
build/bin/peer: build/image/ccenv/$(DUMMY) build/image/javaenv/$(DUMMY)
156+
build/image/peer/$(DUMMY): build/image/ccenv/$(DUMMY) build/image/javaenv/$(DUMMY)
157157

158158
# Both peer-docker and orderer-docker depend on the runtime image
159-
build/image/peer/.dummy: build/image/runtime/.dummy
160-
build/image/orderer/.dummy: build/image/runtime/.dummy
159+
build/image/peer/$(DUMMY): build/image/runtime/$(DUMMY)
160+
build/image/orderer/$(DUMMY): build/image/runtime/$(DUMMY)
161161

162162
build/bin/%: $(PROJECT_FILES)
163163
@mkdir -p $(@D)
@@ -185,8 +185,8 @@ build/image/%/payload:
185185
mkdir -p $@
186186
cp $^ $@
187187

188-
build/image/%/.dummy: Makefile build/image/%/payload
189-
$(eval TARGET = ${patsubst build/image/%/.dummy,%,${@}})
188+
build/image/%/$(DUMMY): Makefile build/image/%/payload
189+
$(eval TARGET = ${patsubst build/image/%/$(DUMMY),%,${@}})
190190
@echo "Building docker $(TARGET)-image"
191191
@cat images/$(TARGET)/Dockerfile.in \
192192
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \

docker-env.mk

+27
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,32 @@ BASE_DOCKER_TAG=$(ARCH)-$(BASEIMAGE_RELEASE)
5656
DOCKER_GO_LDFLAGS += $(GO_LDFLAGS)
5757
DOCKER_GO_LDFLAGS += -linkmode external -extldflags '-static -lpthread'
5858

59+
#
60+
# What is a .dummy file?
61+
#
62+
# Make is designed to work with files. It uses the presence (or lack thereof)
63+
# and timestamps of files when deciding if a given target needs to be rebuilt.
64+
# Docker containers throw a wrench into the works because the output of docker
65+
# builds do not translate into standard files that makefile rules can evaluate.
66+
# Therefore, we have to fake it. We do this by constructioning our rules such
67+
# as
68+
# my-docker-target/.dummy:
69+
# docker build ...
70+
# touch $@
71+
#
72+
# If the docker-build succeeds, the touch operation creates/updates the .dummy
73+
# file. If it fails, the touch command never runs. This means the .dummy
74+
# file follows relatively 1:1 with the underlying container.
75+
#
76+
# This isn't perfect, however. For instance, someone could delete a docker
77+
# container using docker-rmi outside of the build, and make would be fooled
78+
# into thinking the dependency is statisfied when it really isn't. This is
79+
# our closest approximation we can come up with.
80+
#
81+
# As an aside, also note that we incorporate the version number in the .dummy
82+
# file to differentiate different tags to fix FAB-1145
83+
#
84+
DUMMY = .dummy-$(DOCKER_TAG)
85+
5986

6087

0 commit comments

Comments
 (0)