-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
38 lines (29 loc) · 1.04 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
SOURCEDIR ?= configs
BUILDDIR ?= builds
TEMPDIR ?= build-tmp
REPO_DIR ?= .
CONFIGS = $(wildcard $(SOURCEDIR)/*.yml)
IMAGES = $(patsubst $(SOURCEDIR)/%.yml,$(BUILDDIR)/%-manifest.json,$(CONFIGS))
PKR = $(patsubst $(SOURCEDIR)/%.yml,$(BUILDDIR)/%.pkr.hcl,$(CONFIGS))
LOGS = $(patsubst $(SOURCEDIR)/%.yml,$(BUILDDIR)/%.log,$(CONFIGS))
TEMPLATE ?= templates/default.j2
PACKER_FLAGS ?= -color=true
images: $(IMAGES)
packer: $(PKR)
# Use TEMPDIR and mv afterwards so if a step fails the target is not updated
$(BUILDDIR)/%-manifest.json: $(BUILDDIR)/%.pkr.hcl
@mkdir -p $(TEMPDIR)
set -o pipefail; packer build $(PACKER_FLAGS) \
$< | tee $(TEMPDIR)/$(basename $(basename $<)).log
mv $(TEMPDIR)/$(basename $(basename $<)).log $(basename $(basename $<)).log
$(BUILDDIR)/%.pkr.hcl: $(SOURCEDIR)/%.yml
@mkdir -p $(BUILDDIR) $(TEMPDIR)/$(BUILDDIR)
python $(REPO_DIR)/j2-templater.py $(TEMPLATE) $< $(TEMPDIR)/$@
packer validate $(TEMPDIR)/$@
mv $(TEMPDIR)/$@ $@
clean:
rm -f $(IMAGES)
rm -f $(PKR)
rm -f $(LOGS)
rm -rf $(BUILDDIR)
rm -rf $(TEMPDIR)