Spin up a golang development environment with a MEAN stack on the side.
This Vagrant and Virtualbox based Ansible playbook sets up a Go development environment.
For persistence, two alternatives are included:
- MongoDB as part of a complete MEAN stack (Mongodb, Node + Express suitable for back-end for Angular SPAs) together with a sample AngularJS application run on a NodeJS server.
- MySql server
-
Install VirtualBox and Vagrant (make sure Vagrant is version 1.6.5 or later)
-
Install Ansible
-
Clone this project to a folder where you keep your VMs
-
First execute
vagrant box list
to check ifubuntu/trusty64
is already on your laptop or desktop host system. If it isn't download the box withvagrant box add ubuntu/trusty64
. -
If you receive messages to the effect that the box has a newer version, follow the instructions:
==> default: A newer version of the box 'ubuntu/trusty64' is available! You currently
==> default: have version '20150609.0.10'. The latest is version '20151015.0.0'. Run
==> default: `vagrant box update` to update.
-
On the cammand-line in that folder, type
vagrant up
-
The process will take a while, on my 4GB RAM MacBook Pro it took about 20+ minutes initially. But remember that's just the first time, once you have it provisioned it starts up again very quickly. A large part of the initial slowness is the one-time provisioning via Ansible of the MEAN components, especially MongoDB.
-
Check out your new vm on the command line with
vagrant ssh
-
Associate
http://golang-dev/
(or any other name you'd like) with local machine IP specified in the Vagrantfile (192.168.46.100 initially) by including the following line in/etc/hosts
:192.168.46.100 golang-dev
-
Within the guest VM box, if you do your work in, say,
/vagrant/dev/project01
then in the VM dir./dev/project01
you can access the files with your favorite editor or IDE or else edit via ssh remoting. -
The MEAN stack example app is at
/vagrant/dev/recipe-js
-
If you create and run a node.js app on port 3000, you can access it in your browser by pointing it at
http://golang-dev:3000
.
- Box used: Ubuntu 14.04 64-bit (Trusty)
- Virtualbox settings:
- memory 1024
- IP 192.168.76.103
- Installs build-essential, git and curl packages from Apt together with golang and mysql-server (including python-mysqldb in order to automate tasks with mysql).
- The firewall is optionally disabled since the purpose is local development (comment out to omit).
- MySql is started up, the test database removed and a golang-dev database created, with user root without password.
- MongoDB installation:
- Imports MongoDB's public GPG key.
- Adds MongoDB's Apt source.
- Installs MongoDB
- Node.js installation:
- Sets up NodeSource for Ubuntu.
- Installs NodeJS.
- Installs the following globally with
npm install -g
: