The binary targets now use buildkit to build/output binaries instead of
doing it in a DOCKER_RUN_DOCKER container. With that change caused
issues when trying to call multiple make targets such as `make binary
cross` since those targets are updating the variables (with conflicting
data) used by the shared `build` prerequisite.
This change has those binary output targets call `docker build` (or
`buildx build`) directly since that is the action they are preforming
and no longer have any pre-reqs.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
| ... | ... |
@@ -19,9 +19,6 @@ DOCKER ?= docker |
| 19 | 19 |
DOCKER_GRAPHDRIVER := $(if $(DOCKER_GRAPHDRIVER),$(DOCKER_GRAPHDRIVER),$(shell docker info 2>&1 | grep "Storage Driver" | sed 's/.*: //')) |
| 20 | 20 |
export DOCKER_GRAPHDRIVER |
| 21 | 21 |
|
| 22 |
-# enable/disable cross-compile |
|
| 23 |
-DOCKER_CROSS ?= false |
|
| 24 |
- |
|
| 25 | 22 |
# get OS/Arch of docker engine |
| 26 | 23 |
DOCKER_OSARCH := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKER_ENGINE_OSARCH}')
|
| 27 | 24 |
DOCKERFILE := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKERFILE}')
|
| ... | ... |
@@ -143,34 +140,45 @@ endif |
| 143 | 143 |
|
| 144 | 144 |
DOCKER_RUN_DOCKER := $(DOCKER_FLAGS) "$(DOCKER_IMAGE)" |
| 145 | 145 |
|
| 146 |
+DOCKER_BUILD_ARGS += --build-arg=GO_VERSION |
|
| 147 |
+BUILD_OPTS := ${BUILD_APT_MIRROR} ${DOCKER_BUILD_ARGS} ${DOCKER_BUILD_OPTS} -f "$(DOCKERFILE)"
|
|
| 148 |
+ifdef USE_BUILDX |
|
| 149 |
+BUILD_OPTS += $(BUILDX_BUILD_EXTRA_OPTS) |
|
| 150 |
+BUILD_CMD := $(BUILDX) build |
|
| 151 |
+else |
|
| 152 |
+BUILD_CMD := $(DOCKER) build |
|
| 153 |
+endif |
|
| 154 |
+ |
|
| 155 |
+# This is used for the legacy "build" target and anything still depending on it |
|
| 156 |
+BUILD_CROSS = |
|
| 157 |
+ifdef DOCKER_CROSS |
|
| 158 |
+BUILD_CROSS = --build-arg CROSS=$(DOCKER_CROSS) |
|
| 159 |
+endif |
|
| 160 |
+ifdef DOCKER_CROSSPLATFORMS |
|
| 161 |
+BUILD_CROSS = --build-arg CROSS=true |
|
| 162 |
+endif |
|
| 163 |
+ |
|
| 146 | 164 |
default: binary |
| 147 | 165 |
|
| 148 | 166 |
all: build ## validate all checks, build linux binaries, run all tests\ncross build non-linux binaries and generate archives |
| 149 | 167 |
$(DOCKER_RUN_DOCKER) bash -c 'hack/validate/default && hack/make.sh' |
| 150 | 168 |
|
| 151 |
-binary: DOCKER_BUILD_ARGS += --output=bundles/ --target=binary |
|
| 152 |
-binary: build ## build the linux binaries |
|
| 169 |
+binary: ## build statically linked linux binaries |
|
| 170 |
+dynbinary: ## build dynamically linked linux binaries |
|
| 171 |
+cross: ## cross build the binaries for darwin, freebsd and\nwindows |
|
| 153 | 172 |
|
| 154 |
-dynbinary: DOCKER_BUILD_ARGS += --output=bundles/ --target=dynbinary |
|
| 155 |
-dynbinary: build ## build the linux dynbinaries |
|
| 173 |
+cross: BUILD_OPTS += --build-arg CROSS=true --build-arg DOCKER_CROSSPLATFORMS |
|
| 156 | 174 |
|
| 157 |
-cross: DOCKER_BUILD_ARGS += --output=bundles/ --target=cross --build-arg DOCKER_CROSSPLATFORMS=$(DOCKER_CROSSPLATFORMS) |
|
| 158 |
-cross: DOCKER_CROSS := true |
|
| 159 |
-cross: build ## cross build the binaries for darwin, freebsd and\nwindows |
|
| 175 |
+binary dynbinary cross: buildx |
|
| 176 |
+ $(BUILD_CMD) $(BUILD_OPTS) --output=bundles/ --target=$@ . |
|
| 160 | 177 |
|
| 161 |
-ifdef DOCKER_CROSSPLATFORMS |
|
| 162 |
-build: DOCKER_CROSS := true |
|
| 163 |
-endif |
|
| 164 |
-build: DOCKER_BUILD_ARGS += --build-arg=CROSS=$(DOCKER_CROSS) |
|
| 165 |
-ifdef GO_VERSION |
|
| 166 |
-build: DOCKER_BUILD_ARGS += --build-arg=GO_VERSION=$(GO_VERSION) |
|
| 167 |
-endif |
|
| 178 |
+build: target = --target=final |
|
| 168 | 179 |
ifdef USE_BUILDX |
| 169 |
-build: bundles buildx |
|
| 170 |
- $(BUILDX) build ${BUILD_APT_MIRROR} ${DOCKER_BUILD_ARGS} ${DOCKER_BUILD_OPTS} -t "$(DOCKER_IMAGE)" -f "$(DOCKERFILE)" $(BUILDX_BUILD_EXTRA_OPTS) .
|
|
| 180 |
+build: bundles buildx |
|
| 181 |
+ $(BUILD_CMD) $(BUILD_OPTS) $(BUILD_CROSS) $(target) -t "$(DOCKER_IMAGE)" . |
|
| 171 | 182 |
else |
| 172 |
-build: bundles |
|
| 173 |
- $(DOCKER) build ${BUILD_APT_MIRROR} ${DOCKER_BUILD_ARGS} ${DOCKER_BUILD_OPTS} -t "$(DOCKER_IMAGE)" -f "$(DOCKERFILE)" .
|
|
| 183 |
+build: bundles ## This is a legacy target and you should probably use something else. |
|
| 184 |
+ $(BUILD_CMD) $(BUILD_OPTS) -t "$(DOCKER_IMAGE)" $(BUILD_CROSS) $(target) . |
|
| 174 | 185 |
endif |
| 175 | 186 |
|
| 176 | 187 |
bundles: |
| ... | ... |
@@ -191,14 +199,20 @@ install: ## install the linux binaries |
| 191 | 191 |
|
| 192 | 192 |
run: build ## run the docker daemon in a container |
| 193 | 193 |
$(DOCKER_RUN_DOCKER) sh -c "KEEPBUNDLE=1 hack/make.sh install-binary run" |
| 194 |
- |
|
| 194 |
+ |
|
| 195 |
+.PHONY: build_shell |
|
| 195 | 196 |
ifeq ($(BIND_DIR), .) |
| 196 |
-shell: DOCKER_BUILD_ARGS += --target=dev |
|
| 197 |
+build_shell: shell_target := --target=dev |
|
| 197 | 198 |
else |
| 198 |
-shell: DOCKER_BUILD_ARGS += --target=final |
|
| 199 |
+build_shell: shell_target := --target=final |
|
| 199 | 200 |
endif |
| 200 |
-shell: BUILDX_BUILD_EXTRA_OPTS += --load |
|
| 201 |
-shell: build ## start a shell inside the build env |
|
| 201 |
+ifdef USE_BUILDX |
|
| 202 |
+build_shell: buildx_load := --load |
|
| 203 |
+endif |
|
| 204 |
+build_shell: buildx |
|
| 205 |
+ $(BUILD_CMD) $(BUILD_OPTS) $(shell_target) $(buildx_load) $(BUILD_CROSS) -t "$(DOCKER_IMAGE)" . |
|
| 206 |
+ |
|
| 207 |
+shell: build_shell ## start a shell inside the build env |
|
| 202 | 208 |
$(DOCKER_RUN_DOCKER) bash |
| 203 | 209 |
|
| 204 | 210 |
test: build test-unit ## run the unit, integration and docker-py tests |
| ... | ... |
@@ -246,6 +260,7 @@ swagger-docs: ## preview the API documentation |
| 246 | 246 |
bfirsh/redoc:1.6.2 |
| 247 | 247 |
|
| 248 | 248 |
.PHONY: buildx |
| 249 |
+ifdef USE_BUILDX |
|
| 249 | 250 |
ifeq ($(BUILDX), bundles/buildx) |
| 250 | 251 |
buildx: bundles/buildx ## build buildx cli tool |
| 251 | 252 |
endif |