liminspace / django-mjml

The simplest way to use MJML in Django templates.
MIT License
262 stars 32 forks source link

MJML compiler in TCP mode failing in CI on bitbucket #119

Closed bramski closed 3 years ago

bramski commented 3 years ago

I'm having some issues getting our CI builds to pass using MJML-django in TCP mode as the renderer. It was working and then quite consistently when we started rendering more emails they started failing:

RuntimeError: MJML compile error (via MJML TCP server): no working server
Number of servers: 1
Timeouts: 0

I'm a bit baffled by the error. It appears that there are working servers but the compilation step is failing immediately.

Bitbucket YAML looks as follows for docker config:

image: python:3.6-jessie

definitions:
  services:
    mysql:
      image: mysql:5.7
      environment:
        MYSQL_DATABASE: pipelines
        MYSQL_ROOT_PASSWORD: *********
    redis:
      image: redis
    mjml:
      image: liminspace/mjml-tcpserver:0.10.2
      environment:
        HOST: "0.0.0.0"
        PORT: "28102"
      expose:
          - "28102"
      ports:
          - "28102:28102"
liminspace commented 3 years ago

@bramski could you show your MJML_* django settings?

bramski commented 3 years ago
MJML_BACKEND_MODE = env('MJML_BACKEND_MODE', default='cmd')
MJML_TCP_SERVERS = [
    ('127.0.0.1', 28102),
]

In the case of our CI environment MJML_BACKEND_MODE becomes tcpserver.

liminspace commented 3 years ago

try to use mjml instead of 127.0.0.1 in your django settings

bramski commented 3 years ago

Hmmm, all the other configured servers for CI use localhost as the hostname. I wasn't aware of the bitbucket docker container setting up local domain names but I'll give it a shot. i.e. REDIS_CACHE_URL="redis://localhost:6379/zo-enterprise-test" is how I have redis configured for CI on bitbucket pipelines.

liminspace commented 3 years ago

and also try to use the default port settings of mjml-tcpserver:

  mjml:
    image: liminspace/mjml-tcpserver:0.10.2

and

MJML_TCP_SERVERS = [
    ('mjml', 28101),
]

note that when you run CI in your configuration case it can use global ports to run services and if you run them more than one or one of them wasn't stopped correctly, you can have an issue with conflicts. just add docker-compose logs in your CI script to see output and to be sure that all services were started before you run your target scripts.

bramski commented 3 years ago

Yeah this is coming up for me in the wild as well on our dev & staging systems.

bramski commented 3 years ago

This is still not working. I had to change to command mode in CI which is far slower. Please reopen.

On Fri., Jan. 1, 2021, 9:27 a.m. Igor Melnyk, notifications@github.com wrote:

Closed #119 https://github.com/liminspace/django-mjml/issues/119.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/liminspace/django-mjml/issues/119#event-4161106029, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADG7FMMODMR6WBLHQ7XGDTSXYAYHANCNFSM4USJKKBA .

liminspace commented 3 years ago

provide all info to reproduce the issue locally and after that I'll try to fix that. currently I don't see any problem neither python library nor docker image. they are working on various projects quite stable and well (including gitlab-ci to run functional and unit tests)

bramski commented 3 years ago

Please leave it open I will be able to deal with this after holidays thanks.

On Fri., Jan. 1, 2021, 10:41 a.m. Igor Melnyk, notifications@github.com wrote:

provide all info to reproduce the issue locally and after that I'll try to fix that. currently I don't see any problem neither python library nor docker image. they are working on various projects quite stable and well (including gitlab-ci to run functional and unit tests)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/liminspace/django-mjml/issues/119#issuecomment-753363652, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADG7FP5G5PCVR6DQLXNUITSXYJOTANCNFSM4USJKKBA .

bramski commented 3 years ago

Had a chance to investigate this further. There seem to be some bugs in bitbucket's docker work. I changed to port 28101 and then updated the definition for the MJML docker container to be much more plain:

    mjml:
      image: liminspace/mjml-tcpserver:0.10.2

That managed to make the ports work correctly. Not sure why "expose" and "ports" were causing this to fail so randomly.