forked from sclorg/container-common-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.mk
140 lines (110 loc) · 3.52 KB
/
common.mk
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# SKIP_SQUASH = 0/1
# =================
# If set to '0', images are automatically squashed. '1' disables
# squashing. By default only RHEL containers are squashed.
SHELL := /usr/bin/env bash
ifndef common_dir
common_dir = common
endif
build = $(SHELL) $(common_dir)/build.sh
test = $(SHELL) $(common_dir)/test.sh
testr = $(SHELL) $(common_dir)/test-remote-cluster.sh
tag = $(SHELL) $(common_dir)/tag.sh
clean = $(SHELL) $(common_dir)/clean.sh
DG ?= /bin/dg
generator = DG="$(DG)" $(SHELL) $(common_dir)/generate.sh
# pretty printers
# ---------------
__PROLOG = $(if $(VERBOSE),,@echo " $(1) " $@;)
V_LN = $(call __PROLOG,LN )
V_DG = $(call __PROLOG,DG )
V_DGM = $(call __PROLOG,DGM)
V_CP = $(call __PROLOG,CP )
CDIR = mkdir -p "$$(dirname "$@")" || exit 1 ;
ifeq ($(TARGET),rhel8)
SKIP_SQUASH ?= 1
OS := rhel8
DOCKERFILE ?= Dockerfile.rhel8
else ifeq ($(TARGET),rhel7)
SKIP_SQUASH ?= 0
OS := rhel7
DOCKERFILE ?= Dockerfile.rhel7
else ifeq ($(TARGET),fedora)
OS := fedora
DOCKERFILE ?= Dockerfile.fedora
else ifeq ($(TARGET),centos6)
OS := centos6
DOCKERFILE ?= Dockerfile.centos6
else
OS := centos7
DOCKERFILE ?= Dockerfile
endif
SKIP_SQUASH ?= 1
DOCKER_BUILD_CONTEXT ?= .
script_env = \
SKIP_SQUASH=$(SKIP_SQUASH) \
UPDATE_BASE=$(UPDATE_BASE) \
OS=$(OS) \
CLEAN_AFTER=$(CLEAN_AFTER) \
DOCKER_BUILD_CONTEXT=$(DOCKER_BUILD_CONTEXT) \
OPENSHIFT_NAMESPACES="$(OPENSHIFT_NAMESPACES)" \
CUSTOM_REPO="$(CUSTOM_REPO)"
# TODO: switch to 'build: build-all' once parallel builds are relatively safe
.PHONY: build build-serial build-all
build: build-serial
build-serial:
@$(MAKE) -j1 build-all
build-all: $(VERSIONS)
@for i in $(VERSIONS); do \
test -f $$i/.image-id || continue ; \
echo -n "$(BASE_IMAGE_NAME) $$i => " ; \
cat $$i/.image-id ; \
done
.PHONY: $(VERSIONS)
$(VERSIONS): % : %/root/help.1
VERSION="$@" $(script_env) $(build)
.PHONY: test check
check: test
test: script_env += TEST_MODE=true
# The tests should ideally depend on $IMAGE_ID only, but see PR#19 for more info
# while we need to depend on 'tag' instead of 'build'.
test: tag
VERSIONS="$(VERSIONS)" $(script_env) $(test)
.PHONY: test-with-conu
test-with-conu: script_env += TEST_CONU_MODE=true
test-with-conu: tag
VERSIONS="$(VERSIONS)" $(script_env) $(test)
.PHONY: test-openshift-remote-cluster
test-openshift-remote-cluster:
VERSIONS="$(VERSIONS)" BASE_IMAGE_NAME="$(BASE_IMAGE_NAME)" $(script_env) $(testr)
.PHONY: test-openshift
test-openshift: script_env += TEST_OPENSHIFT_MODE=true
test-openshift: tag
VERSIONS="$(VERSIONS)" BASE_IMAGE_NAME="$(BASE_IMAGE_NAME)" $(script_env) $(test)
.PHONY: tag
tag: build
VERSIONS="$(VERSIONS)" $(script_env) $(tag)
.PHONY: clean clean-hook clean-images clean-versions
clean: clean-images
@$(MAKE) --no-print-directory clean-hook
clean-images:
$(clean) $(VERSIONS)
clean-versions:
rm -rf $(VERSIONS)
%root/help.1: %README.md
mkdir -p $(@D)
go-md2man -in "$^" -out "$@"
chmod a+r "$@"
generate-all: generate
MANIFEST_FILE ?= manifest.sh
auto_targets.mk: $(MANIFEST_FILE)
MANIFEST_FILE="$(MANIFEST_FILE)" \
VERSIONS="$(VERSIONS)" \
$(generator)
# triggers build of auto_targets.mk automatically
-include auto_targets.mk
# We have to remove auto_targets.mk here, otherwise subsequent make calls
# with different VERSIONS=* option keeps the auto_targets.mk unchanged.
.PHONY: generate
generate: $(DISTGEN_TARGETS) $(DISTGEN_MULTI_TARGETS) $(COPY_TARGETS) $(SYMLINK_TARGETS)
rm auto_targets.mk