Thanks for getting back to me, that seems to make some sense. This is my vagrant file so far...
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "phusion/ubuntu-14.04-amd64"
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network "forwarded_port", guest: 80, host: 3500
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "192.168.10.10"
# If true, then any SSH connections made will enable agent forwarding.
# Default value: false
config.ssh.forward_agent = true
# configuration step 0: provision setup
config.vm.provision "shell", path: "vagrant/provisioner.sh"
# configuration step 1: apt-get
config.vm.provision "shell", path: "vagrant/apt-get.sh"
# configuration step 2: git
config.vm.provision "shell", path: "vagrant/git.sh"
# configuration step 3: nodejs
config.vm.provision "shell", path: "vagrant/nodejs.sh"
# configuration step 4: mongodb
config.vm.provision "shell", path: "vagrant/mongodb.sh"
# configuration step 5: redis
config.vm.provision "shell", path: "vagrant/redis.sh"
# configuration step 6: nginx
config.vm.provision "shell", path: "vagrant/nginx.sh"
# configuration step 7. env
config.vm.provision "shell", path: "vagrant/env.sh"
# configuration step 8. install
config.vm.provision "shell", path: "vagrant/install.sh"
end
See step 7 is the point at which I'd like to customise it. In step 7, I actually run a nodejs bash script (because I'm more comfortable with that, and by the time step 7 runs it's been installed) which loads a JSON file containing environment variables.
At this point, I'd want to load a different set of environment variables per environment, for configuration of the application. For example, I'd want to define a different URL for my application to run on, a different database to connect to (for the various environments, one per environment), a different redis cache URL, etc. I think I can actually understand how to do this now using environment variables, something like:
Then in my shell script, I can use the value of ENV['TARGET'] to load in other files like env.development.json, or env.staging.json, env.beta.json or whatever.
That solves one problem, thank you! But now I'm a little confused about how you might target different environments on the same provider. It seems as though you can only have one instance per provider (unless you do a multiple machine setup, but I wouldn't always want my code to be the same per provider), because you run vagrant up --provider=aws? How would I vagrant up my staging env on aws, or my beta env on aws?
Scott.