Inedo Community Forums Forums
    • Recent
    • Tags
    • Popular
    • Login

    Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.

    If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!

    ProGet API to get the operating systems of all Docker images

    Scheduled Pinned Locked Moved Support
    4 Posts 2 Posters 34 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      hashim.abu-gellban_3562
      last edited by

      Hi All,

      I used the API (/api/json/DockerImages_GetTags) to get all Docker images and their properties. However, I could not find any API that can get the Docker images' OSs (Windows/ Linux). Can you provide me with the API that get the OSs of docker images?

      dean-houstonD 1 Reply Last reply Reply Quote 0
      • dean-houstonD Offline
        dean-houston inedo-engineer @hashim.abu-gellban_3562
        last edited by

        Hi @hashim-abu-gellban_3562,

        DockerImages_GetTags is part of the Native API, which is basically just a wrapper around the SQL ProGet database. That's fine to use, but you can also use the Docker API to list tags as follows:

        curl -X GET https://proget-url/v2/feedName/repositoryName/tags/list
        

        The Docker API will show you tags that come through a connector, where as the Native API is will only be local tags.

        The Docker API does not provide a way to directly retrieve the operating system information of Docker images. However, you can infer the operating system information by examining the contents of the Docker image itself or by using external tools and scripts.

        Here's an example in Python of how to do that:

        import docker
        
        def get_os_of_image(image_name, tag):
            client = docker.from_env()
            image = client.images.get(f"{image_name}:{tag}")
            os_info = image.attrs['Os']
            return os_info
        
        # Example usage
        os_info = get_os_of_image('my-image', 'latest')
        print(f"Operating System: {os_info}")
        

        Alternatively, you can also inspect the image layers directly. Docker image layers contain files from the image's filesystem, and you can look for specific files or patterns that are indicative of the operating system.

        Best,
        Dean

        1 Reply Last reply Reply Quote 0
        • H Offline
          hashim.abu-gellban_3562
          last edited by hashim.abu-gellban_3562

          @dean-houston said in ProGet API to get the operating systems of all Docker images:

          curl -X GET https://proget-url/v2/feedName/repositoryName/tags/list

          Thank you for your help!

          I passed X-ApiKey to the API Key Authorization in Postman, but I got the following error:

          "errors": [
              {
                  "code": "UNAUTHORIZED",
                  "message": "Anonymous is not permitted to perform the Feeds_ViewFeed task for the                 current scope.",
              ...
              }
          

          ]

          What should I pass for authorization?

          dean-houstonD 1 Reply Last reply Reply Quote 0
          • dean-houstonD Offline
            dean-houston inedo-engineer @hashim.abu-gellban_3562
            last edited by

            Hi @hashim-abu-gellban_3562,

            Due to some reasons I don't fully understand, authenticating to the Docker API requires using a Bearer authentication token Authorization: Bearer {token}

            Here is an example for how to get that token:

            function GetDockerToken() {
            
                param (
                    [string] $packageName = $(throw "-packageName is required.  This is the namespace and image name.  For example: library/my-container-image"),
                    [string] $feed = $(throw "-feed is required"),
                    [string] $actionToAuthorize = $(throw "-action is required.  This is the docker action to be authorized (pull, push, delete, etc)"),
                    [string] $apiKey = $(throw "-apiKey is required"),
                    [string] $progetBaseUrl = $(throw "-progetBaseUrl is required. "),
            	[string] $service
                )
            
            
            	if ($service -eq "") {
                      # This expects that $progetBaseUrl is prepended with "https://"  If you are using "http://" then change 8 to 7 below.
            	  $service = $progetBaseUrl.SubString(8,$progetBaseUrl.Length-8)
            	}
            
            	$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "api","$apiKey")))
            	$response = Invoke-WebRequest -Uri "$progetBaseUrl/v2/_auth?service=$service&scope=repository`:$feed/$packageName`:$actionToAuthorize" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
            	if ($response.StatusDescription -eq "OK") {
            		$token = ($response.Content | ConvertFrom-Json).token
            		$token
            	}
            }
            

            I know we plan to document all this better some day, for now you can find the Semantic Versioning for Containers page.

            Dean

            1 Reply Last reply Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • 1 / 1
            • First post
              Last post
            Inedo Website Home • Support Home • Code of Conduct • Forums Guide • Documentation