Windows Sage Setup Provisioner

Hi,

I have created a bash script that will automatically setup sage for Windows users.

This has been tested with Windows 8.1 and the most recent version of Trellis as of 9/6/15.

This solves the lengthy process that must be completed after every ‘vagrant up’ or ‘vagrant destroy’

It completes many of the steps that I have described in the post below.

Soon I wll update this script to handle all of the file changes that must be handled on the VM in order to get the entire Trellis, Bedrock, Sage stack running.

But for now, this script will:

  • Creates node_modules folder & copies package.json from theme to
    /srv/www/sitename.com on VM

  • Installs nodejs & npm

  • Fixes permissions to run npm without sudo & get latest npm

  • Installs gulp and Bower globally

  • Creates a symlink between node_modules in theme folder and the one created on the VM by the script. NPM directories are not written back to the Window’s host machine in order to bypass Window’s 260 character file length limit.

  • Installs npm & bower locally in theme

  • Fixes hosts executable error which prevents deploys & provisions

Before you run this script, you will need to:

Enable symlinks between (L)ocal and (R)emote machines on Windows host.
Run the following command in an admin command prompt and then restart your machine
for it to take effect. This command enables all forms of symlinks between local and
remote machines.

fsutil behavior set SymlinkEvaluation L2L:1 R2R:1 L2R:1 R2L:1

By default, VirtualBox disables symlinks for security reasons. So we need to add this
to our Vagrantfile.

config.vm.provider "virtualbox" do |vb|
    vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant", "1"]
    vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/current", "1"]
end

As of 8/5/15 Symlinks did not work when using VirtualBox 5.0.0
I believe it has something to do with the vagrant guest additions, but I’m no expert.


I’ve included

windows-sage.sh
Vagrantfile - For your reference

https://gist.github.com/darrienworth/05b68adf245e5fc7912a

If you see any errors while the script is running, try running it a second time.


Tips for speeding up Sage on the development server
In some cases the default shared folder implementations (such as VirtualBox shared folders) have high performance penalties. If you’re seeing less than ideal performance with synced folders, NFS can offer a solution. The bigger your project, the slower your development web server will run. I had 5-6++ second page load times before implementing this solution.

Contrary to the vagrant documentation, there is an NFS solution for Windows called winnfsd.

Install it with the following command in the cmd prompt.

$ vagrant plugin install vagrant-winnfsd

After your first ‘vagrant up’ and you have Trellis, Sage, Bedrock completely working and functional

Open your Vagrantfile and comment out

config.vm.synced_folder local_site_path(site), remote_site_path(name), owner: 'vagrant', group: 'www-data', mount_options: ['dmode=776', 'fmode=775']

And add the following line below it

config.vm.synced_folder local_site_path(site), remote_site_path(name), type: 'nfs'

This is needed to give the development web server a major performance boost!

Run

vagrant reload --provision

If you enable nfs in your Vagrantfile before your first vagrant up, you will receive an error. So you will need to toggle between the original line and the new line.

Please let me know if you have any issues.

Hi, your script is unnecessarily complicated.
I work on Windows 10 Pro using the default windows.sh included in trellis, taking care of run vagrant from an elevated powershell terminal.

Installing npm globally is not optimal. A better way to go is nvm, that permits to install node in the user folder ($HOME/.nvm) and manage easily multiple version without getting crazy.

## Install latest version of nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
## Install latest nodejs version using nvm
nvm install stable
## Use stable version of node
nvm use stable

The only necessary part is symlinking the ‘node_modules’ folder to bypass 260 chars limit. However this will be probably no more necessary starting from npm 3.

Hi I appreciate the feedback.

The script I created was a list of all the steps I needed to run through before I could get sage properly working on my system.

I’m more of a designer than a developer, so I’m sure the script isn’t the best, but it allows me to destroy a VM and spin up another one without wanting to jump off a cliff.

I’m glad to see there’s another Windows user with a better way.

I’ll check out nvm.

You’re welcome. :grinning: NVM is a lifesaver.
I worked on gnu/linux for many years then i moved to Windows starting from 8.x, despite from what people say, maybe the best os i ever used. Today Windows is a good and fast all around operating system but can cause a lot of pain in some development stage. Fortunately Vagrant and modern tools like Trellis can give some relief.

Have you done anything in particular to speed up the development server?