's'
This commit is contained in:
51
redroid.py
51
redroid.py
@@ -24,37 +24,48 @@ def ensure_base_image(container_runtime, android_version):
|
||||
)
|
||||
local_present = inspect.returncode == 0
|
||||
|
||||
helper.print_color(
|
||||
"Trying to pull base image {} first ...".format(base_image),
|
||||
helper.bcolors.GREEN,
|
||||
)
|
||||
pull = subprocess.run([container_runtime, "pull", base_image], check=False)
|
||||
if pull.returncode == 0:
|
||||
return "pulled"
|
||||
tar_name = "redroid-redroid-{}-latest.tar".format(android_version)
|
||||
tar_path = os.path.join(helper.get_image_dir(), tar_name)
|
||||
tar_exists = os.path.isfile(tar_path)
|
||||
offline_only = helper.is_offline_only()
|
||||
|
||||
if local_present:
|
||||
helper.print_color(
|
||||
"Online pull failed, falling back to local image cache ...",
|
||||
helper.bcolors.YELLOW,
|
||||
"Using existing local base image {} ...".format(base_image),
|
||||
helper.bcolors.GREEN,
|
||||
)
|
||||
return "present"
|
||||
|
||||
tar_name = "redroid-redroid-{}-latest.tar".format(android_version)
|
||||
tar_path = os.path.join(helper.get_image_dir(), tar_name)
|
||||
if not os.path.isfile(tar_path):
|
||||
if tar_exists:
|
||||
helper.print_color(
|
||||
"Loading base image from offline archive {} ...".format(tar_path),
|
||||
helper.bcolors.GREEN,
|
||||
)
|
||||
subprocess.run([container_runtime, "load", "-i", tar_path], check=True)
|
||||
return tar_path
|
||||
|
||||
if offline_only:
|
||||
raise FileNotFoundError(
|
||||
"Online pull for {} failed, local image cache is missing, and offline archive {} was not found".format(
|
||||
"REDROID_OFFLINE is set but {} is not in local storage and {} was not found".format(
|
||||
base_image,
|
||||
tar_path,
|
||||
)
|
||||
)
|
||||
|
||||
helper.print_color(
|
||||
"Online pull failed, loading local image archive {} ...".format(tar_path),
|
||||
"No local base image or offline .tar; pulling {} ...".format(base_image),
|
||||
helper.bcolors.YELLOW,
|
||||
)
|
||||
subprocess.run([container_runtime, "load", "-i", tar_path], check=True)
|
||||
return tar_path
|
||||
pull = subprocess.run([container_runtime, "pull", base_image], check=False)
|
||||
if pull.returncode == 0:
|
||||
return "pulled"
|
||||
|
||||
raise FileNotFoundError(
|
||||
"Pull failed for {} and offline archive {} was not found".format(
|
||||
base_image,
|
||||
tar_path,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def build_layers(args):
|
||||
@@ -145,8 +156,16 @@ def main():
|
||||
choices=["docker", "podman"],
|
||||
help="Container runtime",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--offline",
|
||||
dest="offline",
|
||||
action="store_true",
|
||||
help="Do not pull images or download archives; require offline/downloads and offline/images",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
if args.offline:
|
||||
os.environ["REDROID_OFFLINE"] = "1"
|
||||
base_image_source = ensure_base_image(args.container, args.android)
|
||||
dockerfile, tags = build_layers(args)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user