Skip to content

Commit

Permalink
Move skopeo-related code into a new package
Browse files Browse the repository at this point in the history
The following package and file have been created src/pkg/skopeo/skopeo.go
Signed-off-by: Nieves Montero <[email protected]>
  • Loading branch information
nievesmontero committed Jan 25, 2023
1 parent a1d9fa0 commit 7c1e34b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func pullImage(image, release string) (bool, error) {

if promptForDownload {

infoSize, err := podman.InspectSkopeo("image", imageSize)
infoSize, err := podman.Inspect("image", imageSize)
if err != nil {
return false, fmt.Errorf("cannot get the size of the image")
}
Expand Down
41 changes: 0 additions & 41 deletions src/pkg/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,47 +280,6 @@ func Inspect(typearg string, target string) (map[string]interface{}, error) {
return info[0], nil
}

func InspectSkopeo(typearg string, target string) (interface{}, error) {

var stdout bytes.Buffer

args := []string{"inspect", target}

if err := shell.Run("skopeo", nil, &stdout, nil, args...); err != nil {
return nil, err
}

output := stdout.Bytes()

var info interface{}

if err := json.Unmarshal(output, &info); err != nil {
return nil, err
}

m := info.(map[string]interface{})
var totalSize float64 = 0
for k, v := range m {

if k == "LayersData" {
vv := v.([]interface{})

for _, u := range vv {

uu := u.(map[string]interface{})
for j, w := range uu {

if j == "Size" {
totalSize += w.(float64)
}
}
}
}
}
totalSizeIS := (totalSize / 1000000)
return int(totalSizeIS), nil
}

func IsToolboxContainer(container string) (bool, error) {
info, err := Inspect("container", container)
if err != nil {
Expand Down
65 changes: 65 additions & 0 deletions src/pkg/skopeo/skopeo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright © 2019 – 2022 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"
)

func Inspect(typearg string, target string) (interface{}, error) {

var stdout bytes.Buffer

args := []string{"inspect", target}

if err := shell.Run("skopeo", nil, &stdout, nil, args...); err != nil {
return nil, err
}

output := stdout.Bytes()

var info interface{}

if err := json.Unmarshal(output, &info); err != nil {
return nil, err
}

m := info.(map[string]interface{})
var totalSize float64 = 0
for k, v := range m {

if k == "LayersData" {
vv := v.([]interface{})

for _, u := range vv {

uu := u.(map[string]interface{})
for j, w := range uu {

if j == "Size" {
totalSize += w.(float64)
}
}
}
}
}
totalSizeIS := (totalSize / 1000000)
return int(totalSizeIS), nil
}

0 comments on commit 7c1e34b

Please sign in to comment.