def build_and_deploy(zoomdb, app_id, src_repo_type, src_url, zoombuild_cfg_content, use_subtasks=True, bundle_storage_engine=None, post_build_hooks=None, post_deploy_hooks=None, num_workers=1, requires_postgis=False, ): app_dir = os.path.join(taskconfig.NR_CUSTOMER_DIR, app_id) bundle_storage_engine = bundle.get_bundle_storage_engine( bundle_storage_engine) opts = { "APP_ID": app_id, "APP_DIR": app_dir, "CO_DIR": os.path.join(app_dir, "src"), "SRC_REPO_TYPE": src_repo_type, "SRC_URL": src_url, "ZOOMBUILD_CFG_CONTENT": zoombuild_cfg_content, "USE_SUBTASKS": use_subtasks, "BUNDLE_STORAGE": bundle_storage_engine, "POST_BUILD_HOOKS": post_build_hooks, "POST_DEPLOY_HOOKS": post_deploy_hooks, "NUM_WORKERS": num_workers, "REQUIRES_POSTGIS": requires_postgis, } utils.run_steps(zoomdb, opts, ( common_steps.checkout_code, write_build_configuration, build_project_bundle, request_database_setup, upload_project_bundle, wait_for_database_setup_to_complete, select_app_server_for_deployment, deploy_project_to_appserver, run_post_deploy_hooks, update_front_end_proxy, remove_previous_versions, )) return opts["DEPLOYED_ADDRESSES"]
def deploy_app_bundle(app_id, bundle_name, appserver_name, dbinfo, bundle_storage_engine=None, num_workers=1): bundle_storage_engine = bundle.get_bundle_storage_engine( bundle_storage_engine) my_hostname = utils.node_meta("name") my_instance_id = utils.node_meta("instance_id") if appserver_name not in (my_hostname, my_instance_id, "localhost"): raise utils.InfrastructureException( "Incorrect appserver received deploy_app_bundle task; " + "I am %s but the deploy is requesting %s." % (my_hostname, appserver_name)) install_app_bundle(app_id, bundle_name, appserver_name, dbinfo, bundle_storage_engine=bundle_storage_engine, num_workers=num_workers) # result is a (instance_id, node_name, host_ip, port_to_use) return start_serving_bundle(app_id, bundle_name)
def update_local_proxy_config(app_id, bundle_name, appservers, virtual_hostnames, site_media_map, bundle_storage_engine=None, remove_other_bundles=True): bundle_storage_engine = bundle.get_bundle_storage_engine( bundle_storage_engine) site_conf_filename = _get_nginx_conffile(app_id) if len(appservers) == 0: raise utils.InfrastructureException(( "No appserver URLs provided for nginx config update to %s. " "At least one upstream is required.") % app_id) app_dir, bundle_dir = utils.app_and_bundle_dirs(app_id, bundle_name) # We need to make sure this bundle's static is installed locally, so we # can serve its static media. if bundle_storage_engine is not SKIP_BUNDLE_INSTALL: deploy.install_app_bundle_static( app_id, bundle_name, bundle_storage_engine, remove_other_bundles=remove_other_bundles) file_path_vars = { "{SITE_PACKAGES}": os.path.join(bundle_dir, "lib/python2.6/site-packages"), "{SRC_PACKAGES}": os.path.join(bundle_dir, "src"), } default_file_path_base = os.path.join(bundle_dir, "user-repo") def _make_full_path(original_file_path): for varname, pathbase in file_path_vars.items(): if original_file_path.startswith(varname): rest = original_file_path[len(varname):] rest = rest.lstrip("/") return os.path.join(pathbase, rest) return os.path.join(default_file_path_base, original_file_path) sme = [dict(url_path=url_path, alias_dest=_make_full_path(file_path.strip('/')), ) for url_path, file_path in site_media_map.items()] sme.append(dict(url_path=taskconfig.DZ_ADMIN_MEDIA["url_path"], alias_dest=os.path.join( bundle_dir, taskconfig.DZ_ADMIN_MEDIA["bundle_file_path"]))) # NOTE THE SLASHES:::: # location /static/ { # alias /tmp/tmpR_1dI5/test001/bundle_test001_2011-03-09-03.52.55/user-src/static/; # } utils.render_tpl_to_file("nginx/site.conf", site_conf_filename, app_id=app_id, appservers=[dict( # (instance_id, node_name, host_ip, host_port) instance_id=a[0], node_name=a[1], host_ip=a[2], host_port=a[3], ) for a in appservers], virtual_hostnames=virtual_hostnames, site_media_entries=sme) utils.local_privileged(["kick_nginx"])