Skip to content

Commit

Permalink
Merge pull request #2 from mcphailtom/vca_vagrant
Browse files Browse the repository at this point in the history
Packer/Vagrant updates
  • Loading branch information
Mahmoud Bassiouny committed Apr 24, 2015
2 parents d6bdbde + 9821c56 commit c3c4a15
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 33 deletions.
40 changes: 31 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ else
PHOTON_SOURCES := sources
endif

.PHONY : all iso clean toolchain toolchain-minimal photon-build-machine photon-vagrant-box \
.PHONY : all iso clean toolchain toolchain-minimal photon-build-machine photon-vagrant-build photon-vagrant-local \
check check-bison check-g++ check-gawk check-createrepo check-vagrant check-packer check-packer-ovf-plugin

all: iso
Expand Down Expand Up @@ -55,7 +55,7 @@ sources:
@cd $(PHOTON_PULL_SOURCES_DIR) && \
$(PHOTON_PULL_SOURCES) $(PHOTON_SRCS_DIR)

sources-cached:
sources-cached:
@echo "Using cached SOURCES..."
@$(MKDIR) -p $(PHOTON_SRCS_DIR) && \
$(CP) -rf $(PHOTON_SOURCES_PATH)/* $(PHOTON_SRCS_DIR)/
Expand Down Expand Up @@ -140,18 +140,33 @@ photon-build-machine: check-packer check-vagrant
@cd $(PHOTON_PACKER_TEMPLATES) && \
$(PACKER) build photon-build-machine.json
@echo "Adding box to Vagrant boxes..."
@$(VAGRANT) box add $(PHOTON_PACKER_TEMPLATES)/photon-build-machine-vmware.box --name photon-build-machine --force && \
$(RM) $(PHOTON_PACKER_TEMPLATES)/photon-build-machine-vmware.box
@$(VAGRANT) box add $(PHOTON_PACKER_TEMPLATES)/photon-build-machine.box --name photon-build-machine --force && \
$(RM) $(PHOTON_PACKER_TEMPLATES)/photon-build-machine.box

photon-vagrant-box: check-packer check-vagrant
@echo "Building a photon based Vagrant box with Packer..."
photon-vagrant-build: check-vagrant
@echo "Starting Photon build using Vagrant..."
@cd $(SRCROOT) && \
$(VAGRANT) up && \
$(VAGRANT) destroy -f

ifeq ($(VAGRANT_BUILD),all)
PACKER_ARGS=""
else
PACKER_ARGS="-only=$(VAGRANT_BUILD)"
endif

photon-vagrant-local: check-packer check-vagrant

@echo "Building a Photon Vagrant box with Packer..."
@if [ -e $(PHOTON_STAGE)/photon.iso ]; then \
cd $(PHOTON_PACKER_TEMPLATES) && \
$(SED) -i "" -e "s#\"iso_checksum_value\":.*#\"iso_checksum_value\": \"$$($(SHASUM) ../../stage/photon.iso | cut -f 1 -d ' ')\"#" photon.json && \
$(PACKER) build photon.json && \
$(SED) -i "" -e "s#\"iso_checksum_value\":.*#\"iso_checksum_value\": \"\"#" photon.json && \
$(SED) -i "" -e "s#\"iso_checksum_value\":.*#\"iso_checksum_value\": \"$$($(SHASUM) ../../stage/photon.iso | cut -f 1 -d ' ')\",#" photon.json && \
$(PACKER) build $(PACKER_ARGS) photon.json && \
$(SED) -i "" -e "s#\"iso_checksum_value\":.*#\"iso_checksum_value\": \"\",#" photon.json; \
echo "Moving boxes to $(PHOTON_STAGE)..." && \
$(MV) *.box $(PHOTON_STAGE); \
else \
echo "Unable to find $(PHOTON_STAGE)/photon.iso ... aborting build"; \
fi

check: check-bison check-g++ check-gawk check-createrepo
Expand All @@ -171,7 +186,14 @@ check-createrepo:
check-vagrant: check-packer
@command -v $(VAGRANT) >/dev/null 2>&1 || { echo "Vagrant not installed or wrong path, expecting $(VAGRANT). Aborting" >&2; exit 1; }


ifeq ($(VAGRANT_BUILD),vcloudair)
check-packer: check-packer-ovf-plugin
else ifeq ($(VAGRANT_BUILD),all)
check-packer: check-packer-ovf-plugin
else
check-packer:
endif
@command -v $(PACKER) >/dev/null 2>&1 || { echo "Packer not installed or wrong path, expecting $(PACKER). Aborting" >&2; exit 1; }

check-packer-ovf-plugin:
Expand Down
1 change: 1 addition & 0 deletions support/make/makedefs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SED=/usr/bin/sed
SHASUM=/usr/bin/shasum
PACKER=/usr/local/bin/packer
VAGRANT=/usr/bin/vagrant
VAGRANT_BUILD=vagrant

SRCROOT := $(realpath $(SRCROOT))
MAKEROOT := $(realpath $(MAKEROOT))
Expand Down
23 changes: 17 additions & 6 deletions support/packer-templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@

This directory contains [Packer](http://packer.io) templates for `photon-build-machine` and to build a generic `photon` Vagrant box with `docker` binding on `0.0.0.0:2375`.

`photon-build-machine` is a Ubuntu 14.04.1 that contains all the prerequisites to build Photon from scratch, and is the box referenced by the top-level Vagrantfile, to build this machine you will need:
`photon-build-machine` is a Ubuntu 14.04.2 that contains all the prerequisites to build Photon from scratch, and is the box referenced by the top-level Vagrantfile, to build this machine you will need:

- VMware Workstation (on Windows and Linux) or Fusion (on Mac OS X)
- A recent Packer install (tested on v0.7.5)
- Packer OVF Post Processor from [GitHub](https://github.com/gosddc/packer-post-processor-vagrant-vmware-ovf) (Optional for vCloud Air build)
- Vagrant vCloud Air Provider from [GitHub](https://github.com/gosddc/vagrant-vcloudair) (Optional for vCloud Air usage)

### Automatic build machine
To automatically build the `photon-build-machine` and push into the local Vagrant box repository use the make target from the root of the Photon source:
```
sudo make photon-build-machine
make photon-build-machine
```

### Build an ISO using a Vagrant based build machine
To automatically build the `photon-build-machine` and push into the local Vagrant box repository use the make target:
Assuming that the `photon-build-machine` has been created and resides in your local Vagrant repository, running `vagrant up` from the source root will automatically build a new `photon.iso` using the `photon-build-machine` Vagrant box and copy this onto the host into the `stage` directory. The machine will be halted at the completion of the build and can be reused or destroyed using `vagrant destroy`

Alternatively use the convenience make target to run the build process and destroy the machine on completion:
```
sudo make photon-build-machine
make photon-vagrant-build
```
Running `vagrant up` from the source root will automatically build a new `photon.iso` using the `photon-build-machine` Vagrant box and copy this onto the host into the `stage` directory. The machine will be halted at the completion of the build and can be reused or destroyed using `vagrant destroy`

#### Troubleshooting

Expand All @@ -27,8 +30,16 @@ By default Packer will run headless when building the `photon-build-machine` vm,
## Photon Vagrant box with Docker
To build a new Photon Vagrant box and make it available in the `stage` directory use the make target from the root of the Photon source:
```
sudo make photon-vagrant-box
make photon-vagrant-local
```
By default this process will build a Vagrant box using the vmware provider which can be used with VMware Fusion or Workstation. Setting the VAGRANT_BUILD variable allows finer control of the build output:

1. Vagrant only (default) ```make photon-vagrant-local``` OR explicit version ```make photon-vagrant-local VAGRANT_BUILD=vagrant```
2. vCloud Air or vCloud ```make photon-vagrant-local VAGRANT_BUILD=vcloudair```
3. All builds ```make photon-vagrant-local VAGRANT_BUILD=all```

The Vagrant box is configured to start a Docker service daemon bound to 0.0.0.0:2375 which is remapped to your host for convenience. Export DOCKER_HOST=tcp://127.0.0.1:2375 to use.

A sample Vagrantfile for use with vCloud Air resides in ```support/vagrant/Vagrantfile_VCA_Sample```, refer to the [vagrant-vcloudair](https://github.com/gosddc/vagrant-vcloudair) for advanced usage details.

The box is configured to match the Vagrant base box standards, however it is not meant as an official Vagrant box build for Photon but rather as a starting point to create your own.
4 changes: 2 additions & 2 deletions support/packer-templates/photon-build-machine.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"manifest_dir": "puppet/manifests",
"module_paths": [
"puppet/modules"
]
]
},
{
"type": "shell",
Expand All @@ -61,7 +61,7 @@
{
"type": "vagrant",
"compression_level": 9,
"output": "{{.BuildName}}-{{.Provider}}.box"
"output": "{{.BuildName}}.box"
}
]
}
77 changes: 64 additions & 13 deletions support/packer-templates/photon.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,80 @@
{
"variables": {
"iso_file": "../../stage/photon.iso",
"iso_checksum_value": ""
"iso_checksum_value": "99afd5b3280ba91be67907ae2d3be79c05ba3067",
"product_name": "Photon",
"product_version": "1.0",
"headless": "true",
"disk_size": "204080",
"ssh_password": "VMware123!",
"ssh_wait_timeout": "5m",
"shutdown_command": "shutdown -h now"
},
"builders": [
{
"name": "photon",
"name": "vagrant",
"vm_name": "photon",
"vmdk_name": "photon-disk0",
"type": "vmware-iso",
"headless": true,
"disk_size": 20480,
"headless": "{{user `headless`}}",
"disk_size": "{{user `disk_size`}}",
"disk_type_id": 0,
"guest_os_type": "other3xlinux-64",
"iso_url": "{{user `iso_file`}}",
"iso_checksum": "{{user `iso_checksum_value`}}",
"iso_checksum_type": "sha1",
"ssh_username": "root",
"ssh_password": "VMware123!",
"ssh_wait_timeout": "60m",
"ssh_password": "{{user `ssh_password`}}",
"ssh_wait_timeout": "{{user `ssh_wait_timeout`}}",
"shutdown_command": "shutdown -h now",
"http_directory": ".",
"boot_command": [
"<enter>",
"<wait5><enter><enter>",
"<wait5><enter><enter><enter>",
"<down><down><enter><wait>",
"photon<enter><wait>",
"VMware123!<enter><wait>",
"{{user `ssh_password`}}<enter>",
"<wait10><wait10><wait10><wait10><wait10><wait10><wait10>",
"<enter>",
"<wait10><wait10><wait10><wait10><wait10><wait10>",
"root<enter><wait>VMware123!<enter><wait>",
"<wait10><wait10><wait10>",
"root<enter><wait>{{user `ssh_password`}}<enter><wait>",
"sed -i -e 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config<enter>",
"<wait10><wait10><wait10><wait10><wait10><wait10>",
"systemctl restart sshd.service<enter>"
"<wait>",
"systemctl restart sshd.service<enter>",
"<wait5>"
]
},
{
"name": "vcloudair",
"vm_name": "photon",
"vmdk_name": "photon-disk0",
"type": "vmware-iso",
"headless": "{{user `headless`}}",
"disk_size": "{{user `disk_size`}}",
"disk_type_id": 0,
"guest_os_type": "other3xlinux-64",
"iso_url": "{{user `iso_file`}}",
"iso_checksum": "{{user `iso_checksum_value`}}",
"iso_checksum_type": "sha1",
"ssh_username": "root",
"ssh_password": "{{user `ssh_password`}}",
"ssh_wait_timeout": "{{user `ssh_wait_timeout`}}",
"shutdown_command": "shutdown -h now",
"http_directory": ".",
"boot_command": [
"<enter>",
"<wait5><enter><enter><enter>",
"<down><down><enter><wait>",
"photon<enter><wait>",
"{{user `ssh_password`}}<enter>",
"<wait10><wait10><wait10><wait10><wait10><wait10><wait10>",
"<enter>",
"<wait10><wait10><wait10>",
"root<enter><wait>{{user `ssh_password`}}<enter><wait>",
"sed -i -e 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config<enter>",
"<wait>",
"systemctl restart sshd.service<enter>",
"<wait5>"
]
}
],
Expand All @@ -50,8 +92,17 @@
"post-processors": [
{
"type": "vagrant",
"only": ["vagrant"],
"compression_level": 9,
"vagrantfile_template": "scripts/photon-vagrantfile_template.rb",
"output": "{{user `product_name`}}-{{.BuildName}}.box"
},
{
"type": "vagrant-vmware-ovf",
"only": ["vcloudair"],
"compression_level": 9,
"vagrantfile_template": "scripts/photon-vagrantfile_template.rb"
"vagrantfile_template": "scripts/photon-vagrantfile_template.rb",
"output": "{{user `product_name`}}-{{.BuildName}}.box"
}
]

Expand Down
38 changes: 38 additions & 0 deletions support/vagrant/Vagrantfile_VCA_Sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Set our default provider for this Vagrantfile to 'vcloudair'
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vcloudair'

Vagrant.configure('2') do |config|

# vCloud Air provider settings
config.vm.provider :vcloudair do |vcloudair|

vcloudair.username = '<username@domain>'
vcloudair.password = '<password>'

# if you're using a vCloud Air Dedicated Cloud, put the cloud id here, if
# you're using a Virtual Private Cloud, skip this parameter.
vcloudair.cloud_id = '<dedicated cloud id>'
vcloudair.vdc_name = '<vdc name>'

# Set the network to deploy our VM on
vcloudair.vdc_network_name = '<vdc network name>'

# Set our Edge Gateway and the public IP we're going to use.
vcloudair.vdc_edge_gateway = '<vdc edge gateway>'
vcloudair.vdc_edge_gateway_ip = '<vdc edge gateway public ip>'

# Catalog that holds our templates.
vcloudair.catalog_name = 'Vagrant'

# Set our Memory and CPU to a sensible value for Docker.
vcloudair.memory = 2048
vcloudair.cpus = 2
end

#Configure the box to use
config.vm.box = 'box-name'

end
8 changes: 5 additions & 3 deletions support/vagrant/photon-build-machine-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#################################################
# Title: photon-build-machine-init #
# Date: 2015-03-17 #
# Version: 1.0 #
# Date: 2015-04-16 #
# Version: 1.1 #
# Author: tmcphail@vmware.com #
# Options: #
#################################################
Expand All @@ -22,7 +22,9 @@ sudo make toolchain
sudo make iso

# Remove the old stage directory on the host and copy the newly built one
if [[ -d ${PHOTON_HOST}/stage ]] ; then
if [ ! -e ${PHOTON_WORKING}/stage/discus.iso ]; then
echo "The build failed..."
elif [ -d ${PHOTON}/stage ]; then
echo "Refreshing the host stage directory content..."
rm -rf ${PHOTON_HOST}/stage
cp -R ${PHOTON_WORKING}/stage ${PHOTON_HOST}/stage
Expand Down

0 comments on commit c3c4a15

Please sign in to comment.