summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile24
1 files changed, 23 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 0906aa6..7486bc9 100644
--- a/Makefile
+++ b/Makefile
@@ -58,6 +58,9 @@ COMPRESSTARGETS := $(foreach possible, $(COMPRESSPOSSIBLE), $(possible)/compress
BOOTTARGETS := $(foreach template, $(TEMPLATES), $(template)/base/boot)
BOOTTARGETS += $(foreach prov, $(PROVTARGETS), $(prov)/boot)
CURBOOTTARGETS := $(foreach prov, $(REPROVTARGETS), $(prov)/boot)
+BASERMTARGETS := $(foreach target, $(BASETARGETS), rm/$(target))
+PROVRMTARGETS := $(foreach target, $(REPROVTARGETS), rm/$(target))
+
ifndef ANSIBLE_PROV_EXTRA_ARGS
ANSIBLE_PROV_EXTRA_ARGS :=
@@ -125,7 +128,7 @@ ifdef VERBOSE
endif
-.PHONY: help clean_except_last clean_bases clean_all clean_failed $(REPROVTARGETS)
+.PHONY: help clean_except_last clean_bases clean_all clean_failed backinglock $(REPROVTARGETS)
help:
@@ -161,6 +164,7 @@ $(PROVTARGETS) $(REPROVTARGETS):
@mkdir -p $(BUILD_DIR)
@cp -r `readlink -f $(ANSIBLE_DIR_PROV)` $(BUILD_DIR)/$(ANSIBLE_DIR_PROV)
@ln -sfn $(FLAVOR).$(TIMESTAMP) $(@D)/$(FLAVOR).latest
+ @ln -sfr $(BUILD_DIR) $(dir $(BASE_IMAGE))/$(TIMESTAMP).backinglock
@-cp -r $@/$(ANSIBLE_DIR_PROV) $(BUILD_DIR)/$(ANSIBLE_DIR_PROV).$(VERSION)
@-cp -r $@/$(ANSIBLE_DIR_PROV).* $(BUILD_DIR)
$(PACKER) build -only=$(PROVISIONER) \
@@ -213,7 +217,22 @@ $(COMPRESSTARGETS):
@mv $(IMAGE_NAME).tmp $(IMAGE_NAME)
+# Safe removal of images
+$(BASERMTARGETS):
+rm/%: %/*.backinglock
+ @rm -rf $(@)
+
+$(PROVRMTARGETS):
+rm/%: %/build/*.backinglock
+ @rm -rf $(@)
+%.backinglock: backinglock
+ @qemu-img convert -f qcow2 $(@)/build/rootfs-image -O qcow2 $(@)/build/rootfs-image.tmp
+ @rm $(@)/build/rootfs-image
+ @mv $(@)/build/rootfs-image.tmp $(@)/build/rootfs-image
+ @rm $(@)
+
+backinglock:
clean_except_last:
@-$(foreach template,$(TEMPLATES),\
@@ -271,6 +290,9 @@ help:
@echo "Commiting backing files and Compressing targets:"
@for C in $(COMPRESSTARGETS); do printf "\t%s\n" "$$C"; done
@echo
+ @echo "For safely removing targets:"
+ @printf "\trm/<target>\n"
+ @echo
@echo "Available options are:"
@printf "\tANSIBLE_DIR_CORE: Set directory with ansible roles for building initramfs (def: ansible-roles)\n"
@printf "\tANSIBLE_DIR_PROV: Set directory with ansible roles for provisioning (def: ansible-roles-prov)\n"