-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.mk
46 lines (40 loc) · 1.45 KB
/
common.mk
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
export ROOT := $(shell realpath ../)
export BOX_DIR := $(dir $(abspath $(lastword $(shell echo $(MAKEFILE_LIST) | cut -d' ' -f1 ))))
export BOX_NAME := $(notdir $(patsubst %/,%,$(BOX_DIR)))
export BUILDS_DIR := $(ROOT)/builds
export COMMON_DIR := $(ROOT)/_common
export NOW := $(shell date +%s)
export PACKER_CACHE_DIR = $(ROOT)/.packer_cache
export TEST_BASEDIR = $(ROOT)/.spec
export SHELL := /usr/bin/env bash
ifneq ("$(shell which packer)","")
export PACKER = $(shell which packer)
else
export PACKER := ../bin/packer
endif
default: clean build test copy
clean:
rm -rf "$(BUILDS_DIR)/$(BOX_NAME)-virtualbox"
rm -f "$(BUILDS_DIR)/$(BOX_NAME)-virtualbox.box"
build:
$(PACKER) build -var "name=$(BOX_NAME)" -var "output=$(BUILDS_DIR)/$(BOX_NAME)" ./packer.json
test:
$(call test_box,virtualbox)
copy:
cp -r "$(BUILDS_DIR)/$(BOX_NAME)-virtualbox" "$(BUILDS_DIR)/$(BOX_NAME)-virtualbox-$(NOW)"
cp "$(BUILDS_DIR)/$(BOX_NAME)-virtualbox.box" "$(BUILDS_DIR)/$(BOX_NAME)-virtualbox-$(NOW).box"
define test_box
set -ex; \
export VAGRANT_BOX="$(BUILDS_DIR)/$(BOX_NAME)-${1}.box"; \
export SPEC_DIR="$(BOX_DIR)spec"; \
export TEST_DIR="$(TEST_BASEDIR)/$(BOX_NAME)-$(NOW)-${1}"; \
mkdir -p "$${TEST_DIR}"; \
cp "$(COMMON_DIR)/Vagrantfile" "$${TEST_DIR}/Vagrantfile"; \
pushd "$${TEST_DIR}"; \
vagrant up --provider=${1} || TEST_EC=$${?}; \
vagrant destroy -f; \
vagrant box remove --all $${VAGRANT_BOX}; \
popd; \
rm -rf "$${TEST_DIR}"; \
exit $${TEST_EC}
endef