[erlang-questions] Deploying multiple webapps

Loïc Hoguin essen@REDACTED
Wed Dec 16 01:21:09 CET 2015


Hello,

I have been working on RabbitMQ these past few months, and one of the 
tasks I got assigned was to switch the Web components from Webmachine to 
Cowboy.

RabbitMQ already had a way to have different services on different URLs 
running under the same port, as you describe. So my work was in part to 
make it work with Cowboy.

I didn't have to change much.

I made a tiny middleware that queries the RabbitMQ component keeping 
tracks of all the services, that then returns with the 'dispatch' 
environment variable added. This middleware runs just before the 
cowboy_router middleware: 
https://github.com/rabbitmq/rabbitmq-web-dispatch/blob/rabbitmq-management-63/src/rabbit_cowboy_middleware.erl#L27

The process keeping tracks of all services simply has a mapping from 
/service1/ to the service's dispatch list (/service1/ is added dynamically).

This works pretty well, is all on one node, one port, just like you 
need, and doesn't require much code. I suppose it wouldn't be too 
difficult to extract and make it its own project, if that's something 
people need.

Note that everything I talk about here has not been merged yet; but I'm 
getting close to completion (all tests pass, yada yada).

Cheers,

On 12/16/2015 12:41 AM, Hugo Mills wrote:
>     I've got a collection of small services, with minimal coupling
> between the back ends of those services (orchestration is done mostly
> client-side). I'd like to put an HTTPS interface in front of each one
> -- say, with cowboy.
>
>     What I'd also like to be able to do, at least in principle, is
> deploy some arbitrary subset of those services on each machine in my
> (comedically-named) server farm. I'd like to be able to do this with
> one TLS configuration, and preferably under a single port.
>
> i.e., access my services through
>
> https://server.me/service1/...
> https://server.me/service2/...
> https://server.me/service3/...
>
>     Now, in python-land, which is largely where I come from, I'd set up
> Apache with mod-wsgi, and deploy each WSGI app to a specific URL
> within the same URL namespace. I'm not quite sure how to do that
> easily with erlang+cowboy, because there seems to be no easy way of
> treating a webapp as a unit within a larger server configuration. I
> keep coming to one of two approaches:
>
> 1) Write each service completely independently (as HTTP), run it on a
>     distinct port, and splice together the URL namespaces through a
>     reverse proxy on a "normal" web server like Apache.
>
> 2) Find some way to automatically write a top-level router for cowboy,
>     for each set of services that I want to deploy to a machine.
>
>     I don't much like option 1, but I like option 2 even less. I guess
> I could write some kind of "top-level" app that, given a bunch of
> webapp modules (via a configuration file of some kind), gets a router
> for each module and transforms those routers into a single router
> config. Does such a thing already exist?
>
>     It all just feels a bit awkward, and I feel like I'm missing
> something. What do other people do to put together this kind of setup?
>
>     Hugo.
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>

-- 
Loïc Hoguin
http://ninenines.eu
Author of The Erlanger Playbook,
A book about software development using Erlang



More information about the erlang-questions mailing list