Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dynamic plugin should support pulling image with digest #1280

Merged
merged 9 commits into from
Jan 29, 2024
9 changes: 6 additions & 3 deletions pkg/common/plugin/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,13 @@
return fmt.Errorf("unsupported manifest media type: %s", referenceManifestDescriptor.MediaType)
}

if len(referenceManifest.Blobs) == 0 {
return fmt.Errorf("no blobs found in the manifest")
}

Check warning on line 131 in pkg/common/plugin/download.go

View check run for this annotation

Codecov / codecov/patch

pkg/common/plugin/download.go#L130-L131

Added lines #L130 - L131 were not covered by tests

// download the first blob to the target path
blobReference := fmt.Sprintf("%s@%s", source, referenceManifest.Blobs[0].Digest)
logrus.Debugf("Downloading blob %s", blobReference)
_, blobReader, err := repository.Blobs().FetchReference(ctx, blobReference)
logrus.Debugf("Downloading blob %s", referenceManifest.Blobs[0].Digest.String())
_, blobReader, err := repository.Blobs().FetchReference(ctx, referenceManifest.Blobs[0].Digest.String())
if err != nil {
return err
}
Expand Down
64 changes: 41 additions & 23 deletions pkg/referrerstore/factory/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,37 +95,55 @@ func TestCreateStoresFromConfig_PluginStores_ReturnsExpected(t *testing.T) {
func TestCreateStoresFromConfig_DynamicPluginStores_ReturnsExpected(t *testing.T) {
os.Setenv("RATIFY_EXPERIMENTAL_DYNAMIC_PLUGINS", "1")
featureflag.InitFeatureFlagsFromEnv()
storeConfig := map[string]interface{}{
"name": "plugin-store",
"source": map[string]interface{}{
"artifact": "wabbitnetworks.azurecr.io/test/sample-verifier-plugin:v1",
testCases := []struct {
name string
artifact string
}{
{
name: "image specified by tag",
artifact: "wabbitnetworks.azurecr.io/test/sample-store-plugin:v1",
},
{
name: "image specified by digest",
artifact: "wabbitnetworks.azurecr.io/test/sample-store-plugin@sha256:96ba9f9636cde32df87d62dcad4e430d055e708b9f173475c5d7468b732d6566",
},
}

storesConfig := config.StoresConfig{
Stores: []config.StorePluginConfig{storeConfig},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
storeConfig := map[string]interface{}{
"name": "plugin-store",
"source": map[string]interface{}{
"artifact": tc.artifact,
},
}

stores, err := CreateStoresFromConfig(storesConfig, "")
storesConfig := config.StoresConfig{
Stores: []config.StorePluginConfig{storeConfig},
}

if err != nil {
t.Fatalf("create stores failed with err %v", err)
}
stores, err := CreateStoresFromConfig(storesConfig, "")

if len(stores) != 1 {
t.Fatalf("expected to have %d stores, actual count %d", 1, len(stores))
}
if err != nil {
t.Fatalf("create stores failed with err %v", err)
}

if stores[0].Name() != "plugin-store" {
t.Fatalf("expected to create plugin store")
}
if len(stores) != 1 {
t.Fatalf("expected to have %d stores, actual count %d", 1, len(stores))
}

if _, ok := stores[0].(*plugin.StorePlugin); !ok {
t.Fatalf("type assertion failed expected a plugin store")
}
if stores[0].Name() != "plugin-store" {
t.Fatalf("expected to create plugin store")
}

if _, ok := stores[0].(*plugin.StorePlugin); !ok {
t.Fatalf("type assertion failed expected a plugin store")
}

pluginPath := path.Join(stores[0].GetConfig().PluginBinDirs[0], stores[0].Name())
if _, err := os.Stat(pluginPath); errors.Is(err, os.ErrNotExist) {
t.Fatalf("downloaded plugin not found in path")
pluginPath := path.Join(stores[0].GetConfig().PluginBinDirs[0], stores[0].Name())
if _, err := os.Stat(pluginPath); errors.Is(err, os.ErrNotExist) {
t.Fatalf("downloaded plugin not found in path")
}
})
}
}
Loading