Skip to content

Instantly share code, notes, and snippets.

@nathwill
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathwill/7b78f48e08d67e3b1d21 to your computer and use it in GitHub Desktop.
Save nathwill/7b78f48e08d67e3b1d21 to your computer and use it in GitHub Desktop.
snippet of packer-centric makefile
projs := $(basename $(wildcard *.json))
cmds := validate inspect build fix
aliases := bootstrap rebuild
# Enable packer debug logging
PACKER_LOG := 1
PACKER_LOG_PATH := /tmp/packer-debug
export PACKER_LOG PACKER_LOG_PATH
# call out rules that don't generate output
.PHONY: clean deps \
$(cmds) $(foreach proj,$(projs), $(addsuffix -$(proj),$(cmds))) \
all $(projs)
# dep management tasks
clean:
@rm -rf cookbooks
deps: cookbooks
cookbooks:
@berks vendor $@
# auto-define global and per-proj rules for packer commands
define packer_cmd_rules
$1: $(addprefix $1-,$(projs))
$(addprefix $1-,$(projs)):
@packer $1 $$(addsuffix .json,$$(subst $1-,,$$@))
endef
$(foreach cmd,$(cmds), $(eval $(call packer_cmd_rules,$(cmd))))
# auto generate global and per-proj fast-builds
all: $(projs)
$(projs):
@packer build \
-var "base_image=nathwill/${@}" \
$(addsuffix .json, $@)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment