Take home your very own free Vagrant CFML Dev Environment - Presented at dev.Objective() June 17, 2016

Vagrant is a great solution for providing all of your devs a standard dev environment, but like all the other great technology out there, you have to learn it, and then implement it.

Not anymore, this session will give you a well used, documented Vagrant Setup, with the flexibility to use it for all of your future dev projects too. Learn how this Vagrant Environment is setup, and how to extend it. Kill the learning curve, and spin it up today.

This setup is being used by several devs, on several projects, and has simple flexibility built in. Drop your repos in the main folder, follow simple conventions, and add a small amount of configuration and be able to spin up your environment in minutes. This setup can configure a simple welcome page, configure the web server and cfml engine mappings, datasources, web server settings per site, host entries, and much more.

As great as this sounds, nothing is ever perfect, learn how some assumptions left me looking silly, and owing another developer a meal, and how I resolved that issue and made this vagrant setup even better.

3.
The Problem
From developers, designers, managers, everyone working on your app, needs a
way to run dev versions of your app, on their machines.
The problem is, you might have:
● different OSes,
● different file systems,
● different web servers
● different app servers
● different db servers
● manager dns and ips
● a million dependencies to manage

8.
The Solution
A simple vm that can be
up and running in minutes
that gives the developer
the same dev
environment as everyone
else, regardless of
platform, tools, engines,
os etc

9.
The Solution
" Vagrant provides easy to configure,
reproducible, and portable work
environments built on top of industry-
standard technology and controlled by a
single consistent workflow to help
maximize the productivity and flexibility of
you and your team."
https://www.vagrantup.com/docs/why-vagrant/

10.
Is Vagrant Perfect???
● nothing is perfect
● there are a lot of pros and cons
● it might be overkill for
small or simple projects

15.
Docker / Chef / Puppet / Ansible - Cons
● Another set of fast moving tools to learn
● Each have their own strengths and weaknesses
● New configuration options, syntax and DSL
● How easy is it really to drop a CFML site in and go
Disclaimer: I’m going to several docker sessions this week,
so hopefully I will know more

17.
As a CFML Dev - So why should I use vagrant
then?
With the setup I am going to show you:
● It reduces the barriers to entry
● Gives you a great starting point
● No requirement for learning vagrant
We can also work together to better this vagrant tool, offer
more options, and share our successes.

19.
Providers
Providers is the underlying tool that your VM runs on.
While Vagrant ships out of the box with support for
VirtualBox, Hyper-V, and Docker, you can install others.
2 common use cases
● Virtual Box - https://www.virtualbox.org/wiki/Downloads
○ Free
● VM Ware
○ Commercial

20.
Providers
You can switch out a provider in the vagrant file, or
on vagrant up
$ vagrant up --provider=vmware_fusion
$ vagrant up --provider=aws

21.
Boxes
Instead of building a virtual machine from
scratch, which would be a slow and tedious
process, Vagrant uses a base image to quickly
clone a virtual machine.
You can also share your vagrant file and
provisioners, like I am today

22.
Provisioners
Provisioners in Vagrant allow you to automatically install
software, alter configurations, and more on the machine as
part of the vagrant up process.
This is where you can automate your process to make it
repeatable, sharable, and this is where the value of Vagrant
really kicks in.
You can provision with a lot of different tools.

24.
Command Line Interface - CLI
Although you have options to add, edit and remove boxes, and a lot more,
in this session, we're talking about using existing Vagrant setups that we
have built, and we're sharing with you.
Common Commands that you will use with these setups would be
● vagrant up
● vagrant halt
● vagrant reload
● vagrant provision
● vagrant reload --provision
● vagrant ssh
● vagrant destroy
● vagrant share

25.
CLI Command: vagrant up
This command creates and configures guest machines
according to your Vagrantfile.
This is the single most important command in Vagrant, since
it is how any Vagrant machine is created. Anyone using
Vagrant must use this command on a day-to-day basis.

26.
CLI Command: vagrant halt
This command shuts down the running machine Vagrant is
managing.
Vagrant will first attempt to gracefully shut down the machine
by running the guest OS shutdown mechanism. If this fails, or
if the --force flag is specified, Vagrant will effectively just shut
off power to the machine.

27.
CLI Command: vagrant reload
The equivalent of running a halt followed by an up.
This command is usually required for changes made in the
Vagrantfile to take effect. After making any modifications to
the Vagrantfile, a reload should be called.
The configured provisioners will not run again, by default. You
can force the provisioners to re-run by specifying the --
provision flag.

28.
CLI Command: vagrant provision
Runs any configured provisioners against the running
Vagrant managed machine.
This command is a great way to quickly test any provisioners.
You can just make simple modifications to the provisioning
scripts on your machine, run a vagrant provision, and check
for the desired results. Rinse and repeat.

29.
CLI Command: vagrant reload --provision
The equivalent of running a halt followed by an up and forcing
provisioners to run.
After making any modifications to the Vagrantfile, or the
Provisioners, a reload should be called.

30.
CLI Command: vagrant ssh
This will SSH into a running Vagrant machine and give you
access to a shell.
Note: On Windows you need a TTY terminal for full shell
interactivity, one option is ConEmu.

31.
CLI Command: vagrant destroy
This command stops the running machine Vagrant is managing and destroys all
resources that were created during the machine creation process. After running
this command, your computer should be left at a clean state, as if you never
created the guest machine in the first place.
Warning: If you do a destroy, the next time you ‘vagrant up’ - you will have a long
wait before the VM is ready

32.
CLI Command: vagrant share
The share command initializes a Vagrant Share session,
allowing you to share your Vagrant environment with anyone
in the world, enabling collaboration directly in your Vagrant
environment in almost any network environment.
This is not perfect, and you should not rely on it. I will try and
demo this later, but it might go down in flames, be warned.

33.
Learning Curve
The title of this session promised a free cfml dev
environment, do I have to do everything myself?
Thankfully no… thanks to members of the CFML community,
you have some ready to go vagrant images.
Lets look at one, and see how it works.

35.
What’s in the repo?
● vagrant/ : Run all vagrant commands from this directory.
○ artifacts/ : Where downloaded installers will be placed
○ provisioners/ : The provisionning bash scripts for the box
○ configs/ : Configuration files for Nginx, Lucee, etc
○ Vagrantfile/ : The vagrant configuration file
○ log/ : Where a log file is stored that documents the last provisioning
process.
○ Sample_VagrantConfig.yaml : A sample configuration file for new sites.
See "Configuring Sites".
● www/ : Code for the small, default site that shows you the status of your
configuration

36.
Why this setup is awesome
● mappings etc
● cfml customization
● built on commandbox
● you can have fusion reactor built in
● dev config can match staging & production
● Ties into cfml engine to settings & config

37.
Customizations I have made before
● updated lucee version
● updated or specific version or nginx
● SES rewrite support
● installing image magick
● installing and r3 adapter for SAP
● config files that match staging and
production - storage

48.
What is the Vagrant Credentials folder
This is a convention for an external location to store your username and
passwords for your datasources.
VagrantCredentials / DB.yaml
Provisioner looks in this file when generating the datasources for your applications
If you do not have a record for a datasource in the DB.yaml - it will create one for
you and warn you in the provisioner
If you do not have username and password in the app settings yaml, you need a
DB.yaml file, or the provisioner will error.

49.
Why use Vagrant Credentials
Security:
This keeps the usernames and passwords out of your app
source control
Flexibility:
It allows users to have their own usernames and passwords
myDatasource: {username: gavin, password:
topsecretpassword}

57.
Vagrant File - Provider Do
config.vm.provider "virtualbox" do |v|
# set name of vm
v.name = vm_name
# no matter how much cpu is used in vm, use no more than
vm_max_host_cpu_cap amount
v.customize ["modifyvm", :id, "--cpuexecutioncap", vm_max_host_cpu_cap]
# set max amount of host machine ram allotted for vm to use
v.customize ["modifyvm", :id, "--memory", vm_max_memory]
# set number of cpus from host machine that vm is allowed to use
v.customize ["modifyvm", :id, "--cpus", vm_num_cpus]
……...

60.
Vagrant File - The Web Hosts
# An array of hosts that need configured on the host machine to access the VM
hosts = []
# Look for other sites checked out in the same directory as this repo that have a
"VagrantConfig.yaml" in their root.
siteConfigs = Dir["../../*/VagrantConfig/*.yaml"]

71.
ColdFusion 11 Vagrant Box
George Murphy has a CF11 Vagrant running on CentOS.
Presented on it at Into The Box, and some User Groups
https://github.com/murpg/centos-coldfusion-vagrant

72.
More Vagrant Flavors
Using the survey from earlier, I want to prioritize the building
of vagrant boxes with different combinations
Some options can be a flag in the vagrant file
Consistent use across OSes and Webservers with the
conventions
How do you find them all?

73.
Not just installation files any more
Adding IDE and IDE tools / plugins
Adding Vagrant and Docker images & getting started guides
Lets all pitch in and make our lives easier - http://www.cfmlrepo.com
Blog post and new site coming soon