forked from StackStorm/packer-st2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
105 lines (92 loc) · 3.68 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
PACKER ?= ~/bin/packer
PACKER_VERSION := 1.8.4
VAGRANT ?= ~/bin/vagrant
VAGRANT_VERSION := 2.3.4
GIT ?= git
CURL ?= curl
SHELL := /bin/bash
UNAME := $(shell uname | tr '[:upper:]' '[:lower:]')
# Fetch latest stable release if 'ST2_VERSION' ENV var not set (ex: `2.7.1`)
ST2_VERSION ?= $(shell curl --silent "https://api.github.com/repos/stackstorm/st2/releases/latest" | jq -r .tag_name | sed 's/^v//')
# Get today's date if 'BOX_VERSION' ENV var not set (ex: `20180507`)
BOX_VERSION ?= $(shell date -u +%Y%m%d)
BOX_ORG ?= stackstorm
.PHONY: install-inspec inspec-lint install-packer validate build publish clean install-vagrant
VAGRANT = $(shell command -v vagrant 2>/dev/null)
install-vagrant:
ifeq (,$(VAGRANT))
@{ \
case $(UNAME) in \
darwin) \
curl -fsSLo tmp/vagrant.dmg 'https://releases.hashicorp.com/vagrant/$(VAGRANT_VERSION)/vagrant_$(VAGRANT_VERSION)_$(UNAME)_amd64.dmg'; \
hdiutil attach tmp/vagrant.dmg; \
sudo installer -pkg /Volumes/Vagrant/vagrant.pkg -target /; \
hdiutil detach /dev/disk2s1; \
@echo Vagrant $(VAGRANT_VERSION) was successfully installed!
;; \
linux) \
curl -fsSLo tmp/vagrant.zip 'https://releases.hashicorp.com/vagrant/$(VAGRANT_VERSION)/vagrant_$(VAGRANT_VERSION)_$(UNAME)_amd64.zip'; \
mkdir -p ~/bin 2>/dev/null; \
unzip -o -d ~/bin tmp/vagrant.zip; \
chmod +x bin/vagrant; \
@echo Vagrant $(VAGRANT_VERSION) was successfully installed!
;; \
esac \
}
VAGRANT = $(shell command -v vagrant 2>/dev/null)
endif
install-packer: tmp/packer_$(PACKER_VERSION).zip
mkdir -p ~/bin
unzip -o -d ~/bin $<
chmod +x $(PACKER)
@echo Packer $(PACKER_VERSION) was successfully installed!
# Install packer only if it doesn't exist
$(PACKER):
@$(MAKE) install-packer
tmp/packer_$(PACKER_VERSION).zip:
curl -fsSLo $@ 'https://releases.hashicorp.com/packer/$(PACKER_VERSION)/packer_$(PACKER_VERSION)_$(UNAME)_amd64.zip'
@echo Downloaded new Packer version: $(PACKER_VERSION)!
# ~/bin/packer-post-processor-vagrant-cloud-standalone
validate: $(PACKER)
$(PACKER) validate st2.json
INSPEC = $(shell command -v inspec 2>/dev/null)
install-inspec: # https://docs.chef.io/inspec/install
ifeq (,$(INSPEC))
@{ \
case $(UNAME) in \
darwin) \
brew install chef/chef/inspec; \
;; \
linux) \
curl https://omnitruck.chef.io/install.sh | sudo bash -s -- -P inspec; \
;; \
esac \
}
INSPEC = $(shell command -v inspec 2>/dev/null)
endif
inspec-lint: $(INSPEC)
@{ \
cd test/integration/ && \
for dir in */; do \
dir=$$(basename $$dir) ; \
if [ -f "$${dir}/inspec.yml" ]; then \
echo -e "\nRunning Inspec lint for \033[1;36m$${dir}\033[0m ..."; \
inspec check --chef-license=accept-silent --diagnose $${dir}; \
fi \
done \
}
build: $(PACKER) validate
$(PACKER) build \
-var 'st2_version=$(ST2_VERSION)' \
-var 'box_version=$(BOX_VERSION)' \
-var 'box_org=$(BOX_ORG)' \
st2.json
publish: $(VAGRANT)
vagrant cloud publish \
--description "Box with StackStorm (aka 'IFTTT for Ops') event-driven automation platform: auto-remediation, security responses, facilitated troubleshooting, complex deployments, ChatOps and more. \n* https://stackstorm.com/ \n* Documentation: https://docs.stackstorm.com/ \n* Community: https://stackstorm.com/community-signup \n* Discussions: https://github.com/StackStorm/st2/discussions" \
--short-description "StackStorm v$(ST2_VERSION)-$(BOX_VERSION)" \
--version-description "StackStorm v$(ST2_VERSION)-$(BOX_VERSION)" \
--checksum-type sha256 --checksum "$(shell sha256sum builds/st2_v$(ST2_VERSION)-$(BOX_VERSION).box | awk '{print $$1}')" \
--force --release $(BOX_ORG)/st2 $(ST2_VERSION)-$(BOX_VERSION) virtualbox builds/st2_v$(ST2_VERSION)-$(BOX_VERSION).box
clean:
rm -rf tmp/*