forked from submariner-io/shipyard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.images
90 lines (72 loc) · 3.52 KB
/
Makefile.images
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Shared target to build images.
# To build an image, simply add a dependency on the target `package/.image.<abc>`
# where <abc> corresponds to an existing `package/Dockerfile.<abc>` file.
# The resulting image name will be `<abc>`.
SHELL := /bin/bash
REPO ?= quay.io/submariner
### Tunable variables for affecting make commands ###
# Affecting multiple commands
export REPO ?= quay.io/submariner
# Specific to `build_images.sh`
export USE_CACHE ?= true
# Specific to `images`
export OCIFILE PLATFORM
# Specific to `preload-images`
export PRELOAD_IMAGES
# Automatically preload any images that the project builds, on top of any (if there were) requested by the caller
ifdef IMAGES
override PRELOAD_IMAGES += $(IMAGES)
endif
# Specific to `release-images`
export TAG ?= $(CUTTING_EDGE)
# Force rebuild an image if it's not in docker
force_image_rebuild = $(if $(shell docker image history $(REPO)/$(1):$(BASE_BRANCH)),,FORCE_IMAGE)
# Force rebuild dynamically by calling this target
FORCE_IMAGE: ;
# Dockerfile dependencies are the file and any file copied into it
# We have to run it through a variable in order to expand any * that might be
# in the COPY command; find is used to handle directories as dependencies
# Files copied from another image are ignored
docker_deps = $(shell files=($(1) $$(awk '/COPY/ && substr($$2, 1, 7) != "--from=" && $$2 != "." { $$1 = $$NF = ""; print }' $(1))) && find $${files[*]} -type f -o -type l)
# Patterned recipe to use to build any image from any Dockerfile
# An empty file is used for make to figure out if dependencies changed or not
.SECONDEXPANSION:
package/.image.%: $$(call docker_deps,package/Dockerfile.$$*) $$(call force_image_rebuild,$$*)
$(SCRIPTS_DIR)/build_image.sh $* $< $@
# Build an OCI tarball from a Dockerfile
.SECONDEXPANSION:
package/%.tar: $$(call docker_deps,package/Dockerfile.$$*) $$(call force_image_rebuid,$$*)
OCIFILE="$@" $(SCRIPTS_DIR)/build_image.sh $* $< package/.image.$*
# [images] builds all the container images for the project
# Default target to build images based on IMAGES variable
# All these images are built for the default architecture; this enables
# local consumption e.g. for deploy and e2e. Targets needing usable images
# during a build must depend on this target.
images: $(foreach image,$(IMAGES),package/.image.$(image))
# [multiarch-images] builds all multi-arch container images
# Default target to build images based on the MULTIARCH_IMAGES variable
# Default platforms based on the PLATFORMS variable
# These images are not built in a locally-consumable form (OCI tarballs only)
# and are only intended for publication.
multiarch-images: export PLATFORM=$(PLATFORMS)
multiarch-images: $(foreach image,$(MULTIARCH_IMAGES),package/$(image).tar)
# [release-images] uploads the project's images to a public repository
release-images:
ifneq (,$(filter-out $(MULTIARCH_IMAGES),$(IMAGES)))
$(SCRIPTS_DIR)/release_images.sh $(filter-out $(MULTIARCH_IMAGES),$(IMAGES))
endif
ifneq (,$(MULTIARCH_IMAGES))
OCIDIR='package/' $(SCRIPTS_DIR)/release_images.sh $(MULTIARCH_IMAGES)
endif
# [preload-images] into the local registry for testing, based on PRELOAD_IMAGES variable
preload-images: images
set -e;\
. $(SCRIPTS_DIR)/lib/deploy_funcs;\
. $(SCRIPTS_DIR)/lib/debug_functions;\
for image in $(PRELOAD_IMAGES); do\
import_image $(REPO)/$${image};\
done
# [reload-images] rebuilds and reloads the images, optionally restarting with `restart` variable
reload-images: preload-images
$(SCRIPTS_DIR)/reload_images.sh
.PHONY: images multiarch-images preload-images release-images reload-images