ARG APP_RELEASE=v1.3.1
FROM makeplane/plane-backend:${APP_RELEASE}

COPY brevo_email_backend.py /code/plane/utils/brevo_email_backend.py
COPY templates/emails/auth/forgot_password.html /code/templates/emails/auth/forgot_password.html
COPY templates/emails/auth/magic_signin.html /code/templates/emails/auth/magic_signin.html
COPY templates/emails/invitations/workspace_invitation.html /code/templates/emails/invitations/workspace_invitation.html
COPY plane/bgtasks/forgot_password_task.py /code/plane/bgtasks/forgot_password_task.py
COPY plane/bgtasks/magic_link_code_task.py /code/plane/bgtasks/magic_link_code_task.py
COPY plane/bgtasks/workspace_invitation_task.py /code/plane/bgtasks/workspace_invitation_task.py

RUN python - <<'PY'
from pathlib import Path

path = Path("/code/plane/settings/common.py")
text = path.read_text()
old = 'EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"'
new = 'EMAIL_BACKEND = os.environ.get("EMAIL_BACKEND", "django.core.mail.backends.smtp.EmailBackend")'
if old not in text and new not in text:
    raise SystemExit("EMAIL_BACKEND setting was not found")
path.write_text(text.replace(old, new))
PY
