def _run_docker_shell_script(script_name, docker_dir, trailing_args=None, env_variables=dict()): """ script_name (String) filename of a script in the nest/docker/ directory docker_dir (String) directory of docker scripts in the nest repo. expected to be /code_live/docker, but may be different is run outside of the nest_ops container env_variables (dict of string->string): will be set as commandline env variables in the shell that the script is run """ #sh cannot be broken into its own list element or you will be dropped #into a shell cmd_ary = [('sh ' + script_name)] if trailing_args is not None: cmd_ary.extend(trailing_args) cmd = " ".join(cmd_ary) log("Executing command: " + str(cmd)) cr = container_users.make_host_user_command_runner() cr.set_working_dir(docker_dir) cr.add_env_variables(env_variables) result = cr.run(cmd, stream_log=True) exit_code = result.get_exit_code() return exit_code
def test_touchfile(): cr = container_users.make_host_user_command_runner() host_user = os.environ.get("DOCKER_HOST_USER_NAME") host_user_id = int(os.environ.get("DOCKER_HOST_USER_ID")) docker_gid = int(os.environ.get("DOCKER_HOST_DOCKER_GROUP_ID")) tmp_fn = tempfile.mktemp() cr.run('touch ' + tmp_fn) #http://stackoverflow.com/a/927890/270001 stat = os.stat(tmp_fn) obs_uid = stat.st_uid assert (obs_uid == host_user_id) obs_uname = pwd.getpwuid(obs_uid)[0] assert (obs_uname == host_user) obs_gid = stat.st_gid assert (obs_gid == docker_gid) obs_group = grp.getgrgid(obs_gid)[0] assert (obs_group == 'docker') cr.run('rm ' + tmp_fn) return
def _compile_web_assets_ts(project_root_dir, runlevel): """Build the client assets.""" clientdir = os.path.join(project_root_dir, 'client') gulppath = os.path.join(clientdir, 'node_modules', '.bin', 'gulp') log("running gulp from " + str(clientdir)) exit_sum = 0 # clean and build cr = container_users.make_host_user_command_runner() cr.set_working_dir(clientdir) # Pass runlevel down into gulp runlevel.write_to_os() # Pass HUBZERO_APPLICATION_HOST and MAX_CONTENT_LENGTH # down into gulp (knoweng only) project_params = knoweng_config.generate_project_params(runlevel) hz_host = project_params['HUBZERO_APPLICATION_HOST'] if hz_host != 'FIXME': os.environ['HUBZERO_APPLICATION_HOST'] = hz_host os.environ['MAX_CONTENT_LENGTH'] = str( project_params['MAX_CONTENT_LENGTH']) cmd = gulppath + " clean" res = cr.run(cmd, stream_log=True) exit_sum += res.get_exit_code() cmd = gulppath + " dist" res = cr.run(cmd, stream_log=True) exit_sum += res.get_exit_code() return exit_sum
def _run_remote_maintenance(target_site): """ The local docker containers will run as the current user. The remote user will be nestbot. """ local_cmd_runner = container_users.make_host_user_command_runner() remote_user = '******' remote_cmd_runner = CommandRunnerRemote(local_cmd_runner, target_site, remote_user) exit_code = _run_remote_maintenance_commands(remote_cmd_runner) return exit_code
def _prep_client_dist_for_project(project_env, project_root_dir): """ currently this just means copying from index.<project_name>.html to index.html in the client dist directory. """ #need to make the project's index.html the index.html that tomcat will find clientdir = os.path.join(project_root_dir, 'client') index_target_fn = os.path.join(clientdir, 'index.html') index_src_base = 'index.' + project_env.get_project_name() + '.html' index_src_fn = os.path.join(clientdir, index_src_base) cmd = 'cp ' + index_src_fn + ' ' + index_target_fn cr = container_users.make_host_user_command_runner() result = cr.run(cmd) return result.get_exit_code()
def _compile_python(project_root_dir): try: from pylint.lint import Run rcfile = os.path.join(project_root_dir, '.pylintrc') cmd = 'pylint ' cmd += '--errors-only ' cmd += '--rcfile ' + rcfile cmd += ' nest_py' cr = container_users.make_host_user_command_runner() res = cr.run(cmd, stream_log=True) exit_code = res.get_exit_code() except Exception as e: log("linting crashed: " + str(e)) traceback.print_exc() exit_code = 1 return exit_code
def _run_deploy(project_env, git_tag_or_branch, target_site): """ deploy the given git version on the local machine with the given project_env. The code will be in the current user's (who is running nest_ops) home directory (~/nest_releases/nest_<branch_name>/). The docker containers will run as the current user. """ local_cmd_runner = container_users.make_host_user_command_runner() remote_user = '******' remote_cmd_runner = CommandRunnerRemote(local_cmd_runner, target_site, remote_user) exit_code = _run_deploy_commands(project_env, git_tag_or_branch, remote_cmd_runner) return exit_code
def _compile_web_assets_npm(project_root_dir): """(Re)install the node modules.""" clientdir = os.path.join(project_root_dir, 'client') modulesdir = os.path.join(clientdir, 'node_modules') if os.path.isdir(modulesdir): log("removing " + str(modulesdir)) try: rmtree(modulesdir) except OSError as exception: log(exception.strerror + ": " + exception.filename) return 1 log("installing node modules under " + str(clientdir)) cmd = 'npm i' cr = container_users.make_host_user_command_runner() cr.set_working_dir(clientdir) res = cr.run(cmd, stream_log=True) return res.get_exit_code()
def _run_unit_test(project_root_dir): """ Runs all client tests. Returns zero if all tests succeed, non-zero otherwise. """ _start_x() clientdir = os.path.join(project_root_dir, 'client') gulppath = os.path.join(clientdir, 'node_modules', '.bin', 'gulp') cmd = gulppath + ' test' cr = container_users.make_host_user_command_runner() cr.set_working_dir(clientdir) res = cr.run(cmd, stream_log=True) exit_code = res.get_exit_code() _stop_x() return exit_code