Last active
June 27, 2020 05:04
-
-
Save mcbridematt/54d51ed813e6910b9244ce3c7d149e51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import requests | |
import os | |
import subprocess | |
import json | |
# Usage: This script will read the rockon-registry repo (must be located under "rockon-registry") and determines | |
# if each rockon has a published arm64 image. | |
# A working docker client is required (the Docker host being queried may be on another machine, using the usual | |
# DOCKER_HOST environment variable) | |
# Get the image manifest via the Docker CLI | |
# Ideally we would use the docker API directly, but this | |
# is an easier way to do it | |
def get_docker_manifest(image_name): | |
docker_cli_env = {"DOCKER_CLI_EXPERIMENTAL": "enabled"} | |
manifest_result = subprocess.run( | |
["docker", "manifest", "inspect", image_name], | |
capture_output=True, | |
env=docker_cli_env, | |
) | |
if manifest_result.returncode == 0: | |
manifestjsonstr = manifest_result.stdout.decode("utf-8") | |
manifestjson = json.loads(manifestjsonstr) | |
return manifestjson | |
else: | |
print(manifest_result.stderr) | |
def check_for_armv8_image(image_manifest): | |
if "config" in image_manifest: | |
manifest_config = image_manifest["config"]["mediaType"] | |
if manifest_config == "application/vnd.docker.container.image.v1+json": | |
return False | |
if "manifests" in image_manifest: | |
manifests = image_manifest["manifests"] | |
for manifest in manifests: | |
if "platform" in manifest: | |
platform = manifest["platform"] | |
if platform["architecture"] == "arm64" and platform["os"] == "linux": | |
return True | |
else: | |
print("Platform not in manifest") | |
print(manifest) | |
return False | |
def read_rockon(rockon_json_filepath): | |
rockon_def_file = open(rockon_json_filepath, "r") | |
rockon_def = json.load(rockon_def_file) | |
rockon_containers = [] | |
for rockon in rockon_def: | |
rockon_data = rockon_def[rockon] | |
if "containers" not in rockon_data: | |
continue | |
containers = rockon_data["containers"] | |
for container in containers: | |
container_data = containers[container] | |
container_image = container_data["image"] | |
if ("tag" in container_data): | |
container_image = "{}:{}".format(container_image,container_data["tag"]) | |
rockon_containers.append([rockon, container, container_image]) | |
return rockon_containers | |
def load_rockon_definitions(): | |
rockon_root_file = open("rockon-registry/root.json", "r") | |
rockon_root = json.load(rockon_root_file) | |
image_list = [] | |
for rockon_name in rockon_root: | |
rockon_file = rockon_root[rockon_name] | |
rockon_file_path = os.path.join("rockon-registry", rockon_file) | |
rockon_data = read_rockon(rockon_file_path) | |
image_list.extend(rockon_data) | |
return image_list | |
rockons = load_rockon_definitions() | |
for (rockon_name, rockon_container, rockon_image) in rockons: | |
image_manifest = get_docker_manifest(rockon_image) | |
if image_manifest == None: | |
print("{},{},{}".format(rockon_name, rockon_image, "Invalid")) | |
continue | |
has_armv8_image = check_for_armv8_image(image_manifest) | |
print("{},{},{}".format(rockon_name, rockon_image, has_armv8_image)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment