Best Python code snippet using localstack_python
build.py
Source:build.py
...46 _build_cache_if_necessary(args)47 if args.mount:48 _run_docker(['up', '-d', 'postgres_test'])49 # Mount the source code and run a container with bash shell50 _run_docker(['run', '--rm'] + _get_mount_volumes() + ['test', 'bash'])51 _run_docker(['down'])52 elif args.generate:53 _run_docker(54 ['run', '--rm'] + _get_mount_volumes() + ['test', 'make gen'],55 )56 elif args.tests:57 # Run unit tests58 _run_docker(['up', '-d', 'postgres_test'])59 _run_docker(['build', 'test'])60 _run_docker(['run', '--rm', 'test', 'make test'])61 if not args.leave:62 _run_docker(['down'])63 else:64 _run_docker(files_args + _get_docker_build_args(args))65def _get_docker_files_command_args(args: argparse.Namespace) -> List[str]:66 def make_file_args(files: Iterable[str]) -> List[str]:67 ret = []68 for f in files:69 ret.append('-f')70 ret.append(f)71 return ret72 if args.all:73 return make_file_args(COMPOSE_FILES)74 if args.noncore:75 return make_file_args(76 filter(lambda f: f not in CORE_COMPOSE_FILES, COMPOSE_FILES),77 )78 # docker-compose uses docker-compose.yml and docker-compose.override.yml79 # by default80 return []81def _create_build_context_if_necessary(args: argparse.Namespace) -> None:82 """ Clear out the build context from the previous run """83 if args.noncore:84 return85 if os.path.exists(BUILD_CONTEXT):86 shutil.rmtree(BUILD_CONTEXT)87 os.mkdir(BUILD_CONTEXT)88 print("Creating build context in '%s'..." % BUILD_CONTEXT)89 modules = []90 for module in _get_modules():91 _copy_module(module)92 modules.append(module.name)93 print('Context created for modules: %s' % ', '.join(modules))94def _build_cache_if_necessary(args: argparse.Namespace) -> None:95 if args.nocache or args.mount or args.generate or \96 args.tests or args.noncore:97 return98 # Check if orc8r_cache image exists99 result = subprocess.run(['docker', 'images', '-q', 'orc8r_cache'],100 stdout=PIPE, stderr=PIPE)101 if result.stdout == b'':102 print("Orc8r_cache image does not exist. Building...")103 _run_docker(['-f', 'docker-compose.cache.yml', 'build'])104def _get_docker_build_args(args: argparse.Namespace) -> List[str]:105 # noncore containers don't need the orc8r cache106 if args.noncore or args.nocache:107 ret = ['build']108 else:109 ret = ['build', '--build-arg', 'baseImage=orc8r_cache']110 if args.parallel:111 ret.append('--parallel')112 return ret113def _run_docker(cmd: List[str]) -> None:114 """ Run the required docker-compose command """115 print("Running 'docker-compose %s'..." % " ".join(cmd))116 try:117 subprocess.run(['docker-compose'] + cmd, check=True)118 except subprocess.CalledProcessError as err:119 exit(err.returncode)120def _copy_module(module: MagmaModule) -> None:121 """ Copy the module dir into the build context """122 module_dest = _get_module_destination(module)123 dst = os.path.join(BUILD_CONTEXT, module_dest)124 # Copy relevant parts of the module to the build context125 shutil.copytree(126 os.path.join(module.host_path, 'cloud'),127 os.path.join(dst, 'cloud'),128 )129 if module.name == 'orc8r':130 shutil.copytree(131 os.path.join(module.host_path, 'lib'),132 os.path.join(dst, 'lib'),133 )134 shutil.copytree(135 os.path.join(module.host_path, 'gateway', 'go'),136 os.path.join(dst, 'gateway', 'go'),137 )138 if os.path.isdir(os.path.join(module.host_path, 'tools')):139 shutil.copytree(140 os.path.join(module.host_path, 'tools'),141 os.path.join(dst, 'tools'),142 )143 if os.path.isdir(os.path.join(module.host_path, 'cloud', 'configs')):144 shutil.copytree(145 os.path.join(module.host_path, 'cloud', 'configs'),146 os.path.join(BUILD_CONTEXT, 'configs', module.name),147 )148 # Copy the go.mod file for caching the go downloads149 # Use module_dest to preserve relative paths between go modules150 for filename in glob.iglob(dst + '/**/go.mod', recursive=True):151 gomod = filename.replace(152 dst, os.path.join(BUILD_CONTEXT, 'gomod', module_dest),153 )154 os.makedirs(os.path.dirname(gomod))155 shutil.copyfile(filename, gomod)156def _get_mount_volumes() -> List[str]:157 """ Return the volumes argument for docker-compose commands """158 volumes = []159 for module in _get_modules():160 module_mount_path = _get_module_destination(module)161 dst = os.path.join('/', module_mount_path)162 volumes.extend(['-v', '%s:%s' % (module.host_path, dst)])163 return volumes164def _get_modules() -> List[MagmaModule]:165 """166 Read the modules config file and return all modules specified.167 """168 filename = os.environ.get('MAGMA_MODULES_FILE', DEFAULT_MODULES_FILE)169 # Use the FB modules file if the file exists170 if os.path.isfile(FB_MODULES_FILE):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!