I have an app that uses the private_pub gem (which uses faye) for sending notifications to users. The problem is that I'm trying to deploy using docker and docker-compose (since there's quite a few things needed such as solr searching and redis). As long as everything was running under localhost, everything was fine. But now my webserver is running in a docker container, as well as all other services. I've tried starting a container for faye, but then the publishing or subscribing doesn't work.
Here's my docker-compose file:
version: "2"
services:
web:
build: .
command: rails server -e development -p 3000 -b '0.0.0.0'
volumes:
- .:/app
ports:
- "3000:3000"
links:
- solr:solr
- mariadb
- redis
depends_on:
- solr
env_file:
- .env
solr:
image: solr
ports:
- "8983:8983"
volumes:
- data:/opt/solr/server/solr/mycores
entrypoint:
- docker-entrypoint.sh
- solr-precreate
- qwerteach
mariadb:
image: mariadb
volumes:
- mariadb:/var/lib/mysql
env_file:
- .env
ports:
- "13306:3306"
redis:
image: redis:latest
ports:
- "6379"
faye:
image: nickjj/faye
links:
- redis
ports:
- "9292:9292"
environment:
FAYE_PUSH_TOKEN: "secret"
FAYE_PORT: 9292
FAYE_MOUNT: "/faye"
FAYE_LOGGING: 1
volumes:
data:
mariadb:
And my private_pub.yml
development:
server: "http://faye:9292/faye"
secret_token: "secret"
test:
server: "http://localhost:9292/faye"
secret_token: "secret"
production:
server: "http://example.com/faye"
secret_token: "9eba1078bbb9289f949f51abc7ed5f842fed3af11374056bf09799e4ef2733f2"
signature_expiration: 3600 # one hour
With this configuration, from the "outside" (meaning a dumb terminal) I can contact faye:
curl -X POST http://localhost:9292/faye -H 'Content-Type: application/json' -d '{"channel": "/foo", "data": "Hello", "ext": {"pushToken": "secret"}}'
is successful
It also works from the docker web container, but with a different address:
curl -X POST http://faye:9292/faye -H 'Content-Type: application/json' -d '{"channel": "/foo", "data": "Hello", "ext": {"pushToken": "secret"}}'
However the private_pub.yml config file only allows one address... So either subscribing to channels works for clients but I can't publish from controllers, or I can publish from controllers but users can't subscribe. How can I solve this?
Any help would be appreciated! :-)
So, in case someone is trying to run private_pub in a dockerized rails app, here's how I got it running:
rackup private_pub.ru -s thin -E production -o 0.0.0.0
Explicitly telling thin to use host 0.0.0.0 is the key, that's how it'll be available from the outside on port 9292 (same as the rails container that's available on port 3000)The in the private_pub.yml, parameters are as follow:
production:
server: "http://production.server.ip:9292/faye"
secret_token: "this_is_a_very_secret_token"
Not sure it's the best way to do it, but it's the only way I could make it work ; And after 3 days of searching and too much coffee, I'm not going to ask for more.