Skip to content

Commit

Permalink
Add support for selecting the container architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamOlech committed Feb 8, 2023
1 parent 7adb76f commit a2c2976
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 9 additions & 4 deletions dockersave/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_token(image, user=None, password=None, auth_endpoint="https://auth.docke

return r.json()['token']

def get_manifest(image, tag, token, registry_url):
def get_manifest(image, tag, token, registry_url, arch="amd64"):
request_url = "{}/v2/{}/manifests/{}".format(registry_url, image, tag)

supported_fat_manifests = [
Expand All @@ -79,7 +79,12 @@ def get_manifest(image, tag, token, registry_url):
)

if r.headers["content-type"] in supported_fat_manifests:
return get_manifest(image, r.json()['manifests'][0]["digest"], token, registry_url)
return get_manifest(
image,
next(x['digest'] for x in r.json()['manifests'] if x['platform']['architecture'] == arch),
token,
registry_url
)

r.raise_for_status()
return r
Expand Down Expand Up @@ -155,7 +160,7 @@ def lexer_wrapper(string, user=None, password=None, secure=True):
return img

class Image:
def __init__(self, image, tag, user=None, password=None, other_tags=False, registry_url="https://registry-1.docker.io"):
def __init__(self, image, tag, user=None, password=None, other_tags=False, registry_url="https://registry-1.docker.io", arch="amd64"):
self.image = image
self.tag = tag
self.registry_url = registry_url
Expand All @@ -181,7 +186,7 @@ def __init__(self, image, tag, user=None, password=None, other_tags=False, regis
else:
self.taglist = None

self.manifest_response = get_manifest(image, tag, self.token, self.registry_url)
self.manifest_response = get_manifest(image, tag, self.token, self.registry_url, arch)

self.manifest = self.manifest_response.json()

Expand Down
5 changes: 4 additions & 1 deletion dockersave/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def download(args):
user=args.user,
password=args.password,
other_tags=args.tags,
registry_url=l['registry_url'])
registry_url=l['registry_url'],
arch=args.arch
)

if args.tags:
from pprint import PrettyPrinter as pp
Expand Down Expand Up @@ -72,6 +74,7 @@ def get_parser():
parser.add_argument('--metadata', action='store_true')
parser.add_argument('--sha', action='store_true')
parser.add_argument('--tags', action='store_true')
parser.add_argument('--arch', type=str, default="amd64")
parser.add_argument('--version', action='version', version=__version__)
parser.set_defaults(func=download)

Expand Down

0 comments on commit a2c2976

Please sign in to comment.