Skip to content

Add option to manually name image. #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion emu/containers/emulator_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ class EmulatorContainer(DockerContainer):
"""
NO_METRICS_MESSAGE = "No metrics are collected when running this container."

def __init__(self, emulator, system_image_container, repository=None, metrics=False, extra=""):
def __init__(self, emulator, system_image_container, repository=None, metrics=False, extra="", name=None):
self.emulator_zip = AndroidReleaseZip(emulator)
self.system_image_container = system_image_container
self.metrics = metrics
self.name = name

if type(extra) is list:
extra = " ".join(extra)
Expand Down Expand Up @@ -96,6 +97,9 @@ def write(self, dest):
self.emulator_zip.extract(os.path.join(dest, "emu"))

def image_name(self):
if self.name:
return self.name

name = "{}-{}-{}".format(
self.props["ro.build.version.sdk"], self.props["qemu.short_tag"], self.props["qemu.short_abi"]
)
Expand Down
32 changes: 22 additions & 10 deletions emu/emu_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def create_docker_image(args):

emuzip = [args.emuzip]
if emuzip[0] in ["stable", "canary", "all"]:
emuzip = [x.download() for x in emu_downloads_menu.find_emulator(emuzip[0])]
emuzip = [x.download()
for x in emu_downloads_menu.find_emulator(emuzip[0])]
elif re.match(r"\d+", emuzip[0]):
# We must be looking for a build id
logging.info("Treating %s as a build id", emuzip[0])
Expand All @@ -95,7 +96,8 @@ def create_docker_image(args):
if args.sys:
continue

emu_docker = EmulatorContainer(emu, sys_docker, args.repo, cfg.collect_metrics(), args.extra)
emu_docker = EmulatorContainer(
emu, sys_docker, args.repo, cfg.collect_metrics(), args.extra, args.name)
emu_docker.build(args.dest)

if args.start:
Expand Down Expand Up @@ -140,10 +142,12 @@ def main():
"""Entry point that parses the argument, and invokes the proper functions."""

parser = argparse.ArgumentParser(
description="List and create emulator docker containers ({}).".format(emu.__version__),
description="List and create emulator docker containers ({}).".format(
emu.__version__),
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", help="Set verbose logging")
parser.add_argument("-v", "--verbose", dest="verbose",
action="store_true", help="Set verbose logging")

subparsers = parser.add_subparsers()

Expand All @@ -161,7 +165,8 @@ def main():
license_parser = subparsers.add_parser(
"licenses", help="Lists all licenses and gives you a chance to accept or reject them."
)
license_parser.add_argument("--accept", action="store_true", help="Accept all licensens after displaying them.")
license_parser.add_argument(
"--accept", action="store_true", help="Accept all licensens after displaying them.")
license_parser.set_defaults(func=accept_licenses)

create_parser = subparsers.add_parser(
Expand Down Expand Up @@ -192,7 +197,8 @@ def main():
create_parser.add_argument(
"--dest", default=os.path.join(os.getcwd(), "src"), help="Destination for the generated docker files"
)
create_parser.add_argument("--tag", default="", help="Docker tag, defaults to the emulator build id")
create_parser.add_argument(
"--tag", default="", help="Docker tag, defaults to the emulator build id")
create_parser.add_argument(
"--repo",
default="us-docker.pkg.dev/android-emulator-268719/images",
Expand All @@ -212,14 +218,18 @@ def main():
action="store_true",
help="When enabled, the emulator will send usage metrics to Google when the container exists gracefully.",
)
create_parser.add_argument("--no-metrics", action="store_true", help="Disables the collection of usage metrics.")
create_parser.add_argument(
"--no-metrics", action="store_true", help="Disables the collection of usage metrics.")
create_parser.add_argument(
"--start",
action="store_true",
help="Starts the container after creating it. "
"All exposed ports are forwarded, and your private adbkey (if available) is injected but not stored.",
)
create_parser.add_argument("--sys", action="store_true", help="Process system image layer only.")
create_parser.add_argument(
"--sys", action="store_true", help="Process system image layer only.")
create_parser.add_argument(
"--name", help="Name to give image when pushed.", default=None)
create_parser.set_defaults(func=create_docker_image)

create_inter = subparsers.add_parser(
Expand Down Expand Up @@ -269,7 +279,8 @@ def main():
dist_parser.add_argument(
"--dest", default=os.path.join(os.getcwd(), "src"), help="Destination for the generated docker files"
)
dist_parser.add_argument("--git", action="store_true", help="Create a git commit, and push to destination.")
dist_parser.add_argument("--git", action="store_true",
help="Create a git commit, and push to destination.")
dist_parser.add_argument(
"--sys", action="store_true", help="Write system image steps, otherwise write emulator steps."
)
Expand All @@ -291,7 +302,8 @@ def main():
# Configure logger.
lvl = logging.DEBUG if args.verbose else logging.WARNING
handler = colorlog.StreamHandler()
handler.setFormatter(colorlog.ColoredFormatter("%(log_color)s%(levelname)s:%(message)s"))
handler.setFormatter(colorlog.ColoredFormatter(
"%(log_color)s%(levelname)s:%(message)s"))
logging.root = colorlog.getLogger("root")
logging.root.addHandler(handler)
logging.root.setLevel(lvl)
Expand Down
16 changes: 9 additions & 7 deletions emu/emu_downloads_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@
from emu.utils import download
from emu.docker_config import DockerConfig

ANDROID_REPOSITORY = os.environ.get("ANDROID_REPOSITORY", "https://dl.google.com/")

SYSIMG_REPOS = [
"https://dl.google.com/android/repository/sys-img/android/sys-img2-1.xml",
"https://dl.google.com/android/repository/sys-img/google_apis/sys-img2-1.xml",
"https://dl.google.com/android/repository/sys-img/google_apis_playstore/sys-img2-1.xml",
"https://dl.google.com/android/repository/sys-img/android-tv/sys-img2-1.xml",
f"{ANDROID_REPOSITORY}/android/repository/sys-img/android/sys-img2-1.xml",
f"{ANDROID_REPOSITORY}/android/repository/sys-img/google_apis/sys-img2-1.xml",
f"{ANDROID_REPOSITORY}/android/repository/sys-img/google_apis_playstore/sys-img2-1.xml",
f"{ANDROID_REPOSITORY}/android/repository/sys-img/android-tv/sys-img2-1.xml",
]

EMU_REPOS = ["https://dl.google.com/android/repository/repository2-1.xml"]
EMU_REPOS = [f"{ANDROID_REPOSITORY}/android/repository/repository2-1.xml"]

CHANNEL_MAPPING = {"channel-0": "stable", "channel-1": "beta", "channel-2": "dev", "channel-3": "canary"}

Expand Down Expand Up @@ -147,7 +149,7 @@ def __init__(self, pkg, licenses):
url_element = pkg.find(".//url")
self.zip = url_element.text

self.url = "https://dl.google.com/android/repository/sys-img/%s/%s" % (self.tag, self.zip)
self.url = f"{ANDROID_REPOSITORY}/android/repository/sys-img/{self.tag}/{self.zip}"

def short_tag(self):
return self.SHORT_TAG[self.tag]
Expand Down Expand Up @@ -192,7 +194,7 @@ def __init__(self, pkg, licenses):
for archive in archives:
url = archive.find(".//url").text
hostos = archive.find("host-os").text
self.urls[hostos] = "https://dl.google.com/android/repository/%s" % url
self.urls[hostos] = f"{ANDROID_REPOSITORY}/android/repository/{url}"

def download_name(self):
return "emulator-{}.zip".format(self.version)
Expand Down
2 changes: 1 addition & 1 deletion emu/platform_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from emu.utils import download

# Platform tools, needed to get adb.
PLATFORM_TOOLS_URL = "https://dl.google.com/android/repository/platform-tools_r29.0.5-linux.zip"
PLATFORM_TOOLS_URL = f'{os.environ.get("ANDROID_REPOSITORY", "https://dl.google.com")}/android/repository/platform-tools_r29.0.5-linux.zip'


class PlatformTools(object):
Expand Down