Best Python code snippet using localstack_python
cloud_build.py
Source:cloud_build.py
1# Copyright 2019 The Android Open Source Project2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14import itertools15import logging16import os17import re18import yaml19import emu.emu_downloads_menu as emu_downloads_menu20from emu.template_writer import TemplateWriter21from emu.process import run22from emu.containers.emulator_container import EmulatorContainer23from emu.containers.system_image_container import SystemImageContainer24from emu.emu_downloads_menu import accept_licenses25from emu.utils import mkdir_p26def git_commit_and_push(dest):27 """Commit and pushes this cloud build to the git repo.28 Note that this can be *EXTREMELY* slow as you will likely29 have very large objects in your repo.30 Args:31 dest ({string}): The destination of the git repository.32 """33 run(["git", "add", "--verbose", "*"], dest)34 run(["git", "commit", "-F", "README.MD"], dest)35 run(["git", "push"], dest)36def create_build_step(for_container, destination):37 build_destination = os.path.join(destination, for_container.image_name())38 logging.info("Generating %s", build_destination)39 for_container.write(build_destination)40 if for_container.can_pull():41 logging.warning("Container already available, no need to create step.")42 return {}43 step = for_container.create_cloud_build_step(for_container.image_name())44 step["waitFor"] = ["-"]45 step["id"] = for_container.image_name()46 logging.info("Adding step: %s", step)47 return step48def cloud_build(args):49 """Prepares the cloud build yaml and all its dependencies.50 The cloud builder will generate a single cloudbuild.yaml and generates the build51 scripts for every individual container.52 It will construct the proper dependencies as needed.53 """54 accept_licenses(True)55 mkdir_p(args.dest)56 image_zip = [args.img]57 # Check if we are building a custom image from a zip file58 if not os.path.exists(image_zip[0]):59 # We are using a standard image, we likely won't need to download it.60 image_zip = emu_downloads_menu.find_image(image_zip[0])61 emulator_zip = [args.emuzip]62 if emulator_zip[0] in ["stable", "canary", "all"]:63 emulator_zip = [x.download() for x in emu_downloads_menu.find_emulator(emulator_zip[0])]64 elif re.match(r"\d+", emulator_zip[0]):65 # We must be looking for a build id66 logging.warning("Treating %s as a build id", emulator_zip[0])67 emulator_zip = [emu_downloads_menu.download_build(emulator_zip[0])]68 steps = []69 images = []70 emulators = set()71 emulator_images = []72 for (img, emu) in itertools.product(image_zip, emulator_zip):73 logging.info("Processing %s, %s", img, emu)74 system_container = SystemImageContainer(img, args.repo)75 if args.sys:76 steps.append(create_build_step(system_container, args.dest))77 else:78 for metrics in [True, False]:79 emulator_container = EmulatorContainer(emu, system_container, args.repo, metrics)80 emulators.add(emulator_container.props["emu_build_id"])81 steps.append(create_build_step(emulator_container, args.dest))82 images.append(emulator_container.full_name())83 images.append(emulator_container.latest_name())84 emulator_images.append(emulator_container.full_name())85 emulator_images.append(emulator_container.latest_name())86 cloudbuild = {"steps": steps, "images": images, "timeout": "21600s"}87 logging.info("Writing cloud yaml [%s] in %s", yaml, args.dest)88 with open(os.path.join(args.dest, "cloudbuild.yaml"), "w") as ymlfile:89 yaml.dump(cloudbuild, ymlfile)90 writer = TemplateWriter(args.dest)91 writer.write_template(92 "cloudbuild.README.MD",93 {"emu_version": ", ".join(emulators), "emu_images": "\n".join(["* {}".format(x) for x in emulator_images])},94 rename_as="README.MD",95 )96 writer.write_template(97 "registry.README.MD",98 {99 "emu_version": ", ".join(emulators),100 "emu_images": "\n".join(["* {}".format(x) for x in images]),101 "first_image": next(iter(images), None),102 },103 rename_as="REGISTRY.MD",104 )105 if args.git:...
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!!