def configure_riot_nginx5(root="/var/www/riot", **kwargs): kwargs.setdefault("LISTEN_PORT", 80) server_block = utils.merge_into( emit.server_block( server_name=kwargs["SERVER_NAME"], listen=kwargs["LISTEN_PORT"] ), emit.html5_block("/", root), ) sio = StringIO() sio.write( dumps( loads(emit.redirect_block(server_name=kwargs["SERVER_NAME"], port=80)) + server_block if kwargs["LISTEN_PORT"] == 443 else server_block ) ) put( sio, "/etc/nginx/sites-enabled/{server_name}".format( server_name=kwargs["SERVER_NAME"] ), use_sudo=True, ) return restart_systemd("nginx")
def test_proxy_add(self): output0 = upsert_ssl_cert_to_443_block( upsert_redirect_to_443_block(self.one_root, self.server_name), self.server_name, self.ssl_certificate, self.ssl_certificate_key, ) output1 = merge_into(self.server_name, output0, self.parsed_api_block) for i in range(5): self.parsed_api_block[0][1][5][1] += str(i) output1 = merge_into(self.server_name, output1, self.parsed_api_block) output1_s = dumps(output1) self.assertEqual(output1_s.count(self.location), 1) for term in ( self.proxy_pass, self.server_name, "443", self.ssl_certificate, self.ssl_certificate_key, "proxy_pass http://127.0.0.1:5020/awesome01234;", ): self.assertIn(term, output1_s)
def configure_nginx2(*args, **kwargs): kwargs.setdefault("LISTEN_PORT", 80) nginx.install_nginx0() nginx.setup_nginx_init1() if kwargs.get("self_signed", False): certificate.self_signed0(use_sudo=True, **kwargs) server_block = utils.merge_into( ( lambda server_block: utils.apply_attributes( server_block, emit.secure_attr(kwargs["SSL_CERTOUT"], kwargs["SSL_KEYOUT"]), ) if kwargs["LISTEN_PORT"] == 443 else server_block )( emit.server_block( server_name=kwargs["MATRIX_SERVER_NAME"], listen=kwargs["LISTEN_PORT"] ) ), emit.api_proxy_block("/_matrix", "https://127.0.0.1:8008"), ) sio = StringIO() sio.write( dumps( loads( emit.redirect_block(server_name=kwargs["MATRIX_SERVER_NAME"], port=80) ) + server_block if kwargs["LISTEN_PORT"] == 443 else server_block ) ) put( sio, "/etc/nginx/sites-enabled/{matrix_server_name}".format( matrix_server_name=kwargs["MATRIX_SERVER_NAME"] ), use_sudo=True, ) return restart_systemd("nginx")
def configure_nginx3(*args, **kwargs): nginx.install_nginx0() nginx.setup_nginx_init1() if kwargs.get("self_signed"): self_signed0(use_sudo=True, **kwargs) server_block = utils.merge_into( ( lambda server_block: utils.apply_attributes( server_block, emit.secure_attr(kwargs["SSL_CERTOUT"], kwargs["SSL_KEYOUT"]), ) if kwargs["LISTEN_PORT"] == 443 else server_block )( emit.server_block( server_name=kwargs["SERVER_NAME"], listen=kwargs["LISTEN_PORT"] ) ), emit.api_proxy_block("/go", "https://localhost:8154"), ) sio = StringIO() sio.write( dumps( loads(emit.redirect_block(server_name=kwargs["SERVER_NAME"], port=80)) + server_block if kwargs["LISTEN_PORT"] == 443 else server_block ) ) put( sio, "/etc/nginx/sites-enabled/{server_name}".format( server_name=kwargs["SERVER_NAME"] ), use_sudo=True, ) return restart_systemd("nginx")
def test_upsert_by_location(self): # upsert_by_name('/api0', self.parsed_server_block_no_rest, self.parsed_api_block) self.assertEqual( """server { # Emitted by nginx_parse_emit.emit.server_block server_name offscale.io; listen 80; } server { # Emitted by nginx_parse_emit.emit.server_block server_name offscale.io; listen 443; location /api0 { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:5000/awesome; proxy_redirect off; } }""", dumps( upsert_by_location("/api0", self.two_roots, self.parsed_api_block)), ) self.assertEqual( """server { # Emitted by nginx_parse_emit.emit.server_block server_name offscale.io; listen 443; location /api0 { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:5000/awesome; proxy_redirect off; } }""", dumps( upsert_by_location( self.server_name, "/api0", merge_into( self.server_name, self.parsed_server_block_no_rest, self.parsed_api_block, ), self.parsed_api_block, )), ) self.assertEqual( """server { # Emitted by nginx_parse_emit.emit.server_block server_name offscale.io; listen 443; location /api0 { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass WRONG_DOMAIN; proxy_redirect off; } }""", dumps( upsert_by_location( self.server_name, "/api0", merge_into( self.server_name, self.parsed_server_block_no_rest, self.parsed_api_block, ), loads( api_proxy_block(location=self.location, proxy_pass="******")), )), )
def test_server_proxy_merge(self): parsed = merge_into( self.server_name, self.parsed_server_block_no_rest, self.parsed_api_block, self.parsed_api_block, ) self.assertEqual( """server { # Emitted by nginx_parse_emit.emit.server_block server_name offscale.io; listen 443; location /api0 { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:5000/awesome; proxy_redirect off; } location /api0 { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:5000/awesome; proxy_redirect off; } }""", dumps(parsed), ) self.assertEqual( [[ ["server"], [ ["# Emitted by nginx_parse_emit.emit.server_block", "\n"], ["server_name", "offscale.io"], ["listen", "443"], [ ["location", "/api0"], [ ["proxy_set_header", "Host $http_host"], ["proxy_set_header", "X-Real-IP $remote_addr"], ["proxy_set_header", "X-Scheme $scheme"], ["proxy_set_header", "X-Forwarded-Proto $scheme"], [ "proxy_set_header", "X-Forwarded-For $proxy_add_x_forwarded_for", ], ["proxy_pass", "http://127.0.0.1:5000/awesome"], ["proxy_redirect", "off"], ], ], [ ["location", "/api0"], [ ["proxy_set_header", "Host $http_host"], ["proxy_set_header", "X-Real-IP $remote_addr"], ["proxy_set_header", "X-Scheme $scheme"], ["proxy_set_header", "X-Forwarded-Proto $scheme"], [ "proxy_set_header", "X-Forwarded-For $proxy_add_x_forwarded_for", ], ["proxy_pass", "http://127.0.0.1:5000/awesome"], ["proxy_redirect", "off"], ], ], ], ]], parsed, )
def install0(*args, **kwargs): kwargs.setdefault("virtual_env", "/opt/venvs/mlflow") if not kwargs.get("skip_virtualenv", False): venv0_kwargs = { "virtual_env": kwargs["virtual_env"], "python3": True, "pip_version": "19.2.3", "use_sudo": True, "remote_user": "******", "PACKAGES": ["mlflow[extras]"], } venv0_kwargs.update(kwargs) python_mod.install_venv0(**venv0_kwargs) circus0_kwargs = { "APP_NAME": "mlflow", "APP_PORT": 5000, "CMD": "{virtual_env}/bin/mlflow".format(virtual_env=kwargs["virtual_env"]), "CMD_ARGS": "ui", "WSGI_FILE": None, } circus0_kwargs.update(kwargs) circus_mod.install_circus0(**circus0_kwargs) kwargs.setdefault("skip_nginx_restart", True) kwargs.setdefault( "conf_remote_filename", "/etc/nginx/sites-enabled/{}.conf".format(kwargs["SERVER_NAME"]), ) kwargs.update({ "nginx_conf": "proxy-pass.conf", "NAME_OF_BLOCK": "mlflow", "SERVER_LOCATION": "localhost:{port}".format(port=circus0_kwargs["APP_PORT"]), "LISTEN_PORT": 80, "LOCATION": "/", }) if exists(kwargs["conf_remote_filename"]): parsed_remote_conf = get_parsed_remote_conf( kwargs["conf_remote_filename"]) parsed_api_block = loads( api_proxy_block( location=kwargs["LOCATION"], proxy_pass="******".format(kwargs["SERVER_LOCATION"]), )) sio = StringIO() sio.write( dumps( merge_into(kwargs["SERVER_NAME"], parsed_remote_conf, parsed_api_block))) sio.seek(0) put(sio, kwargs["conf_remote_filename"], use_sudo=True) else: nginx_static.setup_conf0(**kwargs) # with shell_env(VIRTUAL_ENV=kwargs['virtual_env'], PATH="{}/bin:$PATH".format(kwargs['virtual_env'])):sudo('mlflow initdb') restart_systemd("circusd")