-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: cuisongliu <cuisongliu@qq.com>
- Loading branch information
1 parent
33663d0
commit b5db3fd
Showing
11 changed files
with
114 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright © 2021 Alibaba Group Holding Ltd. | ||
// | ||
// 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 buildimage | ||
|
||
import ( | ||
"fmt" | ||
"github.com/labring/sreg/pkg/utils/file" | ||
"github.com/labring/sreg/pkg/utils/logger" | ||
"path" | ||
"strings" | ||
) | ||
|
||
func TarList(dir string) ([]string, error) { | ||
wrapGetImageErr := func(err error, s string) error { | ||
return fmt.Errorf("failed to get images in %s: %w", s, err) | ||
} | ||
tarDir := path.Join(dir, ImagesDirName, ImageSkopeoDirName) | ||
if !file.IsExist(path.Join(tarDir, ImageTarConfigName)) { | ||
logger.Warn("image tar config %s is not exists,skip", path.Join(tarDir, ImageTarConfigName)) | ||
return nil, nil | ||
} | ||
|
||
images, err := file.ReadLines(path.Join(tarDir, ImageTarConfigName)) | ||
if err != nil { | ||
return nil, wrapGetImageErr(err, tarDir) | ||
} | ||
for i, image := range images { | ||
parts := strings.SplitN(image, "@", 2) | ||
if len(parts) != 2 { | ||
return nil, fmt.Errorf("invalid image format: %s", image) | ||
} | ||
if strings.HasPrefix(parts[0], "docker-archive:") || strings.HasPrefix(parts[0], "oci-archive:") { | ||
partOne := parts[0] | ||
|
||
partOneSpilt := strings.SplitN(partOne, ":", 2) | ||
if len(partOneSpilt) == 2 { | ||
originalPath := partOneSpilt[1] | ||
// 将原始路径和路径部分组合 | ||
modifiedPath := path.Join(tarDir, originalPath) | ||
// 重新构建 partOne | ||
partOne = partOneSpilt[0] + ":" + modifiedPath | ||
} | ||
parts[0] = partOne | ||
images[i] = strings.Join(parts, "@") | ||
} else { | ||
return nil, fmt.Errorf("invalid image format: %s , must prefix in docker-archive or oci-archive", image) | ||
} | ||
} | ||
return images, nil | ||
} |
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,29 @@ | ||
/* | ||
Copyright 2023 cuisongliu@qq.com. | ||
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 buildimage | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestTarList(t *testing.T) { | ||
data, err := TarList("test/testregistrytar") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
t.Log(data) | ||
} |
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 @@ | ||
docker.io/library/busybox:latest |
File renamed without changes.
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 @@ | ||
docker-archive:config_main.tar@library/config_main |
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,5 @@ | ||
registry.k8s.io/autoscaling/vpa-admission-controller:0.13.0 | ||
registry.k8s.io/autoscaling/vpa-recommender:0.13.0 | ||
registry.k8s.io/autoscaling/vpa-updater:0.13.0 | ||
registry.k8s.io/redis:e2e | ||
registry.k8s.io/ubuntu-slim:0.1 |
Binary file not shown.
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 @@ | ||
docker-archive:config_main.tar@library/config_main |