I seem to work in tangent directions. I’ll get bored and start on a new ‘I think I can do that’. I’ll do some stuff, then either get bored with it or refine the initial concept. Since I live in a low-tech area (Gadsden Alabama), I rely on my former co-workers the give me feedback on my latest tangent. I can pretty much tell if the tangent if worthless by that feedback. Nothing is totally worthless - sometimes a technique (kludge!) has promises, maybe in another area.

To get that feedback, I’d usually publish the demo on a Rails development application binded to some port on 0.0.0.0 (rails s -p 8765 - b 0.0.0.0). I’d open the port on my router and forward it to my laptop. While that works, it opened up my laptop to port scanners and then, if I was getting some non-techie to look at it, they’d get confused: Why I was asking them to go to http://mydomain.us:8765. If I got serious about the tangent I’d deploy the application to a staging server (Linux or my MacMini). Of course I’d have to remember how to deploy the application.

A recent tangent was a Bingo Controller Rails application. As proof of concept, I loaded up a RaspberryPI with rails and ran it on the PI. It actually ran quite well, but I was still opening up ports. I then remembered that I used Nginx on the MacMini to act as a front-end to a staging server. If I got more serious on the tangent, I’d put it on a VPS. So all this post is going to do is remind me how I did this and maybe someone else can adopt the technique. Over the years I’ve set up all kinds of tools to support me, but I seen to forget why and how I did it. Even in the RaspberryPI tangent I set up just used file copies to move the application to the PI. That was pretty stupid in that I had set up a Git repository server do handle my Real applications. How I set up my git server is forgotten, if you google ‘ set up git server’ there are numerous ways and I may have to change mine. Think I had set it up using git protocol, but I really just use ssh.

The basic set up is:

  • A Rails development environment (my laptop). Set up with all the usuals (rbenv). Tangents usually start with a basic scaffold application with my standards (slim, maybe SimpleForms, jQuery and Foundation)

  • A Git Repository. I used the Gist Setting up a Remote Repository and Doing Initial Push to remember what I did. I assume that your router port forwards 22 and 443 to a server. I could have used GitHub, but I don’t have a private account and don’t want to put what may be crap on my public account.

  • A domain that points to your router

Setup remote repository:

  ssh git@example.com
  mkdir my_project.git
  cd my_project.git
  git init --bare

On local machine:

  cd my_project
  git init
  git add *
  git commit -m "Initial commit"
  git remote add origin example.com:my_project.git
  git push -u origin master
  • Nginx running someplace on your network. Again, assuming your router is port forwarding port 80 to this machine. But then you can use another port if whoever you’re asking to look at the demo can understand :port on a URL.

That’s it

I’ll step through the Bingo Controller application life cycle to give a little more detail. Bingo started as a single table application.

The Games
create_table "games", force: :cascade do |t|
  t.string "status"
  t.string "calls"
  t.string "pattern"
  t.datetime "created_at", null: false
  t.datetime "updated_at", null: false
  t.string "game_status"
  t.index ["status"], name: "index_games_on_status"
end
The Model
class Game < ApplicationRecord
  serialize :calls, Array
  GameStatus = %w(current bingo won)
end

I later added a User model and Pattern model but the content of the application is not needed, it just has a controller that Adds (or controls) calls and a display that shows the current status of the game. The initial application will be developed and tested on my laptop.

When I decide I want to publish the Demo

  • Create the git repository and push the application to the repository (see above)

  • ssh into where I’m going to run the demo and get it running (assuming ssh keys set up)

  ssh user@demo.local # or user@10.0.1.x
  cd apps
  git clone developer@example.com:/Users/developer/repo/bingo.git bingo
  cd bingo
  bundle exec bundle 
  # could have version problems. Might have to also do a migration of copy over a development.db
  rails s -p 8765 - b 0.0.0.0  #get rails running
  # use browser to see if it is up (http://10.0.1.x:8765)
  • ssh into your web server (where port 80 goes to)
  ssh developer@example.com # or user@10.0.1.x
  # cd to your nginx config directory (example homebrew on a mac)
  cd /usr/local/etc/nginx/sites-enabled
  • create a nginx file in sites-enabled to handle the demo. I setup nginx to respond to subdomain with proxy forward to machine on local network
server {
    server_name bingo.example.com;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://10.0.1.x:8765;
    }
}

Use browser to see if you can get to http://bingo.example.com

You be done!

Now don’t do like I first did, make changes on the demo instead of the laptop and try to figure out how to merge them. Just use git.

  • Something needs fixed or added.
  • make changes and git commit
  • ssh to the demo machine and the demo app
  • git pull

Your’ve made the changes