|
54 | 54 | #
|
55 | 55 | # REFERENCE:
|
56 | 56 | #
|
| 57 | +# config.vm.box = "wplib/wplib" |
| 58 | +# |
| 59 | +# This line specifies the VM "box" image which is hosted for |
| 60 | +# download on Hashicorp's Atlas Vagrant Box Repository here: |
| 61 | +# |
| 62 | +# https://atlas.hashicorp.com/wplib/boxes/wplib |
| 63 | +# |
| 64 | +# This box image is a pre-provisioned Ubuntu Linux 14.04 LTS |
| 65 | +# with nginx, MySQL, PHP7.0/5.6 and more; everything a good |
| 66 | +# a Linux server needs to be able to serve WordPress pages. |
| 67 | +# |
| 68 | +# In many ways -- compared to Vagrant boxes like VVV and VIP |
| 69 | +# Quickstart -- this is WPLib's "secret sauce." |
| 70 | +# |
57 | 71 | # File.write('IP', "10.10.10.#{rand(10..250)}") if not File.exists?('IP')
|
58 | 72 | #
|
59 | 73 | # This line creates a randomly-generated and non-routable IP
|
|
79 | 93 | # If we can find a better approach later, we will be happy
|
80 | 94 | # to switch to it.
|
81 | 95 | #
|
82 |
| -# config.vm.box = "wplib/wplib" |
| 96 | +# File.write('HOSTNAME', "wplib.box") if not File.exists?('HOSTNAME') |
83 | 97 | #
|
84 |
| -# This line specifies the VM "box" image which is hosted for |
85 |
| -# download on Hashicorp's Atlas Vagrant Box Repository here: |
| 98 | +# This line writes the host name of 'wplib.box' to a file |
| 99 | +# named 'HOSTNAME' in the project's root folder, the same |
| 100 | +# folder in which this Vagrantfile is found to ensure future |
| 101 | +# runs of "vagrant up" or "vagrant reload" use the same host |
| 102 | +# name, unless of course you change it, which we expect. |
86 | 103 | #
|
87 |
| -# https://atlas.hashicorp.com/wplib/boxes/wplib |
| 104 | +# The host name in this context is a domain name local to |
| 105 | +# your computer which you can access via your browser by |
| 106 | +# prefixing the host name with 'http://', for example |
| 107 | +# http://wplib.box or http://example.dev. |
88 | 108 | #
|
89 |
| -# This box image is a pre-provisioned Ubuntu Linux 14.04 LTS |
90 |
| -# with nginx, MySQL, PHP5.6 and more; essentially everything |
91 |
| -# a Linux server needs to be able to serve WordPress pages. |
| 109 | +# To change the host name of your WPLib Box simple update |
| 110 | +# the `HOSTNAME` file to include only your preferred host |
| 111 | +# name, e.g. `example.dev` or similar (but without the |
| 112 | +# quotes). |
92 | 113 | #
|
93 |
| -# In many ways -- compared to Vagrant boxes like VVV and VIP |
94 |
| -# Quickstart -- this is WPLib's "secret sauce." |
| 114 | +# hostname = IO.read('HOSTNAME').strip; |
| 115 | +# |
| 116 | +# This line reads the value in the file named 'HOSTNAME', |
| 117 | +# strips off any leading or trailing whitespace and then |
| 118 | +# assignes it to a variable named 'hostname' which is |
| 119 | +# local to this Vagrantfile. |
95 | 120 | #
|
96 |
| -# config.vm.hostname = "wplib.box" |
| 121 | +# If the previous line wrote the file then it will load |
| 122 | +# 'wplib.box' otherwise it will load a host name that |
| 123 | +# you have updated the 'HOSTNAME' file to include, such |
| 124 | +# as 'example.dev' or similar (but without the quotes). |
| 125 | +# |
| 126 | +# config.vm.hostname = hostname |
97 | 127 | #
|
98 | 128 | # This line specifies the domain name your browser should be
|
99 | 129 | # able to load the WordPress site running inside this box.
|
100 | 130 | #
|
| 131 | +# This value comes from the file named 'HOSTNAME' which was |
| 132 | +# created and/or read into the variable 'hostname' in the |
| 133 | +# previous two lines. |
| 134 | +# |
101 | 135 | # To CHANGE the domain name to use to when loading the box's
|
102 |
| -# website in your browser you only need to change this line; |
103 |
| -# change "wplib.box" to your preferred local domain name and |
104 |
| -# then run "vagrant reload" in your terminal. |
| 136 | +# website in your browser you only need to update the file |
| 137 | +# named 'HOSTNAME', or create one if it does not already |
| 138 | +# exist. It should be a text file than only contains the |
| 139 | +# local domain name that you want to use to access the |
| 140 | +# website(s) on your WPLib Box. |
105 | 141 | #
|
106 | 142 | # Of course your computer's hosts file must contain the IP
|
107 | 143 | # address used by the box for your browser to use it to load
|
108 | 144 | # WordPress but if you have the Vagrant hosts-updater plugin
|
109 | 145 | # then it will handle updating the hosts file for you.
|
110 | 146 | #
|
| 147 | +# Assuming you have that plugin, once you've updated the |
| 148 | +# 'HOSTNAME' file run "vagrant up" or "vagrant reload" in |
| 149 | +# your terminal to update your computer's 'hosts' file to |
| 150 | +# recognize this domain name when typed into your browser. |
| 151 | +# |
| 152 | +# config.hostsupdater.aliases = [ |
| 153 | +# "www.#{hostname}", |
| 154 | +# "adminer.#{hostname}", |
| 155 | +# "mailhog.#{hostname}" |
| 156 | +# ] |
| 157 | +# |
| 158 | +# These lines specify addition domains that WPLib Box will |
| 159 | +# add to your hosts file (assuming you have the Vagrant |
| 160 | +# hosts-updater plugin) and thus WPLib Box will be able to |
| 161 | +# recognize when you request them from your browser. |
| 162 | +# |
| 163 | +# You'll note the use the same (base) host name as the |
| 164 | +# prior line so look to its description for further details |
| 165 | +# on the 'hostname' variable. |
| 166 | +# |
| 167 | +# These lines add a 'www.' alias, domains for Adminer (which |
| 168 | +# is like phpMyAdmin, only better) and for Mailhog (that |
| 169 | +# captures outgoing email into a web email interface, great |
| 170 | +# for accessing the password change request emails that are |
| 171 | +# normally so hard to track down during development, |
| 172 | +# especially if sent to someone else's email address!) |
| 173 | +# |
| 174 | +# You can add other domains here that you might need, such |
| 175 | +# as subdomains of your domain, if you have that need. |
| 176 | +# |
111 | 177 | # config.vm.network 'private_network', ip: IO.read('IP').strip
|
112 | 178 | #
|
113 | 179 | # This line tells Vagrant what IP address to use for the VM.
|
|
191 | 257 | # - https://github.com/mitchellh/vagrant/tree/master/keys
|
192 | 258 | # - https://twitter.com/mitchellh/status/525704721714012160
|
193 | 259 | #
|
194 |
| -# config.vm.provision "shell", path: "scripts/provision.sh" |
| 260 | +# $provision = <<PROVISION |
| 261 | +# if [ -f "/vagrant/scripts/provision.sh" ]; then |
| 262 | +# bash /vagrant/scripts/provision.sh --force |
| 263 | +# else |
| 264 | +# rm -rf /tmp/box-scripts 2>/dev/null |
| 265 | +# git clone https://github.com/wplib/box-scripts.git /tmp/box-scripts 2>/dev/null |
| 266 | +# bash /tmp/box-scripts/provision.sh |
| 267 | +# fi |
| 268 | +# PROVISION |
| 269 | +# |
| 270 | +# These lines create an "inline" provisioning script to be |
| 271 | +# run on the FIRST "vagrant up" or on any "vagrant up" or |
| 272 | +# "vagrant reload" that has the "--provision" switch. |
| 273 | +# |
| 274 | +# This inline script checks for a provision script on disk |
| 275 | +# named '/vagrant/scripts/provision.sh' and if there it |
| 276 | +# runs it. If not there it pulls it down from GitHub by |
| 277 | +# cloning the script, and then it runs it. |
| 278 | +# |
| 279 | +# config.vm.provision "shell", inline: $provision |
195 | 280 | #
|
196 |
| -# This line tells Vagrant to run the bash script named |
197 |
| -# "provision.sh" found in the "scripts" folder which is in |
198 |
| -# the same folder where Vagrantfile is located. |
| 281 | +# This line tells Vagrant to run the "inline" bash script |
| 282 | +# described above, which ultimately runs the "provision.sh" |
| 283 | +# found in the "scripts" folder which is in the same folder |
| 284 | +# where Vagrantfile is located. |
199 | 285 | #
|
200 | 286 | # This provision script runs a few quick commands, such as
|
201 | 287 | # importing "/sql/default.sql" which is the default MySQL
|
|
209 | 295 | #
|
210 | 296 | # REUSE:
|
211 | 297 | #
|
212 |
| -# When you cloning the WPLib Box repository you are getting an |
| 298 | +# When you clone the WPLib Box repository you are getting an |
213 | 299 | # "appliance" for WordPress local development that is designed
|
214 |
| -# to "just work" if at all possible. |
| 300 | +# to "just work," if at all possible. |
215 | 301 | #
|
216 |
| -# However once comfortable with WPLib Box few developers will |
217 |
| -# want to start a problem by first using "git clone" on the |
218 |
| -# github.com/wplib/wplib-box repository. In point of fact, we |
219 |
| -# don't even use WPLib Box in that manner. |
| 302 | +# However once comfortable with WPLib Box most developers will |
| 303 | +# probably not want to start with a "git clone" of the |
| 304 | +# github.com/wplib/wplib-box repository but instead maintain |
| 305 | +# their own Vagrantfile which is based off this one. In point |
| 306 | +# of fact, this is how we use WPLib Box ourselves. |
220 | 307 | #
|
221 |
| -# Instead developers will want a recipe for how to use WPLib |
| 308 | +# But we believe developers want a recipe for how to use WPLib |
222 | 309 | # Box in their projects with the least effort required. And
|
223 | 310 | # that is exactly how WPLib Box is intended to be used once
|
224 | 311 | # a developer becomes familiar with it.
|
|
228 | 315 | #
|
229 | 316 | # 1. Copy this file into a new Vagrantfile in your project.
|
230 | 317 | #
|
231 |
| -# 2. Change config.vm.hostname = "wplib.box" to replace the |
232 |
| -# value of "wplib.box" with the local development domain |
233 |
| -# of your project, e.g. "dev.example.com" |
| 318 | +# 2. Create a/update the HOSTNAME file and replace 'wplib.box' |
| 319 | +# with a local domain name relevant to your project, for |
| 320 | +# examples: 'acme.dev' or 'example.dev'. |
234 | 321 | #
|
235 | 322 | # 3. Either delete the link with config.vm.provision "shell"
|
236 | 323 | # or copy "scripts/provision.sh" and modify it to run
|
|
252 | 339 |
|
253 | 340 | Vagrant.configure(2) do |config|
|
254 | 341 |
|
| 342 | + config.vm.box = "wplib/wplib" |
| 343 | + |
255 | 344 | File.write('IP', "10.10.10.#{rand(10..250)}") if not File.exists?('IP')
|
| 345 | + File.write('HOSTNAME', "wplib.box") if not File.exists?('HOSTNAME') |
256 | 346 |
|
257 |
| - config.vm.box = "wplib/wplib" |
258 |
| - config.vm.hostname = "wplib.box" |
| 347 | + hostname = IO.read('HOSTNAME').strip; |
| 348 | + |
| 349 | + config.vm.hostname = hostname |
259 | 350 | config.hostsupdater.aliases = [
|
260 |
| - "adminer.wplib.box", |
261 |
| - "mailhog.wplib.box" |
| 351 | + "www.#{hostname}", |
| 352 | + "adminer.#{hostname}", |
| 353 | + "mailhog.#{hostname}" |
262 | 354 | ]
|
263 | 355 |
|
264 | 356 | config.vm.network 'private_network', ip: IO.read('IP').strip
|
|
0 commit comments