
We can use cross repository push feature to reuse the existing blobs in the same registry. Before make push fast, we know where the blob comes from. Use the `containerd.io/distribution.source. = [,]` as label format. For example, the blob is downloaded by the docker.io/library/busybox:latest and the label will be containerd.io/distribution.source.docker.io = library/busybox If the blob is shared by different repos in the same registry, the repo name will be appended, like: containerd.io/distribution.source.docker.io = library/busybox,x/y NOTE: 1. no need to apply for legacy docker image schema1. 2. the concurrent fetch actions might miss some repo names in label, but it is ok. 3. it is optional. no need to add label if the engine only uses images not push. Signed-off-by: Wei Fu <fuweid89@gmail.com>
68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
/*
|
|
Copyright The containerd Authors.
|
|
|
|
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 docker
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestAppendDistributionLabel(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
originLabel string
|
|
repo string
|
|
expected string
|
|
}{
|
|
{
|
|
originLabel: "",
|
|
repo: "",
|
|
expected: "",
|
|
},
|
|
{
|
|
originLabel: "",
|
|
repo: "library/busybox",
|
|
expected: "library/busybox",
|
|
},
|
|
{
|
|
originLabel: "library/busybox",
|
|
repo: "library/busybox",
|
|
expected: "library/busybox",
|
|
},
|
|
// remove the duplicate one in origin
|
|
{
|
|
originLabel: "library/busybox,library/redis,library/busybox",
|
|
repo: "library/alpine",
|
|
expected: "library/alpine,library/busybox,library/redis",
|
|
},
|
|
// remove the empty repo
|
|
{
|
|
originLabel: "library/busybox,library/redis,library/busybox",
|
|
repo: "",
|
|
expected: "library/busybox,library/redis",
|
|
},
|
|
{
|
|
originLabel: "library/busybox,library/redis,library/busybox",
|
|
repo: "library/redis",
|
|
expected: "library/busybox,library/redis",
|
|
},
|
|
} {
|
|
if got := appendDistributionSourceLabel(tc.originLabel, tc.repo); !reflect.DeepEqual(got, tc.expected) {
|
|
t.Fatalf("expected %v, but got %v", tc.expected, got)
|
|
}
|
|
}
|
|
}
|