One droplet for staging and public environments?

July 11, 2015 1.7k views
DNS DigitalOcean Deployment MEAN IPv6 Node.js Git Ubuntu

Hello,

I'm using DigitalOceans One click MEAN install image and was wondering if I could set up my droplet in a way where I can deploy commits from my development branch to a staging folder/area on a server that is hooked up to staging.domain.com and at the same time have public/root area hooked up to domain.com that I deploy my master branch to. Is this achievable via one droplet?

1 Answer

Hello,

I'm afraid I don't fully understand the methods you use but I believe I understand the end goal; 2 setups on one droplet.

This should be doable, and this is how I would do it.

I would have the git repo cloned in 2 locations, my production path and dev path. Each would have their own branch, production branch and dev branch respectively. You can do it however you want.

Since I'm not quite sure how you are routing the traffic from your URL to the MEAN application, I'm making a bit of assumption going forward that you are using nginx to proxy it. You will also have to configure your dev and production sites to run on different ports. So we will assume the following:

  1. You are using the proxy_pass directive to pass nginx requests to your MEAN applications.
  2. Your production application is running on 127.0.0.1:8000 and your dev is running on 127.0.0.1:8001

If that's the case, then it's as simple as configuring your server blocks within nginx so that staging.domain.com points to 127.0.0.1:8000

This would not be a complete Server block, but has the parts you will likely be changing.

For the Dev Setup

server {
...
server_name staging.domain.com
proxy_pass http://127.0.0.1:8001
...
}

For the Production Setup

server {
...
server_name domain.com
proxy_pass http://127.0.0.1:8000
...
}

So long as your MEAN apps are running on the respective ports, this will proxy all information to the associated application. Then, when you make changes you can just pull the changes with git for the respective branch and it should update.

Have another answer? Share your knowledge.