diff options
author | Manuel Messner | 2018-02-12 13:22:32 +0100 |
---|---|---|
committer | Manuel Messner | 2018-02-12 13:25:32 +0100 |
commit | c90be4f94df244d508bbc98757a53877346df556 (patch) | |
tree | c7af8e31f01aae975d34108bbde599ac59c5abb8 /Makefile | |
parent | Makefile: rename vm_name (diff) | |
download | packer-templates-c90be4f94df244d508bbc98757a53877346df556.tar.gz packer-templates-c90be4f94df244d508bbc98757a53877346df556.tar.xz packer-templates-c90be4f94df244d508bbc98757a53877346df556.zip |
Makefile: support parallel builds
* now builds provisioned images in a timestamped subdirectory, copying
the ansible-roles it was built with
* simplified the post-processing of images builts using better paths :)
Signed-off-by: Jonathan Bauer <jonathan.bauer@rz.uni-freiburg.de>
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 43 |
1 files changed, 16 insertions, 27 deletions
@@ -41,8 +41,11 @@ ifdef DEBUG PACKER_OPTS += -var='headless=false' endif +TIMESTAMP := $(shell date "+%Y-%m-%d_%H-%M-%S") + check_rootpw = $(if $(strip $(ROOTPW)),,$(error No root password is set, set it as ROOTPW in your environment.)) + .PHONY: all help clean all: help @@ -55,13 +58,8 @@ $(BASETARGETS): $(PACKER) build -only=$(BUILDER) \ $(PACKER_OPTS) \ -var='vm_name=rootfs-image' \ + -var='output_directory=$(@D)/base' \ $(@D).json - @test -f output-$(@D)-$(BUILDER)/$(@D) || false - @-test -d $(@D)/base && rm -rf $(@D)/base - @-mkdir $(@D) - @mv output-$(@D)-$(BUILDER) $(@D)/base - @mv $(@D)/base/$(@D) $(@D)/base/image - @echo "** Success **" ## # Provisioning images @@ -70,20 +68,17 @@ $(BASETARGETS): $(PROVTARGETS): $(foreach flav, $(FLAVORS), %/$(flav)): %/base $(call check_rootpw) + $(eval BUILD_DIR := $(@D)/$(@F).$(TIMESTAMP)) $(info ** Provisioning '$(@D)' with '$(@F)' **) + @mkdir -p $(BUILD_DIR) + @cp -r $(ANSIBLE_DIR) $(BUILD_DIR)/$(ANSIBLE_DIR) $(PACKER) build -only=$(BUILDER) \ $(PACKER_OPTS) \ - -var='image_dir=$(@D)' \ - -var='image_name=base/image' \ -var='vm_name=rootfs-image' \ + -var='output_directory=$(BUILD_DIR)/build' \ + -var='base_image=$(@D)/base/rootfs-image' \ -var='playbook=setup-$(@F).yml' \ - $(ANSIBLE_DIR)/run-playbook-only.json - @test -f output-$(@D)/$(@F) || false - @-test -d $(@D)/$(@F) && rm -rf $(@D)/$(@F) - @-mkdir $(@D)/$(@F) - @mv output-$(@D)/$(@F) $(@D)/$(@F)/image - @rmdir output-$(@D) - @echo "** Success **" + $(BUILD_DIR)/$(ANSIBLE_DIR)/run-playbook-only.json ## # Generating boot files @@ -92,22 +87,16 @@ $(foreach flav, $(FLAVORS), %/$(flav)): %/base $(BOOTTARGETS): %/boot: % $(call check_rootpw) - $(info ** Generating boot files for '$(patsubst %/,%,$(dir $(@D))):$(notdir $(@D))' **) + $(eval BUILD_DIR := $(@D).$(TIMESTAMP)) + $(info ** Generating boot files for '$(BUILD_DIR)') $(PACKER) build -only=$(BUILDER) \ $(PACKER_OPTS) \ - -var='image_dir=$(patsubst %/,%,$(dir $(@D)))/$(notdir $(@D))' \ - -var='image_name=image' \ -var='vm_name=rootfs-image.tmp' \ + -var='output_directory=$(BUILD_DIR)/build/tmp' \ + -var='base_image=$(BUILD_DIR)/build/rootfs-image' \ -var='playbook=build-dracut-initramfs.yml' \ - $(ANSIBLE_DIR)/run-playbook-only.json - @test -f $(ANSIBLE_DIR)/boot_files/initramfs || false - @-test -d $(patsubst %/,%,$(dir $(@D)))/$(notdir $(@D))/boot && \ - rm -rf $(patsubst %/,%,$(dir $(@D)))/$(notdir $(@D))/boot - @mv $(ANSIBLE_DIR)/boot_files $(patsubst %/,%,$(dir $(@D)))/$(notdir $(@D))/boot - ifndef DEBUG - @rm -rf output-$(patsubst %/,%,$(dir $(@D)))/ - endif - @echo "** Success **" + $(BUILD_DIR)/$(ANSIBLE_DIR)/run-playbook-only.json + @mv $(BUILD_DIR)/$(ANSIBLE_DIR)/boot_files $(BUILD_DIR)/build/boot help: @printf "Usage:\n\tmake <template>/<flavor>[/boot]\n" |