-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3194 from tonistiigi/update-from-v0.10.5
Bring in patches from v0.10.5
- Loading branch information
Showing
7 changed files
with
280 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
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,34 @@ | ||
package contentutil | ||
|
||
import ( | ||
"net/url" | ||
"strings" | ||
|
||
"github.com/containerd/containerd/content" | ||
"github.com/containerd/containerd/reference" | ||
) | ||
|
||
func HasSource(info content.Info, refspec reference.Spec) (bool, error) { | ||
u, err := url.Parse("dummy://" + refspec.Locator) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
if info.Labels == nil { | ||
return false, nil | ||
} | ||
|
||
source, target := u.Hostname(), strings.TrimPrefix(u.Path, "/") | ||
repoLabel, ok := info.Labels["containerd.io/distribution.source."+source] | ||
if !ok || repoLabel == "" { | ||
return false, nil | ||
} | ||
|
||
for _, repo := range strings.Split(repoLabel, ",") { | ||
// the target repo is not a candidate | ||
if repo == target { | ||
return true, nil | ||
} | ||
} | ||
return false, 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,57 @@ | ||
package contentutil | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/containerd/containerd/content" | ||
"github.com/containerd/containerd/reference" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestHasSource(t *testing.T) { | ||
info := content.Info{ | ||
Labels: map[string]string{ | ||
"containerd.io/distribution.source.docker.io": "library/alpine", | ||
}, | ||
} | ||
ref, err := reference.Parse("docker.io/library/alpine:latest") | ||
require.NoError(t, err) | ||
b, err := HasSource(info, ref) | ||
require.NoError(t, err) | ||
require.True(t, b) | ||
|
||
info = content.Info{ | ||
Labels: map[string]string{ | ||
"containerd.io/distribution.source.docker.io": "library/alpine,library/ubuntu", | ||
}, | ||
} | ||
b, err = HasSource(info, ref) | ||
require.NoError(t, err) | ||
require.True(t, b) | ||
|
||
info = content.Info{} | ||
b, err = HasSource(info, ref) | ||
require.NoError(t, err) | ||
require.False(t, b) | ||
|
||
info = content.Info{Labels: map[string]string{}} | ||
b, err = HasSource(info, ref) | ||
require.NoError(t, err) | ||
require.False(t, b) | ||
|
||
info = content.Info{ | ||
Labels: map[string]string{ | ||
"containerd.io/distribution.source.docker.io": "library/ubuntu", | ||
}, | ||
} | ||
b, err = HasSource(info, ref) | ||
require.NoError(t, err) | ||
require.False(t, b) | ||
|
||
info = content.Info{Labels: map[string]string{ | ||
"containerd.io/distribution.source.ghcr.io": "library/alpine", | ||
}} | ||
b, err = HasSource(info, ref) | ||
require.NoError(t, err) | ||
require.False(t, b) | ||
} |
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