Docker 컨테이너에서 SMTP 설정하기

Helm 차트로 Discourse를 배포할 때

helm repo add bitnami https://charts.bitnami.com/bitnami
helm install my-release bitnami/discourse

이렇게 하면 의도한 대로 동작하지만, Docker 컨테이너 내에서 SMTP 이메일 구성을 수정할 수 없습니다.

이 문서의 내용을 재현하려고 시도해 보면, 컨테이너에 진입하여 다음 명령을 실행합니다.

cd /opt/bitnami/discourse/config

이 디렉터리에서 discourse.conf 파일을 찾을 수 있지만, 예를 들어 vi가 사용 가능하지 않다는 메시지가 표시되어 파일을 수정할 수 없습니다.

어떤 조치를 취할 수 있을지 조언해 주실 수 있을까요?

그들의 포럼에 질문할 수 있습니다. 다만 포럼이 닫혔습니다.

또는 표준 설치를 진행하고 여기서 도움을 받을 수 있습니다.

환경 변수를 설정할 수 있을지도 모릅니다. 예시를 참고해 보세요.

@pfaffman 님, 소중한 의견 주셔서 감사합니다.

이제 Bitnami helm chart에 환경 변수를 어떻게 전달해야 하는지 알게 되었습니다.

거래용 이메일을 위해 Sendinblue에서 제공하는 SMTP 자격 증명이 다음과 같을 때,

Discourse 컨테이너에 전달해야 하는 환경 변수가 어떤 형식인지 아시나요?

일반 Gmail 계정으로 메일을 보내려고 한다면, 이는 약관(TOS) 위반에 해당하며 작동하지 않습니다(여러 다른 이유도 있습니다).

SMTP 환경 변수의 예시는 다음 링크에서 확인하실 수 있습니다:

@pfaffman @Falco 님,

피드백 주셔서 감사합니다.

현재 제 환경 변수는 다음과 같이 설정되어 있습니다.

discourse:
  extraEnvVars:
    - name: DISCOURSE_SMTP_ADDRESS
      value: "smtp-relay.sendinblue.com"
    - name: DISCOURSE_SMTP_PORT
      value: "587"
    - name: DISCOURSE_NOTIFICATION_EMAIL
      value: "no-reply@my-domain.com"
    - name: DISCOURSE_SMTP_USER_NAME
      value: "my-email@googlemail.com"
    - name: DISCOURSE_SMTP_PASSWORD
      value: "my-pw"
    - name: DISCOURSE_SMTP_DOMAIN
      value: "my-domain.com"

이후 컨테이너가 정상적으로 시작되었습니다. 관리자 패널에서 제 Gmail 계정으로 테스트 이메일을 보내려고 시도했는데, 다음과 같은 결과가 나타났습니다:

아직까지 정상 작동하지 않습니다.

Discourse 컨테이너의 로그는 다음과 같습니다:

Processing by Admin::UsersController#show as JSON
  Parameters: {"id"=>"1"}
Completed 200 OK in 1978ms (Views: 0.6ms | ActiveRecord: 0.0ms | Allocations: 195416)
Started GET "/groups/search.json" for 10.0.0.50 at 2022-08-10 11:55:05 +0000
Processing by GroupsController#search as JSON
Completed 200 OK in 1189ms (Views: 0.5ms | ActiveRecord: 0.0ms | Allocations: 133325)
Started GET "/admin/email.json" for 10.0.0.50 at 2022-08-10 11:55:17 +0000
Processing by Admin::EmailController#index as JSON
Completed 200 OK in 23ms (Views: 1.2ms | ActiveRecord: 0.0ms | Allocations: 864)
Started POST "/admin/email/test" for 10.0.0.50 at 2022-08-10 11:55:20 +0000
Processing by Admin::EmailController#test as */*
  Parameters: {"email_address"=>"test@gmail.com"}
Completed 422 Unprocessable Entity in 20ms (Views: 1.1ms | ActiveRecord: 0.0ms | Allocations: 2037)
Started GET "/about.json" for 10.0.0.47 at 2022-08-10 11:55:46 +0000
Processing by AboutController#index as JSON
Completed 200 OK in 67ms (Views: 0.3ms | ActiveRecord: 0.0ms | Allocations: 9503)
Started GET "/site/basic-info.json" for 10.0.0.47 at 2022-08-10 11:55:46 +0000
Processing by SiteController#basic_info as JSON
Completed 200 OK in 254ms (Views: 0.5ms | ActiveRecord: 0.0ms | Allocations: 33103)
Started GET "/site/basic-info.json" for 10.0.0.47 at 2022-08-10 11:55:47 +0000
Processing by SiteController#basic_info as JSON
Completed 200 OK in 80ms (Views: 0.8ms | ActiveRecord: 0.0ms | Allocations: 4260)

다른 방법으로 시도해 볼 수 있는 부분이 있을까요?

실행 중인 컨테이너에 진입하여 다음을 실행할 수 있습니다.

message = TestMailer.send_test("test@gmail.com")
Email::Sender.new(message, :test_message).send

그리고 던져지는 예외를 검사하여 단서를 찾아보세요.

첫 번째 줄에서 받은 내용은 다음과 같습니다

bash: syntax error near unexpected token `('

아, 먼저 레일즈 콘솔에 진입해야 합니다. Discourse 디렉터리로 이동한 후 rails c를 입력하세요.

그렇게 하면 다음 결과가 나옵니다

root@discourse-69c7f5475c-h9qf5:/opt/bitnami/discourse# rails c
bash: rails: command not found
root@discourse-69c7f5475c-h9qf5:/opt/bitnami/discourse# ls
Brewfile         Gemfile.lock  adminjs  config.ru                  docs                 lefthook.yml  package.json             plugins  test            yarn.lock
CONTRIBUTING.md  LICENSE.txt   app      d                          images               lib           passenger.3000.pid.lock  public   tmp
COPYRIGHT.md     README.md     bin      db                         install-imagemagick  licenses      passenger.8080.pid       script   translator.yml
Gemfile          Rakefile      config   discourse.sublime-project  jsapp                log           passenger.8080.pid.lock  spec     vendor

음, 방금 이렇게 실행해 봤는데

RAILS_ENV=production bundle exec rails c

irb(main):002:0> message = TestMailer.send_test("test@gmail.com")
Traceback (most recent call last):
        2: from app/mailers/test_mailer.rb:7:in `send_test'
        1: from lib/email/build_email_helper.rb:8:in `build_email'
ArgumentError (:arguments expected to be an Array of individual string args)

또, 이거도 작동하지 않아요:

root@discourse-69c7f5475c-h9qf5:/opt/bitnami/discourse# RAILS_ENV=production bundle exec rails c message = TestMailer.send_test("test@gmail.com")
bash: syntax error near unexpected token `('

제가 뭔가 잘못하고 있는 건가요?

이상하네요, 제 설치 환경에서는 정상적으로 작동합니다:

[5] pry(main)> message = TestMailer.send_test("test@gmail.com")
  TranslationOverride Exists? (0.8ms)  SELECT 1 AS one FROM "translation_overrides" WHERE "translation_overrides"."locale" = 'en' AND "translation_overrides"."translation_key" = 'test_mailer.subject_template' LIMIT 1
   (0.2ms)  SELECT "translation_overrides"."translation_key", "translation_overrides"."value" FROM "translation_overrides" WHERE "translation_overrides"."locale" = 'en'
TestMailer#send_test: processed outbound mail in 259.9ms
=> #<Mail::Message:212740, Multipart: false, Headers: <From: "Discourse" <noreply@unconfigured.discourse.org>>, <Reply-To: "Discourse" <noreply@unconfigured.discourse.org>>, <To: test@gmail.com>, <Subject: [Discourse] Email Deliverability Test>, <Mime-Version: 1.0>, <Content-Type: text/plain>, <X-Auto-Response-Suppress: All>, <Auto-Submitted: auto-generated>>

Bitnami에서 패키징한 #unsupported-install을 사용하고 계시기 때문에, 미묘한 부분에서 오류가 나는 것은 예상되는 일입니다. 우리는 이러한 설치 환경에 대한 지원을 제공하지 않으므로, https://github.com/bitnami/charts/issues의 해당 지원 채널에 문의하시는 것이 좋습니다.

안녕하세요 @Falco, 다시 연락 주셔서 감사합니다.

'지원되지 않는 설치’라고 하신 게 무슨 뜻인가요? 더 잘 지원되는 설치 방식으로 진행하는 데는 문제가 없습니다. :slight_smile:

그렇다면 Helm 차트로 모든 작업을 수행할 수 있을까요?

아니요. 공식 설치 방식만 지원됩니다. Discourse가 부트스트래핑이 필요하지 않은 Docker 이미지를 자주 배포할 수 있을까요?를 참고하세요.

지난주에 한 사용자의 K8s 설치 작업을 도왔습니다. 그들의 도구를 사용하여 설치를 완료하는 데 저와 몇몇 유능한 엔지니어가 6시간 이상(저와 함께하지 않은 시간을 제외하면 10시간이었을 수도 있습니다)이 걸렸습니다.

helm chart에서 실행되도록 설계된 이미지를 만드는 것을 고려해 보았지만 아직 실행에 옮기지 못했습니다. 예산이 있다면 개인 메시지나 이메일로 연락 주시면 도움을 드릴 수 있을지 검토해 보겠습니다.