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 multiple apps to the same server? #52

Closed
THPubs opened this issue Feb 3, 2016 · 32 comments
Closed

How to deploy multiple apps to the same server? #52

THPubs opened this issue Feb 3, 2016 · 32 comments

Comments

@THPubs
Copy link
Contributor

THPubs commented Feb 3, 2016

Using the old mup we were able to deploy multiple apps binding to different ports and use nginx to manage them. How can we do it with this one?

@madushan1000
Copy link
Contributor

You can assign a custom port for meteor app by adding a port field under meteor config. We are planning to add Nginx proxy suppot built in to mup but It'll take some time.

@dufia
Copy link

dufia commented Feb 5, 2016

Hey Madushan!

I've just found out, that if you specify a custom port you will get some errors on 'Verifying Deployment' although the apps seems to be deployed 100% right on the specified port. Maybe its still looking for the app on 80 or something? Have a good day!

env: {
  PORT: 3000,
  ROOT_URL: 'http://myapp.com',
  MONGO_URL: 'mongodb://localhost/meteor'
}


Started TaskList: Start Meteor
[172.62.43.119] - Start Meteor
[172.62.43.119] - Start Meteor: SUCCESS
[172.62.43.119] - Verifying Deployment
[172.62.43.119] x Verifying Deployment: FAILED

  -----------------------------------STDERR-----------------------------------
  a

  > fibers@1.0.5 install /bundle/bundle/programs/server/node_modules/fibers
  > node ./build.js

  `linux-x64-v8-3.14` exists; testing
  Binary is fine; exiting
  ansi-regex@0.2.1 node_modules/ansi-regex

  ansi-styles@1.1.0 node_modules/ansi-styles

  escape-string-regexp@1.0.3 node_modules/escape-string-regexp

  chalk@0.5.1 node_modules/chalk

  has-ansi@0.1.0 node_modules/has-ansi

  supports-color@0.2.0 node_modules/supports-color

  strip-ansi@0.3.0 node_modules/strip-ansi

  eachline@2.3.3 node_modules/eachline

  type-of@2.0.1 node_modules/type-of

  amdefine@1.0.0 node_modules/amdefine

  asap@2.0.3 node_modules/asap

  underscore@1.5.2 node_modules/underscore

  meteor-promise@0.5.0 node_modules/meteor-promise

  promise@7.0.4 node_modules/promise

  source-map-support@0.3.2 node_modules/source-map-support

  semver@4.1.0 node_modules/semver

  source-map@0.1.32 node_modules/source-map

  fibers@1.0.5 node_modules/fibers
  => Starting meteor app on port:80
  startup server

  => Redeploying previous version of the app

  -----------------------------------STDOUT-----------------------------------

  To see more logs type 'mup logs --tail=50'

  ----------------------------------------------------------------------------
Error: 
-----------------------------------STDERR-----------------------------------
a

> fibers@1.0.5 install /bundle/bundle/programs/server/node_modules/fibers
> node ./build.js

`linux-x64-v8-3.14` exists; testing
Binary is fine; exiting
ansi-regex@0.2.1 node_modules/ansi-regex

ansi-styles@1.1.0 node_modules/ansi-styles

escape-string-regexp@1.0.3 node_modules/escape-string-regexp

chalk@0.5.1 node_modules/chalk

has-ansi@0.1.0 node_modules/has-ansi

supports-color@0.2.0 node_modules/supports-color

strip-ansi@0.3.0 node_modules/strip-ansi

eachline@2.3.3 node_modules/eachline

type-of@2.0.1 node_modules/type-of

amdefine@1.0.0 node_modules/amdefine

asap@2.0.3 node_modules/asap

underscore@1.5.2 node_modules/underscore

meteor-promise@0.5.0 node_modules/meteor-promise

promise@7.0.4 node_modules/promise

source-map-support@0.3.2 node_modules/source-map-support

semver@4.1.0 node_modules/semver

source-map@0.1.32 node_modules/source-map

fibers@1.0.5 node_modules/fibers
=> Starting meteor app on port:80
startup server

=> Redeploying previous version of the app

-----------------------------------STDOUT-----------------------------------

To see more logs type 'mup logs --tail=50'

----------------------------------------------------------------------------
    at /development/node/nauka/meteor/meteor-up/node_modules/nodemiral/lib/coreTasks.js:39:16
    at /development/node/nauka/meteor/meteor-up/node_modules/nodemiral/lib/session.js:146:9
    at Channel.<anonymous> (/development/node/nauka/meteor/meteor-up/node_modules/nodemiral/lib/ssh.js:125:9)
    at Channel.emit (events.js:107:17)
    at SSH2Stream.<anonymous> (/development/node/nauka/meteor/meteor-up/node_modules/nodemiral/node_modules/ssh2/lib/Channel.js:124:14)
    at SSH2Stream.g (events.js:199:16)
    at SSH2Stream.emit (events.js:104:17)
    at parsePacket (/development/node/nauka/meteor/meteor-up/node_modules/nodemiral/node_modules/ssh2/node_modules/ssh2-streams/lib/ssh.js:3435:10)
    at SSH2Stream._transform (/development/node/nauka/meteor/meteor-up/node_modules/nodemiral/node_modules/ssh2/node_modules/ssh2-streams/lib/ssh.js:552:13)
    at SSH2Stream.Transform._read [as __read] (_stream_transform.js:179:10)
    at SSH2Stream._read (/development/node/nauka/meteor/meteor-up/node_modules/nodemiral/node_modules/ssh2/node_modules/ssh2-streams/lib/ssh.js:213:15)
    at SSH2Stream.Transform._write (_stream_transform.js:167:12)
    at doWrite (_stream_writable.js:301:12)
    at writeOrBuffer (_stream_writable.js:288:5)
    at SSH2Stream.Writable.write (_stream_writable.js:217:11)
    at Socket.ondata (_stream_readable.js:540:20)

@madushan1000
Copy link
Contributor

It should check for the correct port, Can try adding a deployCheckWaitTime field under meteor config for me? See this comment #38 (comment)

@dufia
Copy link

dufia commented Feb 5, 2016

I did it, it took a little longer but still ended up with the same errors. The newest build of the app is running fine on :3000 anyway, my mup.js:

module.exports = {
  servers: {
    one: {
      "host": "123.32.12.123",
      "username": "root",
      //"password": "password"
      // or pem file (ssh based authentication)
      "pem": "/Users/konradmoskal/.ssh/id_rsa"
    },
  },

  meteor: {
    name: 'myapp',
    path: '/development/node/nauka/meteor/mmameta-client/app',
    servers: {
      one: {},
    },
    env: {
      PORT: 3000,
      ROOT_URL: 'http://myapp.com',
      MONGO_URL: 'mongodb://localhost/27016'
    },
    deployCheckWaitTime: 90,
  },


  mongo: {
    oplog: true,
    port: 27016,
    servers: {
      one: {},
    },
  }
};

@THPubs
Copy link
Contributor Author

THPubs commented Feb 9, 2016

@dufia @madushan1000 Thanks it worked! But even though the app is deployed and working, I get the same error dufia gets.

Another small question... when deploying two apps, is it going to use the same mongo container? When I deployed the second app I think it removed the existing mongo container and created a new one!

@dufia
Copy link

dufia commented Feb 9, 2016

@THPubs

when deploying two apps, is it going to use the same mongo container?

Here it gets tricky, you don't really have control over MongoDB when using MUP. I have a Backbone app that uses MongoDB and I would like my Meteor app to share the same DB. Still, I would like to use MUP cause its good software.

Its seems easy to DO, but it isn't. MUP claims to support MongoDB outside of MUP, but fails badly. I tried current MUP, current MUPX and the newest MUP (under development). Neither of them supported MongoDB outside of MUP (or Docker), errors everywhere. Try it yourself. I am waiting for the newest stable of MUP.

@madushan1000
Copy link
Contributor

@THPubs @dufia I'll take a look at it and try to figure out what's causing it. BTW We do not advice to use MongoDB setup comes with mup. It's only intended for testing or aery small apps. For a production app, we recommend setting up a MongoDB replicaset on different hosts or somewhere like compose.io and set MONGO_URL in meteor.env.

@THPubs
Copy link
Contributor Author

THPubs commented Feb 10, 2016

@madushan1000 Actually this is for a small app. It does give issues if I remove the mongo from the mup.js and just leave the url for the existing one...

mongo: {
  oplog: true,
  port: 27027,
  servers: {
    one: {},
  },
},

I was trying to connect two apps to a single db.

@dufia
Copy link

dufia commented Feb 10, 2016

same here +1

@THPubs
Copy link
Contributor Author

THPubs commented Feb 10, 2016

@dufia :-(

Hope we can get a solution soon. The old mup didn't work well with meteor 1.3... Tomorrow I have to launch an app. :-)

@madushan1000
Copy link
Contributor

I'm not recommending this in a production environment, but you can set up mongo in the first meteor deployment and remove all of the mongo config and just set the meteor.env.MONGO_URL to mongodb://localhost/yourdbname in the second app.
Can you post the error if this setup is giving any errors?

@THPubs
Copy link
Contributor Author

THPubs commented Feb 11, 2016

Thanks I tried that but then faced with a 502 bad gateway error when visit the site. Here's the mup logs :

    [188.166.243.100]/bundle/bundle/programs/server/node_modules/fibers/future.js:300
    [188.166.243.100]                       throw(ex);
    [188.166.243.100]                             ^
    [188.166.243.100]Error: failed to connect to [localhost:27017]
    [188.166.243.100]    at Object.Future.wait (/bundle/bundle/programs/server/node_modules/fibers/future.js:420:15)
    [188.166.243.100]    at new MongoConnection (packages/mongo/mongo_driver.js:213:27)
    [188.166.243.100]    at new MongoInternals.RemoteCollectionDriver (packages/mongo/remote_collection_driver.js:4:16)
    [188.166.243.100]    at Object.<anonymous> (packages/mongo/remote_collection_driver.js:38:10)
    [188.166.243.100]    at Object.defaultRemoteCollectionDriver (packages/underscore/underscore.js:750:1)
    [188.166.243.100]    at new Mongo.Collection (packages/mongo/collection.js:102:40)
    [188.166.243.100]    at Package (packages/cfs_tempstore/packages/cfs_tempstore.js:39:1)
    [188.166.243.100]    at Package (packages/cfs_tempstore/packages/cfs_tempstore.js:394:1)
    [188.166.243.100]    at packages/cfs_tempstore/packages/cfs_tempstore.js:394:1
    [188.166.243.100]    at packages/cfs_tempstore/packages/cfs_tempstore.js:394:1
    [188.166.243.100]    - - - - -
    [188.166.243.100]    at [object Object].<anonymous> (/bundle/bundle/programs/server/npm/npm-mongo/node_modules/mongodb/lib/mongodb/connection/server.js:556:74)
    [188.166.243.100]    at [object Object].emit (events.js:106:17)
    [188.166.243.100]    at [object Object].<anonymous> (/bundle/bundle/programs/server/npm/npm-mongo/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:156:15)
    [188.166.243.100]    at [object Object].emit (events.js:98:17)
    [188.166.243.100]    at Socket.<anonymous> (/bundle/bundle/programs/server/npm/npm-mongo/node_modules/mongodb/lib/mongodb/connection/connection.js:534:10)
    [188.166.243.100]    at Socket.emit (events.js:95:17)
    [188.166.243.100]    at net.js:441:14
    [188.166.243.100]    at process._tickCallback (node.js:448:13)
    [188.166.243.100]npm WARN deprecated This version of npm lacks support for important features,
    [188.166.243.100]npm WARN deprecated such as scoped packages, offered by the primary npm
    [188.166.243.100]npm WARN deprecated registry. Consider upgrading to at least npm@2, if not the
    [188.166.243.100]npm WARN deprecated latest stable version. To upgrade to npm@2, run:
    [188.166.243.100]npm WARN deprecated 
    [188.166.243.100]npm WARN deprecated   npm -g install npm@latest-2
    [188.166.243.100]npm WARN deprecated 
    [188.166.243.100]npm WARN deprecated To upgrade to the latest stable version, run:
    [188.166.243.100]npm WARN deprecated 
    [188.166.243.100]npm WARN deprecated   npm -g install npm@latest
    [188.166.243.100]npm WARN deprecated 
    [188.166.243.100]npm WARN deprecated (Depending on how Node.js was installed on your system, you
    [188.166.243.100]npm WARN deprecated may need to prefix the preceding commands with `sudo`, or if
    [188.166.243.100]npm WARN deprecated on Windows, run them from an Administrator prompt.)
    [188.166.243.100]npm WARN deprecated 
    [188.166.243.100]npm WARN deprecated If you're running the version of npm bundled with
    [188.166.243.100]npm WARN deprecated Node.js 0.10 LTS, be aware that the next version of 0.10 LTS
    [188.166.243.100]npm WARN deprecated will be bundled with a version of npm@2, which has some small
    [188.166.243.100]npm WARN deprecated backwards-incompatible changes made to `npm run-script` and
    [188.166.243.100]npm WARN deprecated semver behavior.
    [188.166.243.100]npm WARN package.json meteor-dev-bundle@0.0.0 No description
    [188.166.243.100]npm WARN package.json meteor-dev-bundle@0.0.0 No repository field.
    [188.166.243.100]npm WARN package.json meteor-dev-bundle@0.0.0 No README data
    [188.166.243.100]=> Starting meteor app on port:80
    [188.166.243.100]
    [188.166.243.100]/bundle/bundle/programs/server/node_modules/fibers/future.js:300
    [188.166.243.100]                       throw(ex);
    [188.166.243.100]                             ^
    [188.166.243.100]Error: failed to connect to [localhost:27017]
    [188.166.243.100]    at Object.Future.wait (/bundle/bundle/programs/server/node_modules/fibers/future.js:420:15)
    [188.166.243.100]    at new MongoConnection (packages/mongo/mongo_driver.js:213:27)
    [188.166.243.100]    at new MongoInternals.RemoteCollectionDriver (packages/mongo/remote_collection_driver.js:4:16)
    [188.166.243.100]    at Object.<anonymous> (packages/mongo/remote_collection_driver.js:38:10)
    [188.166.243.100]    at Object.defaultRemoteCollectionDriver (packages/underscore/underscore.js:750:1)
    [188.166.243.100]    at new Mongo.Collection (packages/mongo/collection.js:102:40)
    [188.166.243.100]    at Package (packages/cfs_tempstore/packages/cfs_tempstore.js:39:1)
    [188.166.243.100]    at Package (packages/cfs_tempstore/packages/cfs_tempstore.js:394:1)
    [188.166.243.100]    at packages/cfs_tempstore/packages/cfs_tempstore.js:394:1
    [188.166.243.100]    at packages/cfs_tempstore/packages/cfs_tempstore.js:394:1
    [188.166.243.100]    - - - - -
    [188.166.243.100]    at [object Object].<anonymous> (/bundle/bundle/programs/server/npm/npm-mongo/node_modules/mongodb/lib/mongodb/connection/server.js:556:74)
    [188.166.243.100]    at [object Object].emit (events.js:106:17)
    [188.166.243.100]    at [object Object].<anonymous> (/bundle/bundle/programs/server/npm/npm-mongo/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:156:15)
    [188.166.243.100]    at [object Object].emit (events.js:98:17)
    [188.166.243.100]    at Socket.<anonymous> (/bundle/bundle/programs/server/npm/npm-mongo/node_modules/mongodb/lib/mongodb/connection/connection.js:534:10)
    [188.166.243.100]    at Socket.emit (events.js:95:17)
    [188.166.243.100]    at net.js:441:14
    [188.166.243.100]    at process._tickCallback (node.js:448:13)

It looks like it's failing to connect to the mongo database. I then removed mongo from both the mups and installed mongo locally and let the apps connect to it. Still not working. The app will only connect to it's own mongo docker container (Also we can't change the port of that mongo container. It use the default one).

@THPubs
Copy link
Contributor Author

THPubs commented Feb 11, 2016

Actually I have no other choice... The old mup didn't work. Might be because im using meteor 1.3?

@madushan1000
Copy link
Contributor

Old mup should work. Actually, we are not doing anything meteor version specific inside mup. We just use meteor build command with platform specific flags.

The method I posted above should not work actually. We use docker link internally to link mongo container to meteord container. There are some things you can do listed here.
But this means you have to alter options to meteor docker container.
Since this is not a priority for us(most users use external dbs) I'll take some time to implement.
But if someone can send a PR with proper testing, We can accept it.

PS: I found the problem with failing deployment verification(I was not taking the meteor port from proper place). I'll add a fix soon.

@THPubs
Copy link
Contributor Author

THPubs commented Feb 11, 2016

Ah thanks :-) I will give another look at the old mup :-)

@dufia
Copy link

dufia commented Feb 11, 2016

@THPubs

I tried to connect two apps to the same database (localhost:27017) with all versions of MUP: Old, MUPX, current. MUPX has the same issues like the current (under development). I think it is because it is inside Docker and you are unable to access localhost. I don't know if it is a feature or a bug, it just doesn't work. #828

@madushan1000

That being said (MUP is unable to access database via localhost:27017), do you think it would work if database was accessed via servers ip address instead? Like http://128.34.32.349:27017

@madushan1000
Copy link
Contributor

@dufia Yeah, The mongo setup comes with mup is not meant to be used in production, Let alone two app sharing it(never host your web app and db in the same place, If one goes down, there is a high probability the other will too)

To answer your other question, You would be able to access it trough a public IP(or if you are in a private LAN, private IP) if you configure your firewall to expose the MongoDB port to outside (This is a bad idea, since mup's MongoDB installation doesn't setup any authentication at all, the whole world will be able to access it)

@dufia
Copy link

dufia commented Feb 11, 2016

@madushan1000 @THPubs

Thanks. Now everything is clear, you can easily connect multiple apps to the same database, just not via localhost. You have to allow Mongo to be remotely accessed and use servers IP address. I know, it might be silly for back-end expert but for me it wasn't.

@madushan1000
Copy link
Contributor

Yeah, This is because the way docker works. Unless you've linked your mongo container to meteor container, When you refer as localhost, you actually mean docker containers local address. not the docker host's one. BTW even if you want to use a mongo instance on localhost, set it up separately with a username and password and then set MONGO_URL. mup's one is insecure.

@nizulzaim
Copy link

Sorry, if i have two apps, should i set different port for mongo? because i want to make sure two apps are different from others. For example. first app is
mongo: { oplog: true, port: 27017, servers: { one: {}, }, },

and the second app is:

mongo: { oplog: true, port: 27018, servers: { one: {}, }, },

Or I just set it as same port but it actually work different from other app. Sorry, i dont quite understand this part. I use nginx to proxy my application. First app is in port 3000 and second app is port 3002. Although they are in same server, but i dont want it to share same mongo. From what @THPubs said before, it will overwrite the mongo if i create new container

Another small question... when deploying two apps, is it going to use the same mongo container? When I deployed the second app I think it removed the existing mongo container and created a new one!

@madushan1000
Copy link
Contributor

Yes, The mongo installation mup setup is just a basic one. It's not meant to be used in production at all. Setup your own mongo and use MONG_URL env var instead.

@nizulzaim
Copy link

Thank you.. You have simple answer but i can understand and it meant alot

@nizulzaim
Copy link

i tried to enable remote access. Then, new mongo url should look like

MONGO_URL: 'mongodb://1.2.3.4/bongkahDevsign'

or

MONGO_URL: 'mongodb://1.2.3.4:27017/bongkahDevsign'

or

MONGO_URL: 'http://1.2.3.4:27017/bongkahDevsign'

or

MONGO_URL: 'http://1.2.3.4/bongkahDevsign'
?

@madushan1000
Copy link
Contributor

both of the mongodb:// ones are okay.

@nizulzaim
Copy link

But when i run DEBUG=* mup deploy, here is the output after Pushing Meteor Application Bundle :
Error write ECONNRESET.

when i run `netstat -a' on server, i think it show that my mongodb have already enable remote access.

tcp 0 0 devsign1:27017 *:* LISTEN

Updated:

This problem not show when i run DEBUG=* mup setup. So, the problem is actually when trying to connect to mongodb i think.

@madushan1000
Copy link
Contributor

That error has nothing to do with mongo. It's mup saying it can't connect to your server. I'm not sure why.

@nizulzaim
Copy link

i dont know, But after DEBUG=* reconfig, and deployCheckWaitTime: 120, the problem solved. Thank you. Sorry for asking too many question.

@madushan1000
Copy link
Contributor

I'm not exactly sure why, Can you post you mup.js file here(remove any passwords and stuff)? I'll take a look.

@nizulzaim
Copy link

`module.exports = {
servers: {
one: {
host: '1.2.3.4',
username: 'root',
pem: './.mykey',
},
},

meteor: {
    name: 'bongkahDevsign',
    path: '../',
    servers: {
        one: {},
    },
    env: {
        PORT: 3002,
        ROOT_URL: 'http://server.com',
        MONGO_URL: 'mongodb://1.2.3.4:27017/bongkahDevsign'
    },
    deployCheckWaitTime: 120,
},

};`

Here is my mup.js.

@cyclops24
Copy link

@madushan1000 I have a same issue. I deployed application called A and now want to deploy other application called B that use A database. Which configuration needs for do this in MUP?
I done this with older MUP later but newest MUP can't do this.
Is this feature added to new MUP? (I asked because you close this issue)

@Sphinxxxx
Copy link
Contributor

For the record: Deploying multiple apps to the same server, giving each app separate databases on localhost seems to work just fine. The mup.js files need to have the same mongo configuration:

my-app-111:

module.exports = {
  servers: {
    one: {
      ...
    }
  },

  meteor: {
    name: 'my-app-111',
    path: '../',
    docker: {
      image: 'abernix/meteord:base',
    },
    servers: {
      one: {}
    },
    buildOptions: {
      serverOnly: true,
    },
    env: {
      PORT: 8080,
      ROOT_URL: 'http://app111.mydomain.com',
      MONGO_URL: 'mongodb://localhost/meteor'
    },
    deployCheckWaitTime: 240
  },

  mongo: {
    oplog: true,
    port: 27017,
    servers: {
      one: {},
    },
  },
};

my-app-222:

module.exports = {
  servers: {
    one: {
      ...,
    }
  },

  meteor: {
    name: 'my-app-222',
    path: '../',
    docker: {
      image: 'abernix/meteord:base',
    },
    servers: {
      one: {}
    },
    buildOptions: {
      serverOnly: true,
    },
    env: {
      PORT: 8081,
      ROOT_URL: 'http://app222.mydomain.com',
      MONGO_URL: 'mongodb://localhost/meteor'
    },
    deployCheckWaitTime: 240
  },

  mongo: {
    oplog: true,
    port: 27017,
    servers: {
      one: {},
    },
  },
};

When I access the MongoDB shell on the server (docker exec -it mongodb mongo my-app-111), the databases lie side by side on the same mongo container(?):

> show dbs
admin             0.000GB
local             0.000GB
my-app-111        0.000GB
my-app-222        0.000GB

@micktaiwan
Copy link

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

7 participants