Skip to content

Instantly share code, notes, and snippets.

@raykao
Last active August 29, 2015 14:00
Show Gist options
  • Save raykao/11217326 to your computer and use it in GitHub Desktop.
Save raykao/11217326 to your computer and use it in GitHub Desktop.
#DevTO Appy Hour April 23rd 2014

DevTO Appy Hour April 23rd 2014

"VPS setup to Deploy in 30 Minutes Presentation Notes"

Presentation notes for #DevTO - Appy Hour #1 April 23rd 2014.

Contents

  1. Demo Steps
  2. Considerations
  3. Ubuntu Packages
  4. General Links
  5. Azure Links

Demo Steps:

  1. Create Virtual Machine in Azure Portal/Dashboard
  2. Open ports: 22 (ssh), 80 (http), 9418 (git)
  3. Write Node.js code locally (see file)
  4. Create local git repo
  5. git Add/Commit changes
  6. Install git-core on server
    • sudo apt-get install git-core
  7. Install node.js on server
    • sudo apt-get install build-essential
    • sudo apt-get install nodejs
    • sudo apt-get install npm
  8. Setup git server
    • create git user account
      • sudo adduser git
    • setup .ssh/authorized_keys
      • copy your local ~/.ssh/id_rsa.pub to server's ~/.ssh/authorized_keys file
  9. Create Upstart/init.d file
    • make exectuable e.g. sudo chmod +x /etc/init.d/appyHour
  10. Hack Sudoers group
    • user ALL = NOPASSWD: ALL
  11. Setup git hooks
    • pre-receive
    • post-receive
    • make executable e.g. chmod +x /home/raykao/git/appyhour.git/post-receive
  12. Setup git remote server config on local machine
    • git remote add origin master git@servername.com:~/path/to/repo.git
  13. Push local repo to server
    • git add .
    • git commit -m "initial commit"
    • git push origin master
  14. Show server is running
  15. Make Code Changes
  16. Push changes to server
  17. Show changes are live
  18. Profit

Considerations

  1. Install server firewall package (ufw - uncomplicated firewall)
  2. Install and configure Nginx as server proxy
  3. Make more secure - Sudoers hack is bad for business

Ubuntu Packages Used

  1. git-core
  2. nodejs

General Links

  1. Deploy Node.js website with git
  2. Hello Node - Node.js server examples
  3. Git - Git Hooks
  4. Git - Git on the Server - Setting Up the Server

Azure Links

  1. Node.js Developer Center

Credits

  1. Notes written by: Raymond Kao
  2. Presenters:
    • Marc Gagne - Getting to know Node.JS & Windows Azure PaaS
    • Raymond Kao - VPS setup to deploy in 30 minutes
#!/bin/sh
echo "Checkout the Files"
rm -rf /home/raykao/public_html/appyhour
git clone /home/raykao/git/appyhour.git /home/raykao/public_html/appyhour
echo "start service"
service appyHour start
#!/bin/sh
echo "Stop appyHour service"
service appyHour stop
// Modified From: http://howtonode.org/hello-node
// Load the http module to create an http server.
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});
// Listen on port 80 (default http port), IP defaults to 127.0.0.1
server.listen(80);
// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:80/");
#! /bin/sh
# /etc/init.d/appyHour
#
NAME=appyHour
APP=/home/raykao/public_html/appyhour/server.js
forever=/usr/local/bin/forever
export PATH=$PATH:/usr/local/bin/
LOG=/var/log/sampleNode.log
case "$1" in
start)
echo "Starting $NAME"
sudo HOSTNAME=appyhour1.cloudapp.net PORT=80 $forever --minUptime 5000 --sp$
;;
stop)
echo "Stopping script $NAME"
sudo $forever stop $APP
;;
list)
echo "List"
$forever list
;;
*)
echo "Usage: /etc/init.d/sampleNode {start|stop|list}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment