Need advice in making a new rails app with discourse as one of the two components


(Helloravi) #1

The application I plan to build has two components

1)Discourse forum
2)an exam conducting piece of software with a question bank.

Both of them will be on the same domain. Both of them would be sharing the same login system.

My first thought is to clone discourse and develop the rest of the application inside discourse. I need advice on this.
a)Do I need to keep them as separate rails applications? Can I make single large rails application? What should be my considerations if I can do it both ways?
b)I have a little experience in developing a few rails projects already. I only deployed 5 projects on Heroku so far. How would you recommend me hosting this? I know that discourse supports only docker installations.

I spent a couple of hours to install discourse locally on my Ubuntu system.


(Jens Maier) #2

Quite simply: don’t. Discourse is a huge process and has at least four fulltime-developers plus a large community constantly making changes. If you fork Discourse and integrate your own app, you will be incompatible with upstream in a matter of weeks or spending all your time trying to keep your features compatible with the latest upstream changes.

Instead, you can:

  • Develop your app as a Discourse plugin. Plugins can mount Rails engines into Discourse to route requests to custom controllers, you can override Discourse’s handlebars templates and you can inject custom JavaScript assets implementing new Ember views.

  • Deploy your custom app on a subdomain and use SSO to bind to Discourse’s user database. Other than shared users, the two apps will be totally separate. However, both can run on the same machine if you strip Discourse’s default nginx from the container, install it on the Docker host and use it as a frontend for both.

  • Deploy your app on the same domain. This is hacky to the extreme. Basically, abuse nginx to route requests to either your app or Discourse based on filename matches: /t/... to Discourse, /exam/... to your app, /c/... to Discourse, and so on and so forth. Did I mention that this is really hacky and will probably lead to tears whenever Discourse gains new routes?


(Kane York) #3

Your scientists were so obsessed with whether or not they could that they didn’t stop to consider whether or not they should!


You can do almost anything with a computer. The primary questions are the price tag and the clock.


(Helloravi) #4

@elbert Thank you very much for the reply. I was expecting that it is a bad idea to modify discourse after looking at the source file of the discourse :smile:

I would mostly have the custom app on the domain, discourse on a sub domain and use SSO.

Can you please elaborate on this? I have only heard of docker before. I read about it now after you gave your reply.

Also, I am wondering if it is possible to deploy both parts of the app on heroku and later shift to Digital ocean if necessary? or is it necessary to go with a docker+dokku setup and start working with Digital Ocean directly?


(Jens Maier) #5

There’s not much to elaborate on, really. Follow the usual installation instructions, but base your configuration on the web_only sample instead of the standalone configuration. Look at the templates for PostgreSQL, Redis and nginx, then install these servers manually on your server, replicating Discourse’s configuration as required.
Configure your web_only container to connect to the host’s database server and expose Unicorn on a local port, then configure your nginx to proxy requests for forum.example.com to Discourse’s Unicorn as required (again, based on the nginx sample config).

You can now deploy your own Rails application on the host. Amend nginx’s configuration to proxy requests for example.com to your app and have it store its data in separate PostgreSQL and Redis databases, and that should be it.

Deploying Discourse on Heroku is generally not a good idea. Discourse requires at least two processes to run at any given time (one web worker and one Sidekiq) and that alone means that hosting Discourse on Heroku will be more expensive than a 2GB VM at Digital Ocean.


(Helloravi) #6

@elberet Firstly thanks for all the help so far.

I forgot to mention that I also will be having a Wordpress blog in the same domain in digital ocean. To summarize, I will be having discourse, a rails app and wordpress blog. Can I strip out nginx from discourse container and set up the three applications in three different containers on the same machine?

Also, if price were not an issue would you suggest heroku?

I am really new to Digial ocean and dev ops(heroku doesn’t really have any dev ops). Thank you for helping me out.


(Jens Maier) #7

Sure, can’t see why that wouldn’t work. As long as you have a webserver running directly on the host that can decide which container to route requests to, you should be fine.

Regarding Heroku, I don’t have sufficient experience with the service they provide. Personally, however, I’d prefer having SSH access.