forked from containers/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report the size of the image that will be downloaded from a registry
This uses 'skopeo inspect' to get the size of the image on the registry, which is usually less than the size of the image in a local containers/storage image store after download (eg., 'podman images'), because they are kept compressed on the registry. Skopeo >= 1.10.0 is needed to retrieve the sizes [1]. However, this doesn't add a hard dependency on Skopeo to accommodate size-constrained operating systems like Fedora CoreOS. If skopeo(1) is missing or too old, then the size of the image won't be shown, but everything else would continue to work as before. Some changes by Debarshi Ray. [1] Skopeo commit d9dfc44888ff71a6 containers/skopeo@d9dfc44888ff71a6 containers/skopeo#641 containers#752 Signed-off-by: Nieves Montero <[email protected]>
- Loading branch information
1 parent
2129e28
commit a1c3095
Showing
7 changed files
with
96 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright © 2023 Red Hat Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package skopeo | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
|
||
"github.com/containers/toolbox/pkg/shell" | ||
) | ||
|
||
type Layer struct { | ||
Size json.Number | ||
} | ||
type Image struct { | ||
LayersData []Layer | ||
} | ||
|
||
func Inspect(target string) (*Image, error) { | ||
var stdout bytes.Buffer | ||
|
||
targetWithTransport := "docker://" + target | ||
args := []string{"inspect", "--format", "json", targetWithTransport} | ||
|
||
if err := shell.Run("skopeo", nil, &stdout, nil, args...); err != nil { | ||
return nil, err | ||
} | ||
|
||
output := stdout.Bytes() | ||
var image Image | ||
if err := json.Unmarshal(output, &image); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &image, nil | ||
} |