Skip to content

Commit

Permalink
Transforming to new form after migration from http://github.com/mishe…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mischa Taylor committed May 13, 2014
1 parent 42efec9 commit 2d6f8d8
Show file tree
Hide file tree
Showing 16 changed files with 332 additions and 79 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
packer_cache/
output-*
*.box
*.tar.gz
iso
crash.log
tmp
.vagrant/
*.swp
Makefile.local

.DS_Store
183 changes: 183 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
# if Makefile.local exists, include it
ifneq ("$(wildcard Makefile.local)", "")
include Makefile.local
endif

DEBIAN75_AMD64 ?= http://cdimage.debian.org/cdimage/release/7.5.0/amd64/iso-dvd/debian-7.5.0-amd64-DVD-1.iso
DEBIAN74_AMD64 ?= http://cdimage.debian.org/cdimage/archive/7.4.0/amd64/iso-dvd/debian-7.4.0-amd64-DVD-1.iso
DEBIAN73_AMD64 ?= http://cdimage.debian.org/cdimage/archive/7.3.0/amd64/iso-dvd/debian-7.3.0-amd64-DVD-1.iso
DEBIAN609_AMD64 ?= http://cdimage.debian.org/cdimage/archive/6.0.9/amd64/iso-cd/debian-6.0.9-amd64-CD-1.iso
DEBIAN75_I386 ?= http://cdimage.debian.org/cdimage/release/7.5.0/i386/iso-dvd/debian-7.5.0-i386-DVD-1.iso
DEBIAN74_I386 ?= http://cdimage.debian.org/cdimage/archive/7.4.0/i386/iso-dvd/debian-7.4.0-i386-DVD-1.iso
DEBIAN73_I386 ?= http://cdimage.debian.org/cdimage/archive/7.3.0/i386/iso-dvd/debian-7.3.0-i386-DVD-1.iso
DEBIAN609_I386 ?= http://cdimage.debian.org/cdimage/archive/6.0.9/i386/iso-cd/debian-6.0.9-i386-CD-1.iso

# Possible values for CM: (nocm | chef | chefdk | salt | puppet)
CM ?= nocm
# Possible values for CM_VERSION: (latest | x.y.z | x.y)
CM_VERSION ?=
ifndef CM_VERSION
ifneq ($(CM),nocm)
CM_VERSION = latest
endif
endif
# Packer does not allow empty variables, so only pass variables that are defined
ifdef CM_VERSION
PACKER_VARS := -var 'cm=$(CM)' -var 'cm_version=$(CM_VERSION)'
else
PACKER_VARS := -var 'cm=$(CM)'
endif
ifeq ($(CM),nocm)
BOX_SUFFIX := -$(CM).box
else
BOX_SUFFIX := -$(CM)$(CM_VERSION).box
endif
BUILDER_TYPES := vmware virtualbox
TEMPLATE_FILENAMES := $(wildcard *.json)
BOX_FILENAMES := $(TEMPLATE_FILENAMES:.json=$(BOX_SUFFIX))
BOX_FILES := $(foreach builder, $(BUILDER_TYPES), $(foreach box_filename, $(BOX_FILENAMES), box/$(builder)/$(box_filename)))
TEST_BOX_FILES := $(foreach builder, $(BUILDER_TYPES), $(foreach box_filename, $(BOX_FILENAMES), test-box/$(builder)/$(box_filename)))
VMWARE_BOX_DIR := box/vmware
VIRTUALBOX_BOX_DIR := box/virtualbox
VMWARE_OUTPUT := output-vmware-iso
VIRTUALBOX_OUTPUT := output-virtualbox-iso
VMWARE_BUILDER := vmware-iso
VIRTUALBOX_BUILDER := virtualbox-iso
CURRENT_DIR = $(shell pwd)

.PHONY: all list clean

all: $(BOX_FILES)

test: $(TEST_BOX_FILES)

# Generic rule - not used currently
#$(VMWARE_BOX_DIR)/%$(BOX_SUFFIX): %.json
# cd $(dir $<)
# rm -rf output-vmware-iso
# mkdir -p $(VMWARE_BOX_DIR)
# packer build -only=vmware-iso $(PACKER_VARS) $<

$(VMWARE_BOX_DIR)/debian75$(BOX_SUFFIX): debian75.json
rm -rf $(VMWARE_OUTPUT)
mkdir -p $(VMWARE_BOX_DIR)
packer build -only=$(VMWARE_BUILDER) $(PACKER_VARS) -var "iso_url=$(DEBIAN75_AMD64)" $<

$(VMWARE_BOX_DIR)/debian74$(BOX_SUFFIX): debian74.json
rm -rf $(VMWARE_OUTPUT)
mkdir -p $(VMWARE_BOX_DIR)
packer build -only=$(VMWARE_BUILDER) $(PACKER_VARS) -var "iso_url=$(DEBIAN74_AMD64)" $<

$(VMWARE_BOX_DIR)/debian73$(BOX_SUFFIX): debian73.json
rm -rf $(VMWARE_OUTPUT)
mkdir -p $(VMWARE_BOX_DIR)
packer build -only=$(VMWARE_BUILDER) $(PACKER_VARS) -var "iso_url=$(DEBIAN73_AMD64)" $<

$(VMWARE_BOX_DIR)/debian609$(BOX_SUFFIX): debian609.json
rm -rf $(VMWARE_OUTPUT)
mkdir -p $(VMWARE_BOX_DIR)
packer build -only=$(VMWARE_BUILDER) $(PACKER_VARS) -var "iso_url=$(DEBIAN609_AMD64)" $<

$(VMWARE_BOX_DIR)/debian75-i386$(BOX_SUFFIX): debian75-i386.json
rm -rf $(VMWARE_OUTPUT)
mkdir -p $(VMWARE_BOX_DIR)
packer build -only=$(VMWARE_BUILDER) $(PACKER_VARS) -var "iso_url=$(DEBIAN75_I386)" $<

$(VMWARE_BOX_DIR)/debian74-i386$(BOX_SUFFIX): debian74-i386.json
rm -rf $(VMWARE_OUTPUT)
mkdir -p $(VMWARE_BOX_DIR)
packer build -only=$(VMWARE_BUILDER) $(PACKER_VARS) -var "iso_url=$(DEBIAN74_I386)" $<

$(VMWARE_BOX_DIR)/debian73-i386$(BOX_SUFFIX): debian73-i386.json
rm -rf $(VMWARE_OUTPUT)
mkdir -p $(VMWARE_BOX_DIR)
packer build -only=$(VMWARE_BUILDER) $(PACKER_VARS) -var "iso_url=$(DEBIAN73_I386)" $<

$(VMWARE_BOX_DIR)/debian609-i386$(BOX_SUFFIX): debian609-i386.json
rm -rf $(VMWARE_OUTPUT)
mkdir -p $(VMWARE_BOX_DIR)
packer build -only=$(VMWARE_BUILDER) $(PACKER_VARS) -var "iso_url=$(DEBIAN609_I386)" $<

# Generic rule - not used currently
#$(VIRTUALBOX_BOX_DIR)/%$(BOX_SUFFIX): %.json
# cd $(dir $<)
# rm -rf output-virtualbox-iso
# mkdir -p $(VIRTUALBOX_BOX_DIR)
# packer build -only=virtualbox-iso $(PACKER_VARS) $<

$(VIRTUALBOX_BOX_DIR)/debian75$(BOX_SUFFIX): debian75.json
rm -rf $(VIRTUALBOX_OUTPUT)
mkdir -p $(VIRTUALBOX_BOX_DIR)
packer build -only=$(VIRTUALBOX_BUILDER) $(PACKER_VARS) -var "iso_url=$(DEBIAN75_AMD64)" $<

$(VIRTUALBOX_BOX_DIR)/debian74$(BOX_SUFFIX): debian74.json
rm -rf $(VIRTUALBOX_OUTPUT)
mkdir -p $(VIRTUALBOX_BOX_DIR)
packer build -only=$(VIRTUALBOX_BUILDER) $(PACKER_VARS) -var "iso_url=$(DEBIAN74_AMD64)" $<

$(VIRTUALBOX_BOX_DIR)/debian73$(BOX_SUFFIX): debian73.json
rm -rf $(VIRTUALBOX_OUTPUT)
mkdir -p $(VIRTUALBOX_BOX_DIR)
packer build -only=$(VIRTUALBOX_BUILDER) $(PACKER_VARS) -var "iso_url=$(DEBIAN73_AMD64)" $<

$(VIRTUALBOX_BOX_DIR)/debian609$(BOX_SUFFIX): debian609.json
rm -rf $(VIRTUALBOX_OUTPUT)
mkdir -p $(VIRTUALBOX_BOX_DIR)
packer build -only=$(VIRTUALBOX_BUILDER) $(PACKER_VARS) -var "iso_url=$(DEBIAN609_AMD64)" $<

$(VIRTUALBOX_BOX_DIR)/debian75-i386$(BOX_SUFFIX): debian75-i386.json
rm -rf $(VIRTUALBOX_OUTPUT)
mkdir -p $(VIRTUALBOX_BOX_DIR)
packer build -only=$(VIRTUALBOX_BUILDER) $(PACKER_VARS) -var "iso_url=$(DEBIAN75_I386)" $<

$(VIRTUALBOX_BOX_DIR)/debian74-i386$(BOX_SUFFIX): debian74-i386.json
rm -rf $(VIRTUALBOX_OUTPUT)
mkdir -p $(VIRTUALBOX_BOX_DIR)
packer build -only=$(VIRTUALBOX_BUILDER) $(PACKER_VARS) -var "iso_url=$(DEBIAN74_I386)" $<

$(VIRTUALBOX_BOX_DIR)/debian73-i386$(BOX_SUFFIX): debian73-i386.json
rm -rf $(VIRTUALBOX_OUTPUT)
mkdir -p $(VIRTUALBOX_BOX_DIR)
packer build -only=$(VIRTUALBOX_BUILDER) $(PACKER_VARS) -var "iso_url=$(DEBIAN73_I386)" $<

$(VIRTUALBOX_BOX_DIR)/debian609-i386$(BOX_SUFFIX): debian609-i386.json
rm -rf $(VIRTUALBOX_OUTPUT)
mkdir -p $(VIRTUALBOX_BOX_DIR)
packer build -only=$(VIRTUALBOX_BUILDER) $(PACKER_VARS) -var "iso_url=$(DEBIAN609_I386)" $<

list:
@for box_file in $(BOX_FILES) ; do \
echo $$box_file ; \
done ;

clean: clean-builders clean-output clean-packer-cache

clean-builders:
@for builder in $(BUILDER_TYPES) ; do \
if test -d box/$$builder ; then \
echo Deleting box/$$builder/*.box ; \
find box/$$builder -maxdepth 1 -type f -name "*.box" ! -name .gitignore -exec rm '{}' \; ; \
fi ; \
done

clean-output:
@for builder in $(BUILDER_TYPES) ; do \
echo Deleting output-$$builder-iso ; \
echo rm -rf output-$$builder-iso ; \
done

clean-packer-cache:
echo Deleting packer_cache
rm -rf packer_cache

test-$(VMWARE_BOX_DIR)/%$(BOX_SUFFIX): $(VMWARE_BOX_DIR)/%$(BOX_SUFFIX)
bin/test-box.sh $< vmware_desktop vmware_fusion $(CURRENT_DIR)/test/*_spec.rb

test-$(VIRTUALBOX_BOX_DIR)/%$(BOX_SUFFIX): $(VIRTUALBOX_BOX_DIR)/%$(BOX_SUFFIX)
bin/test-box.sh $< virtualbox virtualbox $(CURRENT_DIR)/test/*_spec.rb

ssh-$(VMWARE_BOX_DIR)/%$(BOX_SUFFIX): $(VMWARE_BOX_DIR)/%$(BOX_SUFFIX)
bin/ssh-box.sh $< vmware_desktop vmware_fusion $(CURRENT_DIR)/test/*_spec.rb

ssh-$(VIRTUALBOX_BOX_DIR)/%$(BOX_SUFFIX): $(VIRTUALBOX_BOX_DIR)/%$(BOX_SUFFIX)
bin/ssh-box.sh $< virtualbox virtualbox $(CURRENT_DIR)/test/*_spec.rb
24 changes: 24 additions & 0 deletions bin/ssh-box.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash -eux

box_path=$1
box_provider=$2
vagrant_provider=$3

box_filename=$(basename "${box_path}")
box_name=${box_filename%.*}
tmp_path=/tmp/boxtest

rm -rf ${tmp_path}

vagrant box remove ${box_name} --provider ${box_provider} || true
vagrant box add ${box_name} ${box_path}
mkdir -p ${tmp_path}

pushd ${tmp_path}
vagrant init ${box_name}
VAGRANT_LOG=warn vagrant up --provider ${vagrant_provider}
vagrant ssh
vagrant destroy -f
popd

vagrant box remove ${box_name} --provider ${box_provider}
43 changes: 43 additions & 0 deletions bin/test-box.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash -eux

create_vagrantfile_linux() {
cat << EOF > $tmp_path/Vagrantfile
Vagrant.configure('2') do |config|
config.vm.box = '$box_name'
config.vm.provision :serverspec do |spec|
spec.pattern = '$test_src_path'
end
end
EOF
}

cleanup() {
rm -f ~/.ssh/known_hosts
}

box_path=$1
box_provider=$2
vagrant_provider=$3
test_src_path=$4

box_filename=$(basename "${box_path}")
box_name=${box_filename%.*}
tmp_path=/tmp/boxtest

rm -rf ${tmp_path}

vagrant box remove ${box_name} --provider ${box_provider} 2>/dev/null || true
vagrant box add ${box_name} ${box_path}
mkdir -p ${tmp_path}

pushd ${tmp_path}
create_vagrantfile_linux
cleanup
VAGRANT_LOG=warn vagrant up --provider ${vagrant_provider}
sleep 10
vagrant destroy -f
popd

vagrant box remove ${box_name} --provider ${box_provider}
cleanup
17 changes: 8 additions & 9 deletions debian609-i386.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"variables": {
"provisioner": "provisionerless",
"provisioner_version": "",
"cm": "nocm",
"cm_version": "",
"iso_url": "http://cdimage.debian.org/cdimage/archive/6.0.9/i386/iso-cd/debian-6.0.9-i386-CD-1.iso",
"iso_checksum": "bc2886211bce0e9c54bdf779f21a35d5e5a122fd"
},
Expand Down Expand Up @@ -82,22 +82,21 @@
"provisioners": [{
"type": "shell",
"environment_vars": [
"PROVISIONER={{user `provisioner`}}",
"PROVISIONER_VERSION={{user `provisioner_version`}}"
"CM={{user `cm`}}",
"CM_VERSION={{user `cm_version`}}"
],
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'",
"scripts": [
"script/base.sh",
"script/vagrant.sh",
"script/vmtools.sh",
"script/provisioner.sh",
"script/cleanup.sh",
"script/zerodisk.sh"
"script/vmtool.sh",
"script/cmtool.sh",
"script/cleanup.sh"
]
}],
"post-processors": [{
"type": "vagrant",
"keep_input_artifact": false,
"output": "../../{{.Provider}}/debian609-i386-{{user `provisioner`}}{{user `provisioner_version`}}.box"
"output": "box/{{.Provider}}/debian609-i386-{{user `cm`}}{{user `cm_version`}}.box"
}]
}
17 changes: 8 additions & 9 deletions debian609.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"variables": {
"provisioner": "provisionerless",
"provisioner_version": "",
"cm": "nocm",
"cm_version": "",
"iso_url": "http://cdimage.debian.org/cdimage/archive/6.0.9/amd64/iso-cd/debian-6.0.9-amd64-CD-1.iso",
"iso_checksum": "3f3ec3e1adb4c2904a1234799f4775c10cf47cce"
},
Expand Down Expand Up @@ -82,22 +82,21 @@
"provisioners": [{
"type": "shell",
"environment_vars": [
"PROVISIONER={{user `provisioner`}}",
"PROVISIONER_VERSION={{user `provisioner_version`}}"
"CM={{user `cm`}}",
"CM_VERSION={{user `cm_version`}}"
],
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'",
"scripts": [
"script/base.sh",
"script/vagrant.sh",
"script/vmtools.sh",
"script/provisioner.sh",
"script/cleanup.sh",
"script/zerodisk.sh"
"script/vmtool.sh",
"script/cmtool.sh",
"script/cleanup.sh"
]
}],
"post-processors": [{
"type": "vagrant",
"keep_input_artifact": false,
"output": "../../{{.Provider}}/debian609-{{user `provisioner`}}{{user `provisioner_version`}}.box"
"output": "box/{{.Provider}}/debian609-{{user `cm`}}{{user `cm_version`}}.box"
}]
}
17 changes: 8 additions & 9 deletions debian73-i386.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"variables": {
"provisioner": "provisionerless",
"provisioner_version": "",
"cm": "nocm",
"cm_version": "",
"iso_url": "http://cdimage.debian.org/cdimage/archive/7.3.0/i386/iso-dvd/debian-7.3.0-i386-DVD-1.iso",
"iso_checksum": "0b6b29b7dd004362889a52fb06d68f4131d79801",
"iso_checksum_type": "sha1"
Expand Down Expand Up @@ -73,22 +73,21 @@
"provisioners": [{
"type": "shell",
"environment_vars": [
"PROVISIONER={{user `provisioner`}}",
"PROVISIONER_VERSION={{user `provisioner_version`}}"
"CM={{user `cm`}}",
"CM_VERSION={{user `cm_version`}}"
],
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S bash '{{.Path}}'",
"scripts": [
"script/base.sh",
"script/vagrant.sh",
"script/vmtools.sh",
"script/provisioner.sh",
"script/cleanup.sh",
"script/zerodisk.sh"
"script/vmtool.sh",
"script/cmtool.sh",
"script/cleanup.sh"
]
}],
"post-processors": [{
"type": "vagrant",
"keep_input_artifact": false,
"output": "../../{{.Provider}}/debian73-i386-{{user `provisioner`}}{{user `provisioner_version`}}.box"
"output": "box/{{.Provider}}/debian73-i386-{{user `cm`}}{{user `cm_version`}}.box"
}]
}
Loading

0 comments on commit 2d6f8d8

Please sign in to comment.