From 75a737b21f2d298ceba33fb7a3fcf072c4d4f886 Mon Sep 17 00:00:00 2001 From: Nick Shvelidze Date: Tue, 6 Oct 2015 11:26:52 +0400 Subject: [PATCH 1/4] Add Deploy to Heroku button --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4be8238c9..00c87874e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ BrowserQuest [![Build Status](https://travis-ci.org/browserquest/BrowserQuest.png)](https://travis-ci.org/browserquest/BrowserQuest) [![Dependency Status](https://gemnasium.com/browserquest/BrowserQuest.png)](https://gemnasium.com/browserquest/BrowserQuest) +[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) + [BrowserQuest](http://browserquest-teambq.rhcloud.com:8000) is a HTML5/JavaScript multiplayer game experiment. It has three major parts: From 8a6d00f1921d26af7c1a44d6841e8340e4a4ba09 Mon Sep 17 00:00:00 2001 From: Nick Shvelidze Date: Tue, 6 Oct 2015 11:35:08 +0400 Subject: [PATCH 2/4] Create app.json for Heroku --- app.json | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 app.json diff --git a/app.json b/app.json new file mode 100644 index 000000000..24d2e9b24 --- /dev/null +++ b/app.json @@ -0,0 +1,21 @@ +{ + "name": "BrowserQuest", + "description": "HTML5/JavaScript multiplayer game experiment", + "website": "https://github.com/shvelo/BrowserQuest", + "success_url": "/", + "addons": ["heroku-redis:hobby-dev"], + "env": { + "HEROKU": "true", + "HEROKU_REDIS_HOST": { + "description": "Redis hostname" + }, + "HEROKU_REDIS_PORT": { + "description": "Redis port" + }, + "HEROKU_REDIS_PASSWORD": { + "description": "Redis password" + } + }, + "scripts": { + } +} From 8aec4d4c332a594f54cc4540e1c10456e6ff985f Mon Sep 17 00:00:00 2001 From: Nick Shvelidze Date: Tue, 6 Oct 2015 11:38:04 +0400 Subject: [PATCH 3/4] Update app.json --- app.json | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/app.json b/app.json index 24d2e9b24..0ee8aff55 100644 --- a/app.json +++ b/app.json @@ -5,16 +5,7 @@ "success_url": "/", "addons": ["heroku-redis:hobby-dev"], "env": { - "HEROKU": "true", - "HEROKU_REDIS_HOST": { - "description": "Redis hostname" - }, - "HEROKU_REDIS_PORT": { - "description": "Redis port" - }, - "HEROKU_REDIS_PASSWORD": { - "description": "Redis password" - } + "HEROKU": "true" }, "scripts": { } From 5774601563455101f976f32a8af97bac174d8fa8 Mon Sep 17 00:00:00 2001 From: Nick Shvelidze Date: Tue, 6 Oct 2015 11:58:22 +0400 Subject: [PATCH 4/4] Revamp Heroku support and add support for Redis URLs --- README.md | 30 +++++++++++----------------- server/config.json | 3 +-- server/js/db_providers/redis.js | 8 ++++++-- server/production_hosts/heroku.js | 4 +--- server/production_hosts/openshift.js | 7 ++++--- 5 files changed, 24 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 00c87874e..b5efed9d5 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Then install the Node.js dependencies by running: $ npm config set registry http://registry.npmjs.org/ $ npm install -d - + Before starting the BrowserQuest server, you must start Redis. In Windows, you can simply run `redis-server.exe` in your `redis\bin\release` directory. Then start the server by running: @@ -178,11 +178,11 @@ Currently, BrowserQuest can run on the following PAAS (Platform as a Service) pr $ git remote add github https://github.com/browserquest/BrowserQuest.git $ git fetch github $ git reset --hard github/master - + 5. Copy the BrowserQuest config file with the following command: $ cp server/config.json server/config_local.json - + 6. Open `server/config_local.json` in a text editor such as Gedit (Linux), TextEdit (OS X), or Vim. On the line that reads `"production": "heroku",`, change `"heroku"` to `"openshift"`. @@ -203,7 +203,7 @@ Congratulations! You have now deployed BrowserQuest to Openshift! You can see th Visit the url shown by the above command to see BrowserQuest running. You will need to add ":8000" to the end. Use the url below as a guide: http://your_openshift_browserquest_url.rhcloud.com:8000/ - + ### Instructions for Heroku ### 1. Install the Heroku toolbelt from [here](https://toolbelt.herokuapp.com/). @@ -211,35 +211,29 @@ Visit the url shown by the above command to see BrowserQuest running. You will n 2. Create a new application by running the following command: $ heroku create [NAME] - + Where [NAME] is an optional name for your application (Heroku will automatically create one otherwise). -3. Sign up for a Redis provider, such as [Redis To Go](https://redistogo.com), or host a Redis instance yourself. +3. Add heroku-redis add-on: + + heroku addons:create heroku-redis:hobby-dev 4. Run the following commands to allow BrowserQuest to run on Heroku: $ heroku config:add HEROKU=true - $ heroku config:add HEROKU_REDIS_HOST=[REDIS_HOST] - $ heroku config:add HEROKU_REDIS_PORT=[REDIS_PORT] - $ heroku config:add HEROKU_REDIS_PASSWORD=[REDIS_PASSWORD] - -Where [REDIS_HOST], [REDIS_PORT], and [REDIS_PASSOWRD] are your Redis hostname, port, and password, respectively. -If you Redis instance is configued without a password, omit the last command. -Note: If you use RedisToGo, you will be provided with a URL that looks something like this: + If you need to use a different Redis provider than `heroku-redis`, set a `REDIS_URL`: - redis://redistogo:12345678901234567890@something.redistogo.com:9023/ - -In this case, your REDIS_HOST is `something.redistogo.com`, your REDIS_PORT is `9023`, and your REDIS_PASSWORD is `12345678901234567890`. + $ heroku config:add REDIS_URL=[REDIS_URL] 5. Deploy to Heroku by running the following command: $ git push heroku master - + 6. Enable the Heroku WebSockets lab (needed for communication between the browser and the BrowserQuest server) with the following command: $ heroku labs:enable websockets - + Congratulations! You have now deployed BrowserQuest to Heroku! To open BrowserQuest in your browser, run `heroku open`. diff --git a/server/config.json b/server/config.json index d9daa897a..5f61ea40e 100644 --- a/server/config.json +++ b/server/config.json @@ -6,8 +6,7 @@ "map_filepath": "./server/maps/world_server.json", "metrics_enabled": false, "use_one_port": true, - "redis_port": 6379, - "redis_host": "127.0.0.1", + "redis_url": "redis://127.0.0.1:6379", "memcached_host": "127.0.0.1", "memcached_port": 11211, "game_servers": [{"server": "localhost", "name": "localhost"}], diff --git a/server/js/db_providers/redis.js b/server/js/db_providers/redis.js index 348858683..a9e81b931 100644 --- a/server/js/db_providers/redis.js +++ b/server/js/db_providers/redis.js @@ -8,8 +8,12 @@ var cls = require("../lib/class"), module.exports = DatabaseHandler = cls.Class.extend({ init: function(config){ - client = redis.createClient(config.redis_port, config.redis_host, {socket_nodelay: true}); - client.auth(config.redis_password || ""); + if(config.redis_url) { + client = redis.createClient(config.redis_url, {socket_nodelay: true}); + } else { + client = redis.createClient(config.redis_port, config.redis_host, {socket_nodelay: true}); + client.auth(config.redis_password || ""); + } }, loadPlayer: function(player){ var self = this; diff --git a/server/production_hosts/heroku.js b/server/production_hosts/heroku.js index 49b4ee40e..c2faf7db8 100644 --- a/server/production_hosts/heroku.js +++ b/server/production_hosts/heroku.js @@ -1,9 +1,7 @@ var config = {} config.port = process.env.PORT; -config.redis_port = process.env.HEROKU_REDIS_PORT -config.redis_host = process.env.HEROKU_REDIS_HOST -config.redis_password = process.env.HEROKU_REDIS_PASSWORD +config.redis_url = process.env.REDIS_URL config.isActive = function() { return process.env.HEROKU !== undefined; diff --git a/server/production_hosts/openshift.js b/server/production_hosts/openshift.js index b566d8d71..69e4d3f56 100644 --- a/server/production_hosts/openshift.js +++ b/server/production_hosts/openshift.js @@ -3,9 +3,10 @@ var config = {} config.ip = process.env.OPENSHIFT_NODEJS_IP; config.port = process.env.OPENSHIFT_NODEJS_PORT; -config.redis_port = process.env.OPENSHIFT_REDIS_PORT || process.env.OPENSHIFT_REDIS_DB_PORT -config.redis_host = process.env.OPENSHIFT_REDIS_HOST || process.env.OPENSHIFT_REDIS_DB_HOST -config.redis_password = process.env.REDIS_PASSWORD +config.redis_url = false; +config.redis_port = process.env.OPENSHIFT_REDIS_PORT || process.env.OPENSHIFT_REDIS_DB_PORT; +config.redis_host = process.env.OPENSHIFT_REDIS_HOST || process.env.OPENSHIFT_REDIS_DB_HOST; +config.redis_password = process.env.REDIS_PASSWORD; config.isActive = function() { return process.env.OPENSHIFT_NODEJS_IP !== undefined;