Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to deploy the server manually? #12

Open
ramsestom opened this issue Aug 10, 2015 · 8 comments
Open

How to deploy the server manually? #12

ramsestom opened this issue Aug 10, 2015 · 8 comments

Comments

@ramsestom
Copy link

What are the steps I should follow manually deploy the server?
The instructions in here: http://playtomic.org/server.html are only for an Heroku installation and I want to put it on openshift...
So once I have downloaded and copied the git source on my openshift application, what am I supposed to do? Is there any config file I must change or something?

@benlowry
Copy link
Member

Hi ramsestom, to deploy it manually you need to set up the dependencies:

  • nodejs
  • mongodb

You'll need to create a database and user account in mongodb, and create credentials for your game just like the instructions here: http://playtomic.org/games.html except in your own mongodb database.

You will need an ENV var that contains your mongodb connection string:
export playtomic=mongodb://..........

And then it's just a nodejs project you can start via:
node web.js

You may also set up mailchimp's ENV vars for newsletters, you can see the expected variables here:
https://github.com/playtomic/apiserver/blob/master/api/config.js

@ramsestom
Copy link
Author

Thanks for your reply.
But I think I aslo need to change the node.js port in the web.js script (process.env.PORT does not exists on openshift so I guess it must be replaced by process.env.OPENSHIFT_NODEJS_PORT). Correct me if I am wrong.
I don't know if I need to define the server_ip_address (process.env.OPENSHIFT_NODEJS_IP) somewhere too...?
As for the mongodb connection, I think I will modify it in the config.js file rather than putting it in an env variable...
To start the server, I defined : "main": "web.js" in package.json so it should be OK
I don't know if I need to make any other change...

Also, I guess I can delete the .c9 and .idea directories so as the Procfile and mongod file (that seems to be requiered for c9.io, Heroku or idea hosts deployment only. No?)
Bytheway, If I wanted to deploy to c9.io rather than openshift, do you know wich would be the procedure? Is there any tutorail somewhere (as there is a .c9 directory and a mongod file, I guess someone already tested to deploy it on c9.io. So did he wrote some helpfile with the necessary steps? )

@benlowry
Copy link
Member

You can change the port by providing a PORT var or changing the default here:
https://github.com/playtomic/apiserver/blob/master/web.js#L53

Those files should be deletable - c9 is from the web IDE, .idea is from IntelliJ I think, the Procfile is for starting the server on Heroku, and the mongod file is for starting mongodb on C9 (that was me).

@ramsestom
Copy link
Author

Well it do not work
I think it as to do to the fact that, additionaly to the specific port, the application has to be bind to the IP address defined in process.env.OPENSHIFT_NODEJS_IP in order to recieve traffic from the routing layer (but I do not see anywhere to define it in the playtomic code. Only the Port can be changed, mot the IP...).
I tried to change https://github.com/playtomic/apiserver/blob/master/web.js#L55 by
var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.PORT || 3000;
var ipaddress = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
app.listen(port, ipaddress, function() {
but it do not fixed the problem. The application is still not able to connect

EDIT: I made some test with the openshift node.js sample application and if, in its package.json file, I change
"express": "~3.4.4",
for
"express": "^4.10.4", (like in the playtomic package.json file)
the application is not able to establish connection anymore...
So I really don't know what is going on... The issue seems linked to the express version defined in package.json even though, if I define "express": "~3.4.4", in the playtomic package.json, the application still do not connect (whereas it does if I use server.js witch is the openshift default nodejs sample rather than web.js).

EDIT2: looking at the nodejs.log, here is the error I get:

var app = express.createServer();
^
TypeError: Object function createApplication() {
var app = function(req, res, next) {
app.handle(req, res, next);
};
mixin(app, proto);
mixin(app, EventEmitter.prototype);
app.request = { proto: req, app: app };
app.response = { proto: res, app: app };
app.init();
return app;
} has no method 'createServer'
at Object. (/var/lib/openshift/55c8d09489f5cf855100006b/app-root/runtime/repo/web.js:8:9)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:929:3
DEBUG: Program node web.js exited with code 8
DEBUG: Starting child process with 'node web.js'

@benlowry
Copy link
Member

You might have more luck now, there was a pending pull request that added support for a module (express) that had obsoleted some parts of their API.

I have also prepared instructions for deploying to DigitalOcean:

create ubuntu droplet and ssh into server

dependencies

$ sudo apt-get update && sudo apt-get install -y nodejs npm mongodb git
$ ln -s /usr/bin/nodejs /usr/bin/node

copy api server and install its dependencies

$ git clone https://github.com/playtomic/apiserver.git
$ cd apiserver
$ npm install

setup mongodb

$ mongo
use playtomic
db.addUser(‘playtomic’, ‘playtomic’)
exit

setup config

echo PORT=3000 > start
echo playtomic=mongodb://playtomic:[email protected]:27017/playtomic >> start
echo node web.js >> start

start server

bash start

@ramsestom
Copy link
Author

Yes seems to work now (the application build successfully on Openshift. Not tried to interact with it yet though). Thanks

And just for information. You have twice the same process.env.MONGOLAB_URI test in your config.js file now. So you can delete one ;)

EDIT: for the publickey and privatekey does it need to be ssh keys or can I put any string as private/public keys? I really don't understand why there is a public and a private key as both needs to be provided both in the database and in the public applications that would connect through api (usually if you have a public/private key pair, the private key is supposed to remain private and would not be provided to the public applications (i.e. games that would connect to your server) and the public key do not need to be provided to the private server either (he only needs the private key to decipher messages encoded with public keys))

@benlowry
Copy link
Member

The keys date back to when playtomic was a commercial service, the public key was used to isolate each game to separate subdomains on the api server while the private key was the actual credential.

They definitely shouldn't be ssh keys, you can use any value you want for them.

@Lucidarme
Copy link

Hello, I try to set up Playtomic on my own server too. I followed your tutorial and when I run bash start, I have the following errors:

{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
(node) sys is deprecated. Use util instead.
Listening on 3000, env: undefined, local: false

And then the server is listening, but when I try to connect a player, I always have the error 1, which is:

Unable to login: General error, this typically means the player is unable to connect to the server

I have searched for the error about module bson, and some people said to update mongoose. I tried to do that but it doesn't change anything. Have you an idea to resolve this error? Or perhaps I am wrong and this error is not important, and the problem comes to my authentication ?
Thanks for help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants