Skip to content

Latest commit

 

History

History
75 lines (43 loc) · 3.81 KB

app_deployment.md

File metadata and controls

75 lines (43 loc) · 3.81 KB

Deploy Application with Nginx on Virtual Machine using Vagrant

To automate this process reference: automation of app deployment.

  1. 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.
  2. 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
  1. vagrant up in terminal to create and start running the VM.
  2. vagrant ssh in terminal to enter the VM.
  3. 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:

Python Properties

Python Properties fin

  1. 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:

curl1

curl2

  1. Next installs correct version of nodejs by entering: sudo apt-get install nodejs -y. Following should be output:

nodejs install 1

  1. 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).

pm2 install 1

pm2 install 5

  1. Navigate into the 'app' directory in your VM by using the cd command.

navigate

  1. Next install npm by entering: npm install. (Note: npm (node package manager) is package manager for JavaScript in this case nodejs)

npm install

  1. Now we can run our app by either entering: npm start or node app.js. This should return "Your app is ready and listening on port 3000" as a foreground process as shown in the image below:

Launch

  1. 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:

Running web server app

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)