示例#1
0
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")
示例#2
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"
    )
示例#3
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")
示例#4
0
def set_up_m2ee_client(vcap_data):
    client = m2ee_class(
        yamlfiles=[".local/m2ee.yaml"],
        load_default_files=False,
        config={
            "m2ee": {
                # this is named admin_pass, but it's the verification http header
                # to communicate with the internal management port of the runtime
                "admin_pass": security.get_m2ee_password()
            }
        },
    )

    version = client.config.get_runtime_version()

    mendix_runtimes_path = "/usr/local/share/mendix-runtimes.git"
    mendix_runtime_version_path = os.path.join(os.getcwd(), "runtimes",
                                               str(version))
    if os.path.isdir(mendix_runtimes_path
                     ) and not os.path.isdir(mendix_runtime_version_path):
        util.mkdir_p(mendix_runtime_version_path)
        env = dict(os.environ)
        env["GIT_WORK_TREE"] = mendix_runtime_version_path

        # checkout the runtime version
        process = subprocess.Popen(
            ["git", "checkout", str(version), "-f"],
            cwd=mendix_runtimes_path,
            env=env,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        process.communicate()
        if process.returncode != 0:
            logging.info("Mendix %s is not available in the rootfs", version)
            logging.info("Fallback (1): trying to fetch Mendix %s using git",
                         version)
            process = subprocess.Popen(
                [
                    "git",
                    "fetch",
                    "origin",
                    "refs/tags/{0}:refs/tags/{0}".format(str(version)),
                    "&&",
                    "git",
                    "checkout",
                    str(version),
                    "-f",
                ],
                cwd=mendix_runtimes_path,
                env=env,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
            )
            process.communicate()
            if process.returncode != 0:
                logging.info(
                    "Unable to fetch Mendix {} using git".format(version))
                url = util.get_blobstore_url("/runtime/mendix-%s.tar.gz" %
                                             str(version))
                logging.info(
                    "Fallback (2): downloading Mendix {} from {}".format(
                        version, url))
                util.download_and_unpack(url,
                                         os.path.join(os.getcwd(), "runtimes"))

        client.reload_config()
    runtime.set_runtime_config(
        client.config._model_metadata,
        client.config._conf["mxruntime"],
        vcap_data,
        client,
    )
    java_version = runtime.get_java_version(
        client.config.get_runtime_version())["version"]
    java.update_config(client.config._conf["m2ee"], vcap_data, java_version)
    runtime.set_jetty_config(client)
    newrelic.update_config(client, vcap_data["application_name"])
    appdynamics.update_config(client, vcap_data["application_name"])
    runtime.set_application_name(client, vcap_data["application_name"])
    telegraf.update_config(client, vcap_data["application_name"])
    datadog.update_config(client)
    return client