def configure(m2ee):
    samesite_cookie_workaround_enabled = _is_samesite_cookie_workaround_enabled(
        MXVersion(str(m2ee.config.get_runtime_version())))
    if samesite_cookie_workaround_enabled:
        logging.info("SameSite cookie workaround is enabled")

    output_path = os.path.abspath(CONFIG_FILE)
    template_path = os.path.abspath("{}.j2".format(CONFIG_FILE))

    with open(template_path, "r") as file_:
        template = Template(file_.read(), trim_blocks=True, lstrip_blocks=True)
    rendered = template.render(
        instadeploy_enabled=instadeploy.use_instadeploy(
            m2ee.config.get_runtime_version()),
        samesite_cookie_workaround_enabled=samesite_cookie_workaround_enabled,
        locations=get_access_restriction_locations(),
        default_headers=get_http_headers(),
        nginx_port=str(util.get_nginx_port()),
        runtime_port=str(util.get_runtime_port()),
        admin_port=str(util.get_admin_port()),
        deploy_port=str(util.get_deploy_port()),
        root=os.getcwd(),
    )

    logging.debug("Writing nginx configuration file...")
    with open(output_path, "w") as file_:
        file_.write(rendered)
    logging.debug("nginx configuration file written")

    generate_password_file({"MxAdmin": security.get_m2ee_password()})
    generate_password_file({"deploy": os.getenv("DEPLOY_PASSWORD")},
                           file_name_suffix="-mxbuild")
Example #2
0
def set_up_instadeploy_if_deploy_password_is_set(m2ee_client):
    if os.getenv("DEPLOY_PASSWORD"):
        mx_version = m2ee_client.config.get_runtime_version()
        if util.use_instadeploy(mx_version):

            def reload_callback():
                m2ee_client.client.request("reload_model")

            def restart_callback():
                global app_is_restarting
                app_is_restarting = True
                if not m2ee_client.stop():
                    m2ee_client.terminate()
                runtime.complete_start_procedure_safe_to_use_for_restart(m2ee)
                app_is_restarting = False

            thread = instadeploy.InstaDeployThread(
                util.get_deploy_port(),
                restart_callback,
                reload_callback,
                mx_version,
                runtime.get_java_version(mx_version),
            )
            thread.setDaemon(True)
            thread.start()

            if os.path.exists(os.path.expanduser("~/.sourcepush")):
                instadeploy.send_metadata_to_cloudportal()
        else:
            logging.warning(
                "Not setting up InstaDeploy because this mendix "
                "runtime version %s does not support it",
                mx_version,
            )
Example #3
0
def set_up_files(m2ee):
    lines = ""

    if util.use_instadeploy(m2ee.config.get_runtime_version()):
        mxbuild_upstream = "proxy_pass http://mendix_mxbuild"
    else:
        mxbuild_upstream = "return 501"
    with open("nginx/conf/nginx.conf") as fh:
        lines = "".join(fh.readlines())
    http_headers = parse_headers()
    lines = (
        lines.replace("CONFIG", get_path_config())
        .replace("NGINX_PORT", str(util.get_nginx_port()))
        .replace("RUNTIME_PORT", str(util.get_runtime_port()))
        .replace("ADMIN_PORT", str(util.get_admin_port()))
        .replace("DEPLOY_PORT", str(util.get_deploy_port()))
        .replace("ROOT", os.getcwd())
        .replace("HTTP_HEADERS", http_headers)
        .replace("MXBUILD_UPSTREAM", mxbuild_upstream)
    )
    for line in lines.split("\n"):
        logging.debug(line)
    with open("nginx/conf/nginx.conf", "w") as fh:
        fh.write(lines)

    gen_htpasswd({"MxAdmin": security.get_m2ee_password()})
    gen_htpasswd(
        {"deploy": os.getenv("DEPLOY_PASSWORD")}, file_name_suffix="-mxbuild"
    )
Example #4
0
def set_up_files(m2ee):
    lines = ""

    if instadeploy.use_instadeploy(m2ee.config.get_runtime_version()):
        mxbuild_upstream = "proxy_pass http://mendix_mxbuild"
    else:
        mxbuild_upstream = "return 501"
    with open("nginx/conf/nginx.conf") as fh:
        lines = "".join(fh.readlines())

    samesite_cookie_workaround_enabled = _is_samesite_cookie_workaround_enabled(
        MXVersion(str(m2ee.config.get_runtime_version())))

    if samesite_cookie_workaround_enabled:
        logging.info("SameSite cookie workaround is enabled")

    http_headers = parse_headers(samesite_cookie_workaround_enabled)
    lines = (lines.replace(
        "CONFIG", get_path_config(samesite_cookie_workaround_enabled)).replace(
            "NGINX_PORT", str(util.get_nginx_port())).replace(
                "RUNTIME_PORT", str(util.get_runtime_port())).replace(
                    "ADMIN_PORT", str(util.get_admin_port())).replace(
                        "DEPLOY_PORT", str(util.get_deploy_port())).replace(
                            "ROOT", os.getcwd()).replace(
                                "HTTP_HEADERS",
                                http_headers).replace("MXBUILD_UPSTREAM",
                                                      mxbuild_upstream))
    with open("nginx/conf/nginx.conf", "w") as fh:
        fh.write(lines)

    gen_htpasswd({"MxAdmin": security.get_m2ee_password()})
    gen_htpasswd({"deploy": os.getenv("DEPLOY_PASSWORD")},
                 file_name_suffix="-mxbuild")
Example #5
0
def set_up_instadeploy_if_deploy_password_is_set(reload_callback,
                                                 restart_callback, mx_version,
                                                 java_version):
    if os.getenv("DEPLOY_PASSWORD"):
        if use_instadeploy(mx_version):

            thread = InstaDeployThread(
                util.get_deploy_port(),
                restart_callback,
                reload_callback,
                mx_version,
                java_version,
            )
            thread.setDaemon(True)
            thread.start()

            if os.path.exists(os.path.expanduser("~/.sourcepush")):
                send_metadata_to_cloudportal()
        else:
            logging.warning(
                "Not setting up InstaDeploy because Mendix "
                "runtime version [%s] does not support it",
                mx_version,
            )