@@ -56,7 +56,7 @@ DOCKER_GET_REVISION_SCRIPT?=$(JML_BUILD)/get_git_revision.sh
56
56
57
57
# DOCKER_PUSH: if this is defined, then docker will be asked to push the
58
58
# container to the repository after it has been successfully built.
59
- #
59
+ # N.B. the tag "latest" will be applied to the image before pushing
60
60
# This should be added to local.mk, not edited here.
61
61
62
62
# DOCKER_PUSH:=1
@@ -70,6 +70,8 @@ DOCKER_GET_REVISION_SCRIPT?=$(JML_BUILD)/get_git_revision.sh
70
70
# DOCKER_TAG: if this is defined, the given tag will also be applied to the
71
71
# built image. By default it's "latest" which is expected by most docker
72
72
# tooling, but can be changed to something else or undefined if required.
73
+ DOCKER_TAG: = $(shell whoami) _latest
74
+ DOCKER_TAGS += $(DOCKER_TAG )
73
75
74
76
# DOCKER_COMMIT_ARGS: Anything in this variable (which should be overridden
75
77
# on a per-target basis) will be passed to docker commit as arguments.
@@ -79,13 +81,10 @@ DOCKER_GET_REVISION_SCRIPT?=$(JML_BUILD)/get_git_revision.sh
79
81
# container after the container is created. It can be used to modify the
80
82
# container before it is committed.
81
83
82
- DOCKER_TAG: =latest
83
-
84
-
85
84
86
85
# Docker target (generic). If you make docker_target_name, it will make
87
86
# target_name and install it inside a docker image.
88
- #
87
+ #
89
88
# In order to determine the tag, by default this rule will call the
90
89
# get_git_revision script that will return a revision ID from git to tag
91
90
# the image with. The script will also ensure that everything used in the
@@ -94,18 +93,67 @@ DOCKER_TAG:=latest
94
93
95
94
# docker_%: $(TMPBIN)/%.iid
96
95
97
- docker_% : % $(DOCKER_GLOBAL_DEPS ) $(DOCKER_TARGET_DEPS )
98
- @BUILD=$(BUILD ) bash $(DOCKER_GET_REVISION_SCRIPT ) $(< ) > $(TMPBIN ) /$(< ) .rid $(if $(DOCKER_ALLOW_DIRTY ) , || true,)
99
- echo " revision" ` cat $( TMPBIN) /$( < ) .rid`
100
- @echo " Building $( < ) for use within docker"
101
- +make TMPBIN=$(TMPBIN ) LIB=$(TMPBIN ) /docker-$(< ) /lib BIN=$(TMPBIN ) /docker-$(< ) /bin ETC=$(TMPBIN ) /docker-$(< ) /etc $(< )
96
+ altroot_prep_% : % $(DOCKER_GLOBAL_DEPS ) $(DOCKER_TARGET_DEPS )
97
+ @BUILD=$(BUILD ) bash $(DOCKER_GET_REVISION_SCRIPT ) $(* ) > $(TMPBIN ) /$(* ) .rid $(if $(DOCKER_ALLOW_DIRTY ) , || true,)
98
+ echo " revision" ` cat $( TMPBIN) /$( * ) .rid`
99
+ @echo " Building $( * ) for use within docker"
100
+ make TMPBIN=$(TMPBIN ) LIB=$(TMPBIN ) /docker-$(* ) /opt/lib BIN=$(TMPBIN ) /docker-$(* ) /opt/bin ALTROOT=$(TMPBIN ) /docker-$(* ) $(* )
101
+
102
+ docker_% : altroot_prep_% $(DOCKER_GLOBAL_DEPS ) $(DOCKER_TARGET_DEPS )
102
103
@echo " Creating container"
103
- @rm -f $(TMPBIN ) /$(< ) .cid
104
- docker run -cidfile $(TMPBIN ) /$(< ) .cid -v ` pwd` :/tmp/build $(DOCKER_BASE_IMAGE ) sh /tmp/build/$(JML_BUILD ) /docker_install_inside_container.sh /tmp/build/$(TMPBIN ) /docker-$(< ) $(if $(DOCKER_POST_INSTALL_SCRIPT ) ,/tmp/build/$(DOCKER_POST_INSTALL_SCRIPT ) )
105
- cat $(TMPBIN ) /$(< ) .cid
106
- echo docker commit ` cat $( TMPBIN) /$( < ) .cid` $(DOCKER_REGISTRY )$(DOCKER_USER )$(< ) :` cat $( TMPBIN) /$( < ) .rid`
107
- docker commit $(DOCKER_COMMIT_ARGS ) ` cat $( TMPBIN) /$( < ) .cid` $(DOCKER_REGISTRY )$(DOCKER_USER )$(< ) :` cat $( TMPBIN) /$( < ) .rid` > $(TMPBIN ) /$< .iid && cat $(TMPBIN ) /$< .iid
108
- $(if $(DOCKER_TAG ) ,docker tag `cat $(TMPBIN ) /$(< ) .iid` $(DOCKER_REGISTRY )$(DOCKER_USER )$(< ) :$(DOCKER_TAG ) )
109
- @docker rm ` cat $( TMPBIN) /$( < ) .cid`
110
- $(if $(DOCKER_PUSH ) ,docker push $(DOCKER_REGISTRY )$(DOCKER_USER )$(< ) )
111
- @echo $(COLOR_WHITE ) Created $(if $(DOCKER_PUSH ) ,and pushed )$(COLOR_BOLD )$(DOCKER_REGISTRY )$(DOCKER_USER )$(< ) :` cat $( TMPBIN) /$( < ) .rid` $(COLOR_RESET ) as image $(COLOR_WHITE )$(COLOR_BOLD ) ` cat $( TMPBIN) /$< .iid` $(COLOR_RESET )
104
+ @rm -f $(TMPBIN ) /$(* ) .cid
105
+ docker run --cidfile $(TMPBIN ) /$(* ) .cid -v ` pwd` :/tmp/build $(DOCKER_BASE_IMAGE ) sh /tmp/build/$(JML_BUILD ) /docker_install_inside_container.sh /tmp/build/$(TMPBIN ) /docker-$(* ) $(if $(DOCKER_POST_INSTALL_SCRIPT ) ,/tmp/build/$(DOCKER_POST_INSTALL_SCRIPT ) )
106
+ cat $(TMPBIN ) /$(* ) .cid
107
+ echo docker commit ` cat $( TMPBIN) /$( * ) .cid` $(DOCKER_REGISTRY )$(DOCKER_USER )$(* ) :` cat $( TMPBIN) /$( * ) .rid`
108
+ docker commit $(DOCKER_COMMIT_ARGS ) ` cat $( TMPBIN) /$( * ) .cid` $(DOCKER_REGISTRY )$(DOCKER_USER )$(* ) :` cat $( TMPBIN) /$( * ) .rid` > $(TMPBIN ) /$(* ) .iid && cat $(TMPBIN ) /$(* ) .iid
109
+ $(foreach tag,$(DOCKER_TAGS ) ,docker tag -f `cat $(TMPBIN ) /$(* ) .iid` $(DOCKER_REGISTRY )$(DOCKER_USER )$(* ) :$(tag ) ;)
110
+ $(if $(DOCKER_PUSH ) ,docker tag -f `cat $(TMPBIN ) /$(* ) .iid` $(DOCKER_REGISTRY )$(DOCKER_USER )$(* ) :latest)
111
+ @docker rm ` cat $( TMPBIN) /$( * ) .cid`
112
+ # $(if $(DOCKER_PUSH),$(if $(DOCKER_TAG), docker push $(DOCKER_REGISTRY)$(DOCKER_USER)$(*):$(DOCKER_TAG)))
113
+ $(if $(DOCKER_PUSH ) ,docker push $(DOCKER_REGISTRY )$(DOCKER_USER )$(* ) :latest)
114
+ @echo $(COLOR_WHITE ) Created $(if $(DOCKER_PUSH ) ,and pushed )$(COLOR_BOLD )$(DOCKER_REGISTRY )$(DOCKER_USER )$(* ) :` cat $( TMPBIN) /$( * ) .rid` $(COLOR_RESET ) as image $(COLOR_WHITE )$(COLOR_BOLD ) ` cat $( TMPBIN) /$( * ) .iid` $(COLOR_RESET )
115
+
116
+
117
+ # # Functions
118
+ # install_templated_file
119
+ # 1: source file
120
+ # 2: destination file
121
+ # 3: mode (444)
122
+ # 4: make target to add the rule as a prerequisite
123
+ # 5: variable definition file
124
+ # 6: template filter # must take a file as sole parameter and output
125
+ # the result on stdout
126
+ define install_templated_file
127
+ $$(if $(trace ) ,$$(warning called "$(0 ) " "$(1 ) " "$(2 ) " "$(3 ) " "$(4 ) " "$(5 ) " "$(6 ) ) )
128
+ $(eval mode := $(if $(3 ) ,-m $(3 ) ,-m 0444) )
129
+ $(eval target_add_prereq := $(4 ) )
130
+ $(eval var_file := $(if $(5 ) ,$(5 ) ) )
131
+ $(eval new_target := $(0 ) -$(1 ) -$(2 ) )
132
+
133
+ $(new_target ) : $(1 ) $(var_file )
134
+ install -d `dirname $(2 ) `
135
+ $(6 ) $(1 ) >$(2 ) ~
136
+ install $(mode ) $(2 ) ~ $(2 )
137
+ rm $(2 ) ~
138
+
139
+ $(target_add_prereq ) : $(new_target )
140
+ .PHONY: $(new_target )
141
+ endef
142
+
143
+ # install_directory
144
+ # $(1): source dir
145
+ # $(2): destination dir
146
+ # $(3): make target to add the rule as a prerequisite
147
+ define install_directory
148
+ $$(if $(trace ) ,$$(warning called "$(0 ) " "$(1 ) " "$(2 ) " "$(3 ) ") )
149
+ $(eval target_add_prereq := $(3 ) )
150
+ $(eval new_target := $(0 ) -$(1 ) -$(2 ) )
151
+
152
+ $(new_target ) :
153
+ mkdir -p $(2 )
154
+ cp -vR $(1 ) $(2 )
155
+
156
+ $(target_add_prereq ) : $(new_target )
157
+ .PHONY: $(new_target )
158
+ endef
159
+
0 commit comments