take home your very own free vagrant cfml dev environment

89
Take Home Your Very Own Free Vagrant CFML Dev Environment Presented By: Gavin Pickin dev.Objective() 2016

Upload: coldfusionconference

Post on 12-Apr-2017

390 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Take Home Your Very Own Free Vagrant CFML Dev Environment

Take Home Your Very Own Free Vagrant CFML Dev Environment

Presented By: Gavin Pickindev.Objective() 2016

Page 2: Take Home Your Very Own Free Vagrant CFML Dev Environment

Who Am I?★Gavin Pickin – developing Web Apps since late 90s

○Ortus Solutions Software Consultant

○ContentBox Evangelist

★What else do you need to know?

○CFMLRepo.com http://www.cfmlrepo.com

○Blog - http://gpickin.com

○Twitter – http://tw.gavinpickin.com

○Github - https://github.com/gpickin

○Linked In: http://li.gavinpickin.com/

★Lets get on with the show.

Page 3: Take Home Your Very Own Free Vagrant CFML Dev Environment

The ProblemFrom 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

Page 4: Take Home Your Very Own Free Vagrant CFML Dev Environment

● Windows● CentOS / RHEL● Ubuntu● Other?

What OS do you use?

Page 5: Take Home Your Very Own Free Vagrant CFML Dev Environment

What Web Server do you use?● IIS● Apache● Nginx

Page 6: Take Home Your Very Own Free Vagrant CFML Dev Environment

What CFML Server do you use?● Railo● Lucee 4.5● Lucee 5● ColdFusion 9● ColdFusion 10● ColdFusion 11● ColdFusion 12 2016

Page 7: Take Home Your Very Own Free Vagrant CFML Dev Environment

What DB do you use?● MSSql● MySql● PostgreSql● Oracle● Couchbase● CouchDB● Reddis● Mongo

● Local Storage● Cookies● MS Access● Excel● CSV● Text

Page 8: Take Home Your Very Own Free Vagrant CFML Dev Environment

The SolutionA 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

Page 9: Take Home Your Very Own Free Vagrant CFML Dev Environment

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/

Page 10: Take Home Your Very Own Free Vagrant CFML Dev Environment

Is Vagrant Perfect???● nothing is perfect● there are a lot of pros and cons● it might be overkill for

small or simple projects

Page 11: Take Home Your Very Own Free Vagrant CFML Dev Environment

Alternatives to Vagrant● CommandBox● Docker - Containers● Chef / Puppet / Ansible

Page 12: Take Home Your Very Own Free Vagrant CFML Dev Environment

CommandBox - Pros● love it● cross platform● Simple● multi engine● it's cfml and json ● always improving

Page 13: Take Home Your Very Own Free Vagrant CFML Dev Environment

CommandBox - Cons● undertow not a full web server● It's dependent on your os● limited host support● limited rewrites etc● it's dependent on your

libraries tools etc

Page 14: Take Home Your Very Own Free Vagrant CFML Dev Environment

Docker / Chef / Puppet / Ansible - Pros● Lots of great alternative options● Lots of great features and benefits

but...

Page 15: Take Home Your Very Own Free Vagrant CFML Dev Environment

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

Page 16: Take Home Your Very Own Free Vagrant CFML Dev Environment

Why use Vagrant?● automated configuration for team environments, perfect example,

SAP connector or image magick plugins● automated mappings, data sources, other settings● automated dependencies and library versions● easy switching in and out between os, web servers etc● source control for sharing and maintaining the specs / automation● solid cross platform compat ● dev like local, test like staging

Page 17: Take Home Your Very Own Free Vagrant CFML Dev Environment

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.

Page 18: Take Home Your Very Own Free Vagrant CFML Dev Environment

Installing VagrantInstalling Vagrant is easy

Visit Download page and select the appropriate OS packagehttps://www.vagrantup.com/downloads.html

Installation will add ‘vagrant’ to your path. Logout and login again if necessary

Page 19: Take Home Your Very Own Free Vagrant CFML Dev Environment

ProvidersProviders 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

Page 20: Take Home Your Very Own Free Vagrant CFML Dev Environment

ProvidersYou can switch out a provider in the vagrant file, or on vagrant up

$ vagrant up --provider=vmware_fusion

$ vagrant up --provider=aws

Page 21: Take Home Your Very Own Free Vagrant CFML Dev Environment

BoxesInstead 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

Page 22: Take Home Your Very Own Free Vagrant CFML Dev Environment

ProvisionersProvisioners 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.

Page 23: Take Home Your Very Own Free Vagrant CFML Dev Environment

PluginsOnce Vagrant is installed, or if it already is, it's highly recommended that you install the following Vagrant plugins:

● vagrant-hostsupdater $ vagrant plugin install vagrant-hostsupdater

● vagrant-vbguest $ vagrant plugin install vagrant-vbguest

Page 24: Take Home Your Very Own Free Vagrant CFML Dev Environment

Command Line Interface - CLIAlthough 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

Page 25: Take Home Your Very Own Free Vagrant CFML Dev Environment

CLI Command: vagrant upThis 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.

Page 26: Take Home Your Very Own Free Vagrant CFML Dev Environment

CLI Command: vagrant haltThis 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.

Page 27: Take Home Your Very Own Free Vagrant CFML Dev Environment

CLI Command: vagrant reloadThe 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.

Page 28: Take Home Your Very Own Free Vagrant CFML Dev Environment

CLI Command: vagrant provisionRuns 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.

Page 29: Take Home Your Very Own Free Vagrant CFML Dev Environment

CLI Command: vagrant reload --provisionThe 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.

Page 30: Take Home Your Very Own Free Vagrant CFML Dev Environment

CLI Command: vagrant sshThis 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.

Page 31: Take Home Your Very Own Free Vagrant CFML Dev Environment

CLI Command: vagrant destroyThis 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

Page 32: Take Home Your Very Own Free Vagrant CFML Dev Environment

CLI Command: vagrant shareThe 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.

Page 33: Take Home Your Very Own Free Vagrant CFML Dev Environment

Learning CurveThe 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.

Page 34: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant-centos-luceeGithub Repo: https://github.com/Ortus-Solutions/vagrant-centos-lucee

Big thanks to: Dan Skaggs, Luis Majano, Brad Wood, and Evagoras Charalambous

Lets look at the readme.md

Page 35: Take Home Your Very Own Free Vagrant CFML Dev Environment

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

Page 36: Take Home Your Very Own Free Vagrant CFML Dev Environment

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

Page 37: Take Home Your Very Own Free Vagrant CFML Dev Environment

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

Page 38: Take Home Your Very Own Free Vagrant CFML Dev Environment

Deep dive into the r3 adapter install● copy jars

● copy *.so files

● you, installing lib.std.c++5.0

● copying an so file to the right folder /usr/var

● creating and ldconfig conf file with paths to jars

and so files

● running the ldconfig to load the dynamic library

Page 39: Take Home Your Very Own Free Vagrant CFML Dev Environment

Let's look at vagrant up and running I’m not dumb enough to do a full live demo without slides.

Screenshots, so we can stop and talk about each one

Fingers crossed, we’ll try a live demo too.

Page 40: Take Home Your Very Own Free Vagrant CFML Dev Environment
Page 41: Take Home Your Very Own Free Vagrant CFML Dev Environment
Page 42: Take Home Your Very Own Free Vagrant CFML Dev Environment
Page 43: Take Home Your Very Own Free Vagrant CFML Dev Environment
Page 44: Take Home Your Very Own Free Vagrant CFML Dev Environment
Page 45: Take Home Your Very Own Free Vagrant CFML Dev Environment
Page 46: Take Home Your Very Own Free Vagrant CFML Dev Environment
Page 47: Take Home Your Very Own Free Vagrant CFML Dev Environment
Page 48: Take Home Your Very Own Free Vagrant CFML Dev Environment
Page 49: Take Home Your Very Own Free Vagrant CFML Dev Environment
Page 50: Take Home Your Very Own Free Vagrant CFML Dev Environment
Page 51: Take Home Your Very Own Free Vagrant CFML Dev Environment
Page 52: Take Home Your Very Own Free Vagrant CFML Dev Environment
Page 53: Take Home Your Very Own Free Vagrant CFML Dev Environment
Page 54: Take Home Your Very Own Free Vagrant CFML Dev Environment

Add a new site to this setupThe conventions for this setup are fairly simple

Create a folder to put your VM stuff in

Inside that:

● clone your vagrant repo● Add your websites● Add VagrantConfig folder to your websites● Add vagrant credentials folder**

** Vagrant Credentials Folder - optional but recommended

Page 55: Take Home Your Very Own Free Vagrant CFML Dev Environment

Add your WebsiteYou can take 2 approaches to adding your files

Flat structure Nested structure

Page 56: Take Home Your Very Own Free Vagrant CFML Dev Environment

Website Vagrant Config File● Yaml file - Tabs and spaces matter

● Location: VagrantConfig / settings.yaml

● Site settings to help vagrant spin up your website automatically

Page 57: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant Config - Page 1# name of the appname: coldboxRest

# Path to web root relative to the repo rootwebroot: www

# SES Rewrites - True or Falsesesrewrites: false

# List of domains to be added to the Host machine's and VM's "hosts" filehosts:- coldboxrest.gpickin.com

Page 58: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant Config - Page 2# List of CF Mappings to create relative to the repo root or drive root if starts with a /cfmappings:- virtual: '/storage/coldboxrest/' physical: '/opt/storage/coldboxrest/'

# List of Nginx Mappings to createnginxmappings:- virtual: '/storage/coldboxrest/' physical: '/opt/storage/coldboxrest/'

Page 59: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant Config - Page 3# List of datasources to createdatasources:- name: coldboxapp_client database: coldboxapp_Client host: mydb.gpickin.com port: 1433 class: com.microsoft.jdbc.sqlserver.SQLServerDriver dsn: jdbc:sqlserver://{host}:{port};DATABASENAME={database};sendStringParametersAsUnicode=true;SelectMethod=direct storage: true password: topsecret username: gavin

Page 60: Take Home Your Very Own Free Vagrant CFML Dev Environment

Provisioning your WebsitesVagrant provision or vagrant reload --provision

Page 61: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant Mini Web Status Page

Page 62: Take Home Your Very Own Free Vagrant CFML Dev Environment

What is the Vagrant Credentials folderThis 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.

Page 63: Take Home Your Very Own Free Vagrant CFML Dev Environment

Why use Vagrant CredentialsSecurity: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}

Page 64: Take Home Your Very Own Free Vagrant CFML Dev Environment

Reprovision VagrantVagrant provision or vagrant reload --provision

Page 65: Take Home Your Very Own Free Vagrant CFML Dev Environment

Now our sites work

Page 66: Take Home Your Very Own Free Vagrant CFML Dev Environment

The Site List Mini Website

Page 67: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant FileThe vagrant file is the core of vagrant, with all the details, on what should run, when, and how.

https://github.com/Ortus-Solutions/vagrant-centos-lucee/blob/master/vagrant/Vagrantfile

# -*- mode: ruby -*-# vi: set ft=ruby :

# Require YAML modulerequire 'yaml'

Page 68: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant File - Server Configuration# server configurationvm_ip_address = "192.168.60.35"vm_naked_hostname = "lucee.dev"vm_name = "Lucee-CFML"vm_max_memory = 1024vm_num_cpus = 2vm_max_host_cpu_cap = "100"

Page 69: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant File - Synced Folders# synced folder configurationsynced_webroot_local = "../www"synced_webroot_box = "/var/wwwDefault/"synced_webroot_id = "wwwDefault"synced_webroot_owner = "vagrant"synced_webroot_group = "vagrant"

synced_parent_local = "../../"synced_parent_box = "/vagrant-parent"synced_parent_id = "vagrant-parent"synced_parent_owner = "vagrant"synced_parent_group = "vagrant"

Page 70: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant File - do ConfigVagrant.configure("2") do |config|

config.vm.box = "centos-7-x64"

config.vm.box_url = "https://github.com/holms/vagrant-centos7-box/releases/download/7.1.1503.001/CentOS-7.1.1503-x86_64-netboot.box"

config.vm.boot_timeout = 180

Page 71: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant File - Provider Doconfig.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] ……...

Page 72: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant File - Provider Do - Cont. # the next two settings enable using the host computer's dns inside the vagrant box # enable dns proxy in nat mode v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] # use the host's resolver as a dns proxy in nat mode v.customize ["modifyvm", :id, "--natdnsproxy1", "on"] end

Page 73: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant File - Network Setup # set vm ip address and add auto_correct on forwarded port so it doesn't collide with other vagrant boxes

config.vm.network :private_network, ip: vm_ip_address

# config.vm.network :forwarded_port, guest: 22, host: 2223, auto_correct: true

Page 74: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant File - The Web Hosts# An array of hosts that need configured on the host machine to access the VMhosts = []

# 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"]

Page 75: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant File - The Web Hosts - Cont.siteConfigs.each do |config|

if File.read(config).length > 0 thisConfig = YAML.load_file( config ) puts "Found '#{thisConfig["name"]}' in #{config.sub! '../../', ''}" hosts.concat thisConfig["hosts"]

elseputs "Found '#{config}' but it was empty!"

endend

Page 76: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant File - Host Updaterif Vagrant.has_plugin?("vagrant-hostsupdater") # set vm hostname

config.vm.hostname = vm_naked_hostname config.hostsupdater.aliases = hostsend

Page 77: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant File - Provisioners# Init log fileconfig.vm.provision :shell, :path => "provisioners/setup-log.sh", :privileged => true

# set vm timezone and do some cleanup before installationsconfig.vm.provision :shell, :path => "provisioners/set-vm-timezone.sh", :privileged => true

# install miscellaneous utilitiesconfig.vm.provision :shell, :path => "provisioners/install-utilities.sh", :privileged => true

Page 78: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant File - Provisioners# install/configure nginxconfig.vm.provision :shell, :path => "provisioners/install-nginx.sh", :privileged => true

# install/configure Oracle JDKconfig.vm.provision :shell, :path => "provisioners/install-jdk.sh", :privileged => true

Page 79: Take Home Your Very Own Free Vagrant CFML Dev Environment

Vagrant File - Provisioners# install/configure CommandBoxconfig.vm.provision :shell, :path => "provisioners/install-commandbox.sh", :privileged => true

# install/configure luceeconfig.vm.provision :shell, :path => "provisioners/install-lucee.sh", :privileged => true, :args => [

vm_name, vm_naked_hostname, vm_ip_address]

Page 80: Take Home Your Very Own Free Vagrant CFML Dev Environment

Gotchas - The hard lessons learned● Hosts plugin, killing vagrant can leave them in your hosts file

● Vpn access can mess with your host files, and sometimes your Vagrant

● Case sensitivity

Page 81: Take Home Your Very Own Free Vagrant CFML Dev Environment

Gotchas - The hard lessons learned● Sometimes I forgot if it was running...

● Or which vagrant was running

● Fs plugin only works for 1 share

● vagrant reload vs vagrant reload --provision

Page 82: Take Home Your Very Own Free Vagrant CFML Dev Environment

Gotchas - The hard lessons learned● Hosts plugin, killing vagrant can leave them in your hosts file● Vpn access can mess with your host files, and sometimes your

vagrant● Sometimes I forgot if it was running... Or which vagrant was

running● Case sensitivity● Fs plugin only works for 1 share● Vagrant reload vs vagrant reload --provision

Page 83: Take Home Your Very Own Free Vagrant CFML Dev Environment

CentOS Lucee Nginx Vagrant● This is the vagrant box used today● Please go fork it, star it, and subscribe● Clone it, spin it up and try it out

Github repo: https://github.com/Ortus-Solutions/vagrant-centos-lucee

Page 84: Take Home Your Very Own Free Vagrant CFML Dev Environment

Ubuntu Lucee Nginx Vagrant● This is the vagrant box I have not completed converting

yet● Please go fork it, star it, and watch it for more information.

Github repo: https://github.com/Ortus-Solutions/vagrant-ubuntu-lucee

Page 85: Take Home Your Very Own Free Vagrant CFML Dev Environment

ColdFusion 11 Vagrant BoxGeorge 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

Page 86: Take Home Your Very Own Free Vagrant CFML Dev Environment

More Vagrant FlavorsUsing 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?

Page 87: Take Home Your Very Own Free Vagrant CFML Dev Environment

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.comBlog post and new site coming soon

Page 88: Take Home Your Very Own Free Vagrant CFML Dev Environment

Q & A● Questions

● Comments

● Insults?

Page 89: Take Home Your Very Own Free Vagrant CFML Dev Environment

● Come try some chocolateRichy & Creamy

● Keep an eye on http://www.gpickin.com/ for slides, blog posts and updates

● Linked In - http://li.gavinpickin.com/

Thanks everyone