To automate this process reference: automation of app deployment.
- Open VirtualBox and Git Bash terminal and set folder destination for Virtual Machine (VM) using the change directory command
cd
in the terminal to the appropriate directory containing your 'Vagrantfile' and 'provision.sh' files (see automation_nginx_deployment.md and nginx_deployment.md to get these files if you do not already have them) and the extracted 'app' and 'environment' folders provided by the developers. - Open and add a line in 'Vagrantfile'
config.vm.synced_folder "app", "/home/vagrant/app"
to put/sync 'app' folder from local machine to VM. Save. 'Vagrantfile' should have same code/similar to code block below:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.network "private_network", ip:"192.168.10.100"
config.vm.provision "shell", path: "provision.sh"
config.vm.synced_folder "app", "/home/vagrant/app"
end
vagrant up
in terminal to create and start running the VM.vagrant ssh
in terminal to enter the VM.- In your VM environment enter:
sudo apt-get install python-software-properties -y
in order to access the correct/needed version of nodejs as this installs the 'python-software-properties' package. Allow it to complete. The following image should be the output:
- Next enter:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
, which changes source to look for nodejs to one from specific url internet. It should output the following:
- Next installs correct version of nodejs by entering:
sudo apt-get install nodejs -y
. Following should be output:
- Next install pm2 and make it available globally (to all on VM) by entering:
sudo npm install pm2 -g
. (Note: PM2 is a process manager for JavaScript runtime).
- Navigate into the 'app' directory in your VM by using the
cd
command.
- Next install npm by entering:
npm install
. (Note: npm (node package manager) is package manager for JavaScript in this case nodejs)
- Now we can run our app by either entering:
npm start
ornode app.js
. This should return "Your app is ready and listening on port 3000" as a foreground process as shown in the image below:
- Now we can go to our web browser and enter '192.168.10.100:3000' into our url bar to show nodejs app that we ran. It should show the following:
Additional notes:
curl
is a tool to transfer data from a server (in this case to download a script from the provided url)
-s
flag tells a process/tool to run silently.
-L
flag tells the tool/process to follow redirects.
sudo
gives extra privileges when running a command.
-E
flag tells sudo
to preserve the current user's environment variables while running the command.
|
pipes into another command (in this case bash
, which is the command interpreter that executes script)