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

Opened port 25 in container to docker host (for SMTP) #2095

Merged
merged 1 commit into from
Apr 6, 2018

Conversation

namangupta01
Copy link
Member

Closes #2065

@PublicLabBot
Copy link

3 Messages
📖 @namangupta01 Thank you for your pull request! I’m here to help with some tips and recommendations. Please take a look at the list provided and help us review and accept your contribution! And don’t be discouraged if you see errors – we’re here to help.
📖 Your pull request is on the master branch. Please make a separate feature branch) with a descriptive name like new-blog-design while making PRs in the future.
📖 This pull request doesn’t link to a issue number. Please refer to the issue it fixes (if any) in the body of your PR, in the format: Fixes #123.

Generated by 🚫 Danger

@icarito
Copy link
Member

icarito commented Jan 25, 2018

I was researching this and I think this could be a part of the solution.
In order to work in production I'd need to alias smtp to localhost.
Then in order to work in staging, we'd need to figure out a way to bind smtp hostname to the docker host. Some documentation on it here https://stackoverflow.com/questions/17770902/forward-host-port-to-docker-container .

Summarizing @jywarren it's a good idea but requires:
[ ] - smtp alias in production
[ ] - smtp alias dockerhost in docker-compose.yml file
[ ] - configure host exim to listen on docker virtual network (currently only listens to localhost).

@namangupta01
Copy link
Member Author

@icarito so the problem is that :
We have a docker container for staging and we have another docker container where we have smtp server setup so all we want to do here is to access one docker container port from another docker container?

@icarito
Copy link
Member

icarito commented Jan 31, 2018

@namangupta01 sorry, no. We do not have another container doing smtp.
In staging, the app is running in a container. The docker host is listening for SMTP on localhost.
In production, the app is running directly on the server (not yet in a container). The same server is listening for SMTP on localhost.

So we want to access the appropriate SMTP host in each instance.

This might become simpler once we have containers in production.

From the plan above, the one thing that needs to be done here is to somehow see if we can setup docker-compose.yml for the app to reach the docker host smtp service in staging, without breaking production.

Copy link
Member

@icarito icarito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this would break production and doesn't by itself address the problem. Could we change smtp for localhost? This should work in production and is a step in the right direction because we will need to use SMTP in staging to fix the actual issue as well.
@jywarren this would change the default mail settings - perhaps it would be in order to leave a comment on how to setup sendmail instead?

@namangupta01
Copy link
Member Author

@icarito I was researching over this issue, i want to know one thing where are you defining your smtp settings? In rails config files or in linux files?

@icarito
Copy link
Member

icarito commented Feb 1, 2018

Currently since plots2 runs locally in production, it relies on sendmail command, if I understood the configuration. But the host itself is listening to SMTP on localhost, so it should be safe to switch from sendmail to SMTP.

@namangupta01
Copy link
Member Author

namangupta01 commented Feb 1, 2018

I think directly writing the smtp setting in config files should work everywhere:
Like this:
config.action_mailer.smtp_settings = { address: 'smtp.gmail.com', port: 587, domain: 'gmail.com', user_name: 'xyz@gmail.com', password: 'yourpassword', authentication: :plain, enable_starttls_auto: true } what do you say?

@icarito
Copy link
Member

icarito commented Feb 1, 2018

Yeah - a sensible default would be localhost:25 which is standard SMTP.

I think having the other options as comments would be great so they are easy to figure out.

@namangupta01
Copy link
Member Author

I think using above configuration has nothing to do with whether it is running in container or directly.
And i think action_mailer.smtp_settings manages itself for standard SMTP but i'm not sure.

@namangupta01
Copy link
Member Author

I have been using these settings in my projects and everything working fine for me https://github.com/namangupta01/MCQ/blob/master/config/environments/development.rb#L44

@icarito
Copy link
Member

icarito commented Feb 1, 2018

I don't know what you mean with manages itself :-)
The issue at hand is providing a mechanism for staging (docker-compose up -d) to send mail, without breaking production.
Thanks for trying to resolve it!

@jywarren
Copy link
Member

jywarren commented Feb 2, 2018

What's the next step for this, do you think? Perhaps we should consider an approach that sets up a "fallback" mailing system that would be overridden by the production setup, but would silently accept mail (but not send it) from staging. What might that look like?

@jywarren
Copy link
Member

jywarren commented Mar 3, 2018

Hi @icarito if you have some time to think about how this could work, we're hoping to test out #2257 based on fixing mail in staging; currently it doesn't let us test that out. What do you think? Thanks!

@icarito
Copy link
Member

icarito commented Mar 3, 2018 via email

@jywarren
Copy link
Member

jywarren commented Mar 9, 2018

OK, so should we first create a separate docker-compose-production.yml in Git?

Thanks!

@jywarren
Copy link
Member

@icarito - do we have to start version tracking docker-compose-production.yml then? Thanks!

@icarito
Copy link
Member

icarito commented Mar 14, 2018 via email

@jywarren
Copy link
Member

jywarren commented Mar 14, 2018 via email

@jywarren
Copy link
Member

Trying this in #2495 -- let's see if that passes! @icarito if it does, please go ahead and merge it so we can test in staging. Thanks!

@icarito
Copy link
Member

icarito commented Apr 3, 2018

Apologies I thought this would be simpler. The problem is that with containers SMTP won't be 127.0.0.1 unless we do some tricks that make everything more complex. See moby/moby#1143 for a discussion on this specific issue.
The simplest solution is to containerize the SMTP service.

@jywarren jywarren merged commit 7d3951a into publiclab:master Apr 6, 2018
@jywarren
Copy link
Member

jywarren commented Apr 6, 2018

Great work! Thank you!!! 👍

SrinandanPai pushed a commit to SrinandanPai/plots2 that referenced this pull request May 5, 2019
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

Successfully merging this pull request may close these issues.

4 participants