forked from boxcutter/ubuntu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
287 lines (226 loc) · 10.5 KB
/
Makefile
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# if Makefile.local exists, include it
ifneq ("$(wildcard Makefile.local)", "")
include Makefile.local
endif
PACKER ?= packer
# Possible values for CM: (nocm | chef | chefdk | salt | puppet)
CM ?= nocm
# Possible values for CM_VERSION: (latest | x.y.z | x.y)
CM_VERSION ?=
ifndef CM_VERSION
ifneq ($(CM),nocm)
CM_VERSION = latest
endif
endif
BOX_VERSION ?= $(shell cat VERSION)
ifeq ($(CM),nocm)
BOX_SUFFIX := -$(CM)-$(BOX_VERSION).box
else
BOX_SUFFIX := -$(CM)$(CM_VERSION)-$(BOX_VERSION).box
endif
# Packer does not allow empty variables, so only pass variables that are defined
PACKER_VARS_LIST = 'cm=$(CM)' 'version=$(BOX_VERSION)'
ifdef CM_VERSION
PACKER_VARS_LIST += 'cm_version=$(CM_VERSION)'
endif
ifdef CUSTOM_SCRIPT
PACKER_VARS_LIST += 'custom_script=$(CUSTOM_SCRIPT)'
endif
ifdef HEADLESS
PACKER_VARS_LIST += 'headless=$(HEADLESS)'
endif
ifdef INSTALL_VAGRANT_KEY
PACKER_VARS_LIST += 'install_vagrant_key=$(INSTALL_VAGRANT_KEY)'
endif
ifdef ISO_PATH
PACKER_VARS_LIST += 'iso_path=$(ISO_PATH)'
endif
ifdef SSH_FULLNAME
PACKER_VARS_LIST += 'ssh_fullname=${SSH_FULLNAME}'
endif
ifdef SSH_PASSWORD
PACKER_VARS_LIST += 'ssh_password=$(SSH_PASSWORD)'
endif
ifdef SSH_USERNAME
PACKER_VARS_LIST += 'ssh_username=$(SSH_USERNAME)'
endif
ifdef UPDATE
PACKER_VARS_LIST += 'update=$(UPDATE)'
endif
PACKER_VARS := $(addprefix -var , $(PACKER_VARS_LIST))
ifdef PACKER_DEBUG
PACKER_CMD := PACKER_LOG=1 $(PACKER) --debug
else
PACKER_CMD := $(PACKER)
endif
BUILDER_TYPES ?= vmware virtualbox parallels
TEMPLATE_FILENAMES := $(wildcard *.json)
BOX_FILENAMES := $(TEMPLATE_FILENAMES:.json=$(BOX_SUFFIX))
VMWARE_BOX_DIR ?= box/vmware
VIRTUALBOX_BOX_DIR ?= box/virtualbox
PARALLELS_BOX_DIR ?= box/parallels
VMWARE_TEMPLATE_FILENAMES = $(filter-out ubuntu1504-desktop.json ubuntu1510-i386.json ubuntu1510.json,$(TEMPLATE_FILENAMES))
VMWARE_BOX_FILENAMES := $(VMWARE_TEMPLATE_FILENAMES:.json=$(BOX_SUFFIX))
VMWARE_BOX_FILES := $(foreach box_filename, $(VMWARE_BOX_FILENAMES), $(VMWARE_BOX_DIR)/$(box_filename))
VIRTUALBOX_TEMPLATE_FILENAMES = $(filter-out ubuntu1510-i386.json ubuntu1510.json,$(TEMPLATE_FILENAMES))
VIRTUALBOX_BOX_FILENAMES := $(VIRTUALBOX_TEMPLATE_FILENAMES:.json=$(BOX_SUFFIX))
VIRTUALBOX_BOX_FILES := $(foreach box_filename, $(VIRTUALBOX_BOX_FILENAMES), $(VIRTUALBOX_BOX_DIR)/$(box_filename))
PARALLELS_TEMPLATE_FILENAMES = $(filter-out ubuntu1504-desktop ubuntu1510-i386.json ubuntu1510.json ,$(TEMPLATE_FILENAMES))
PARALLELS_BOX_FILENAMES := $(PARALLELS_TEMPLATE_FILENAMES:.json=$(BOX_SUFFIX))
PARALLELS_BOX_FILES := $(foreach box_filename, $(PARALLELS_BOX_FILENAMES), $(PARALLELS_BOX_DIR)/$(box_filename))
BOX_FILES := $(VMWARE_BOX_FILES) $(VIRTUALBOX_BOX_FILES) $(PARALLELS_BOX_FILES)
VMWARE_OUTPUT ?= output-vmware-iso
VIRTUALBOX_OUTPUT ?= output-virtualbox-iso
PARALLELS_OUTPUT ?= output-parallels-iso
VMWARE_BUILDER := vmware-iso
VIRTUALBOX_BUILDER := virtualbox-iso
PARALLELS_BUILDER := parallels-iso
CURRENT_DIR = $(shell pwd)
SOURCES := $(wildcard script/*.sh) $(wildcard floppy/*.*) $(wildcard http/*.cfg)
.PHONY: \
all \
clean-builders \
clean-output \
clean-packer-cache \
clean \
list \
s3cp-parallels \
s3cp-virtualbox \
s3cp-vmware \
test \
validate
all: $(BOX_FILES)
###############################################################################
# Target shortcuts
define SHORTCUT
vmware/$(1): $(VMWARE_BOX_DIR)/$(1)$(BOX_SUFFIX)
test-vmware/$(1): test-$(VMWARE_BOX_DIR)/$(1)$(BOX_SUFFIX)
ssh-vmware/$(1): ssh-$(VMWARE_BOX_DIR)/$(1)$(BOX_SUFFIX)
virtualbox/$(1): $(VIRTUALBOX_BOX_DIR)/$(1)$(BOX_SUFFIX)
test-virtualbox/$(1): test-$(VIRTUALBOX_BOX_DIR)/$(1)$(BOX_SUFFIX)
ssh-virtualbox/$(1): ssh-$(VIRTUALBOX_BOX_DIR)/$(1)$(BOX_SUFFIX)
parallels/$(1): $(PARALLELS_BOX_DIR)/$(1)$(BOX_SUFFIX)
test-parallels/$(1): test-$(PARALLELS_BOX_DIR)/$(1)$(BOX_SUFFIX)
ssh-parallels/$(1): ssh-$(PARALLELS_BOX_DIR)/$(1)$(BOX_SUFFIX)
$(1): vmware/$(1) virtualbox/$(1) parallels/$(1)
test-$(1): test-vmware/$(1) test-virtualbox/$(1) test-parallels/$(1)
s3cp-$(1): s3cp-$(VMWARE_BOX_DIR)/$(1)$(BOX_SUFFIX) s3cp-$(VIRTUALBOX_BOX_DIR)/$(1)$(BOX_SUFFIX) s3cp-$(PARALLELS_BOX_DIR)/$(1)$(BOX_SUFFIX)
s3cp-vmware/$(1): s3cp-$(VMWARE_BOX_DIR)/$(1)$(BOX_SUFFIX)
s3cp-virtualbox/$(1): s3cp-$(VIRTUALBOX_BOX_DIR)/$(1)$(BOX_SUFFIX)
s3cp-parallels/$(1): s3cp-$(PARALLELS_BOX_DIR)/$(1)$(BOX_SUFFIX)
test-atlas-$(1): test-atlas-$(VMWARE_BOX_DIR)/$(1)$(BOX_SUFFIX) test-atlas-$(VIRTUALBOX_BOX_DIR)/$(1)$(BOX_SUFFIX) test-atlas-$(PARALLELS_BOX_DIR)/$(1)$(BOX_SUFFIX)
test-atlas-vmware/$(1): test-atlas-$(VMWARE_BOX_DIR)/$(1)$(BOX_SUFFIX)
test-atlas-virtualbox/$(1): test-atlas-$(VIRTUALBOX_BOX_DIR)/$(1)$(BOX_SUFFIX)
test-atlas-parallels/$(1): test-atlas-$(PARALLELS_BOX_DIR)/$(1)$(BOX_SUFFIX)
s3cp-$(1): s3cp-$(VMWARE_BOX_DIR)/$(1)$(BOX_SUFFIX) s3cp-$(VIRTUALBOX_BOX_DIR)/$(1)$(BOX_SUFFIX) s3cp-$(PARALLELS_BOX_DIR)/$(1)$(BOX_SUFFIX)
register-atlas-$(1): register-atlas/$(1)$(BOX_SUFFIX)
endef
SHORTCUT_TARGETS := $(basename $(TEMPLATE_FILENAMES))
$(foreach i,$(SHORTCUT_TARGETS),$(eval $(call SHORTCUT,$(i))))
###############################################################################
$(VMWARE_BOX_DIR)/%$(BOX_SUFFIX): %.json $(SOURCES)
rm -rf $(VMWARE_OUTPUT)
mkdir -p $(VMWARE_BOX_DIR)
$(PACKER_CMD) build -only=$(VMWARE_BUILDER) $(PACKER_VARS) $<
$(VIRTUALBOX_BOX_DIR)/%$(BOX_SUFFIX): %.json $(SOURCES)
rm -rf $(VIRTUALBOX_OUTPUT)
mkdir -p $(VIRTUALBOX_BOX_DIR)
$(PACKER_CMD) build -only=$(VIRTUALBOX_BUILDER) $(PACKER_VARS) $<
$(PARALLELS_BOX_DIR)/%$(BOX_SUFFIX): %.json $(SOURCES)
rm -rf $(PARALLELS_OUTPUT)
mkdir -p $(PARALLELS_BOX_DIR)
$(PACKER_CMD) build -only=$(PARALLELS_BUILDER) $(PACKER_VARS) $<
list:
@echo "Prepend 'vmware/' to build only vmware target:"
@echo " make vmware/ubuntu1404"
@echo "Prepend 'virtualbox/' to build only virtualbox target:"
@echo " make virtualbox/ubuntu1404"
@echo "Prepend 'parallels/' to build only parallels target:"
@echo " make parallels/ubuntu1404"
@echo ""
@echo "Targets:"
@for shortcut_target in $(SHORTCUT_TARGETS) ; do \
echo $$shortcut_target ; \
done | sort
validate:
@for template_filename in $(TEMPLATE_FILENAMES) ; do \
echo Checking $$template_filename ; \
$(PACKER) validate $$template_filename ; \
done
clean: clean-builders clean-output clean-packer-cache
clean-builders:
@for builder in $(BUILDER_TYPES) ; do \
if test -d box/$$builder ; then \
echo Deleting box/$$builder/*.box ; \
find box/$$builder -maxdepth 1 -type f -name "*.box" ! -name .gitignore -exec rm '{}' \; ; \
fi ; \
done
clean-output:
@for builder in $(BUILDER_TYPES) ; do \
echo Deleting output-$$builder-iso ; \
echo rm -rf output-$$builder-iso ; \
done
clean-packer-cache:
echo Deleting packer_cache
rm -rf packer_cache
test-$(VMWARE_BOX_DIR)/%$(BOX_SUFFIX): $(VMWARE_BOX_DIR)/%$(BOX_SUFFIX)
rm -f ~/.ssh/known_hosts
bin/test-box.sh $< vmware_desktop vmware_fusion $(CURRENT_DIR)/test/*_spec.rb
test-$(VIRTUALBOX_BOX_DIR)/%$(BOX_SUFFIX): $(VIRTUALBOX_BOX_DIR)/%$(BOX_SUFFIX)
rm -f ~/.ssh/known_hosts
bin/test-box.sh $< virtualbox virtualbox $(CURRENT_DIR)/test/*_spec.rb
test-$(PARALLELS_BOX_DIR)/%$(BOX_SUFFIX): $(PARALLELS_BOX_DIR)/%$(BOX_SUFFIX)
rm -f ~/.ssh/known_hosts
bin/test-box.sh $< parallels parallels $(CURRENT_DIR)/test/*_spec.rb
test: test-vmware test-virtualbox test-parallels
test-vmware: $(addprefix test-,$(VMWARE_BOX_FILES))
test-virtualbox: $(addprefix test-,$(VIRTUALBOX_BOX_FILES))
test-parallels: $(addprefix test-,$(PARALLELS_BOX_FILES))
ssh-$(VMWARE_BOX_DIR)/%$(BOX_SUFFIX): $(VMWARE_BOX_DIR)/%$(BOX_SUFFIX)
rm -f ~/.ssh/known_hosts
bin/ssh-box.sh $< vmware_desktop vmware_fusion $(CURRENT_DIR)/test/*_spec.rb
ssh-$(VIRTUALBOX_BOX_DIR)/%$(BOX_SUFFIX): $(VIRTUALBOX_BOX_DIR)/%$(BOX_SUFFIX)
rm -f ~/.ssh/known_hosts
bin/ssh-box.sh $< virtualbox virtualbox $(CURRENT_DIR)/test/*_spec.rb
ssh-$(PARALLELS_BOX_DIR)/%$(BOX_SUFFIX): $(PARALLELS_BOX_DIR)/%$(BOX_SUFFIX)
rm -f ~/.ssh/known_hosts
bin/ssh-box.sh $< parallels parallels $(CURRENT_DIR)/test/*_spec.rb
S3_STORAGE_CLASS ?= REDUCED_REDUNDANCY
S3_ALLUSERS_ID ?= uri=http://acs.amazonaws.com/groups/global/AllUsers
s3cp-$(VMWARE_BOX_DIR)/%$(BOX_SUFFIX): $(VMWARE_BOX_DIR)/%$(BOX_SUFFIX)
@for i in {1..20}; do \
aws --profile $(AWS_PROFILE) s3 cp $< $(VMWARE_S3_BUCKET) --storage-class $(S3_STORAGE_CLASS) --grants full=$(S3_GRANT_ID) read=$(S3_ALLUSERS_ID) && break || sleep 62; \
done
s3cp-$(VIRTUALBOX_BOX_DIR)/%$(BOX_SUFFIX): $(VIRTUALBOX_BOX_DIR)/%$(BOX_SUFFIX)
@for i in {1..20}; do \
aws --profile $(AWS_PROFILE) s3 cp $< $(VIRTUALBOX_S3_BUCKET) --storage-class $(S3_STORAGE_CLASS) --grants full=$(S3_GRANT_ID) read=$(S3_ALLUSERS_ID) && break || sleep 62; \
done
s3cp-$(PARALLELS_BOX_DIR)/%$(BOX_SUFFIX): $(PARALLELS_BOX_DIR)/%$(BOX_SUFFIX)
@for i in {1..20}; do \
aws --profile $(AWS_PROFILE) s3 cp $< $(PARALLELS_S3_BUCKET) --storage-class $(S3_STORAGE_CLASS) --grants full=$(S3_GRANT_ID) read=$(S3_ALLUSERS_ID) && break || sleep 62; \
done
s3cp-vmware: $(addprefix s3cp-,$(VMWARE_BOX_FILES))
s3cp-virtualbox: $(addprefix s3cp-,$(VIRTUALBOX_BOX_FILES))
s3cp-parallels: $(addprefix s3cp-,$(PARALLELS_BOX_FILES))
ATLAS_NAME ?= boxcutter
test-atlas: test-atlas-vmware test-atlas-virtualbox test-atlas-parallels
test-atlas-vmware: $(addprefix test-atlas-,$(VMWARE_BOX_FILES))
test-atlas-virtualbox: $(addprefix test-atlas-,$(VIRTUALBOX_BOX_FILES))
test-atlas-parallels: $(addprefix test-atlas-,$(PARALLELS_BOX_FILES))
test-atlas-$(VMWARE_BOX_DIR)%$(BOX_SUFFIX):
bin/test-vagrantcloud-box.sh boxcutter$* vmware_fusion vmware_desktop $(CURRENT_DIR)/test/*_spec.rb
bin/test-vagrantcloud-box.sh box-cutter$* vmware_fusion vmware_desktop $(CURRENT_DIR)/test/*_spec.rb
test-atlas-$(VIRTUALBOX_BOX_DIR)%$(BOX_SUFFIX):
bin/test-vagrantcloud-box.sh boxcutter$* virtualbox virtualbox $(CURRENT_DIR)/test/*_spec.rb
bin/test-vagrantcloud-box.sh box-cutter$* virtualbox virtualbox $(CURRENT_DIR)/test/*_spec.rb
test-atlas-$(PARALLELS_BOX_DIR)%$(BOX_SUFFIX):
bin/test-vagrantcloud-box.sh boxcutter$* parallels parallels $(CURRENT_DIR)/test/*_spec.rb
bin/test-vagrantcloud-box.sh box-cutter$* parallels parallels $(CURRENT_DIR)/test/*_spec.rb
test-atlas: test-atlas-vmware test-atlas-virtualbox test-atlas-parallels
test-atlas-vmware: $(addprefix test-atlas-,$(VMWARE_BOX_FILES))
test-atlas-virtualbox: $(addprefix test-atlas-,$(VIRTUALBOX_BOX_FILES))
test-atlas-parallels: $(addprefix test-atlas-,$(PARALLELS_BOX_FILES))
register-atlas: $(addprefix register-atlas-,$(basename $(TEMPLATE_FILENAMES)))
register-atlas/%$(BOX_SUFFIX):
bin/register_atlas.sh $* $(BOX_SUFFIX) $(BOX_VERSION)
bin/register_atlas_box_cutter.sh $* $(BOX_SUFFIX) $(BOX_VERSION)