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

Add buf plugin update command #3482

Merged
merged 7 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 60 additions & 6 deletions private/buf/bufcli/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,40 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmoduleapi"
"github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmodulecache"
"github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmodulestore"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/bufpkg/bufplugin/bufpluginapi"
"github.com/bufbuild/buf/private/bufpkg/bufplugin/bufplugincache"
"github.com/bufbuild/buf/private/bufpkg/bufplugin/bufpluginstore"
"github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule"
"github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiowner"
"github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiplugin"
"github.com/bufbuild/buf/private/pkg/app/appext"
"github.com/bufbuild/buf/private/pkg/filelock"
"github.com/bufbuild/buf/private/pkg/normalpath"
"github.com/bufbuild/buf/private/pkg/storage/storageos"
)

var (
// AllCacheModuleRelDirPaths are all directory paths for all time concerning the module cache.
// AllCacheRelDirPaths are all directory paths for all time
// concerning the module and plugin caches.
//
// These are normalized.
// These are relative to container.CacheDirPath().
//
// This variable is used for clearing the cache.
AllCacheModuleRelDirPaths = []string{
v1beta1CacheModuleDataRelDirPath,
v1beta1CacheModuleLockRelDirPath,
AllCacheRelDirPaths = []string{
v1CacheModuleDataRelDirPath,
v1CacheModuleLockRelDirPath,
v1CacheModuleSumRelDirPath,
v1beta1CacheModuleDataRelDirPath,
v1beta1CacheModuleLockRelDirPath,
v2CacheModuleRelDirPath,
v3CacheModuleRelDirPath,
v3CacheCommitsRelDirPath,
v3CacheWKTRelDirPath,
v3CacheModuleLockRelDirPath,
v3CacheModuleRelDirPath,
v3CachePluginRelDirPath,
v3CacheWKTRelDirPath,
v3CacheWasmRuntimeRelDirPath,
}

// v1CacheModuleDataRelDirPath is the relative path to the cache directory where module data
Expand Down Expand Up @@ -103,6 +111,10 @@ var (
//
// Normalized.
v3CacheModuleLockRelDirPath = normalpath.Join("v3", "modulelocks")
// v3CachePluginRelDirPath is the relative path to the files cache directory in its newest iteration.
//
// Normalized.
v3CachePluginRelDirPath = normalpath.Join("v3", "plugins")
// v3CacheWasmRuntimeRelDirPath is the relative path to the Wasm runtime cache directory in its newest iteration.
// This directory is used to store the Wasm runtime cache. This is an implementation specific cache and opaque outside of the runtime.
//
Expand Down Expand Up @@ -146,6 +158,21 @@ func NewCommitProvider(container appext.Container) (bufmodule.CommitProvider, er
)
}

// NewPluginDataProvider returns a new PluginDataProvider while creating the
// required cache directories.
func NewPluginDataProvider(container appext.Container) (bufplugin.PluginDataProvider, error) {
clientConfig, err := NewConnectClientConfig(container)
if err != nil {
return nil, err
}
return newPluginDataProvider(
container,
bufregistryapiplugin.NewClientProvider(
clientConfig,
),
)
}

// CreateWasmRuntimeCacheDir creates the cache directory for the Wasm runtime.
//
// This is used by the Wasm runtime to cache compiled Wasm plugins. This is an
Expand Down Expand Up @@ -241,6 +268,33 @@ func newCommitProvider(
), nil
}

func newPluginDataProvider(
container appext.Container,
pluginClientProvider bufregistryapiplugin.ClientProvider,
) (bufplugin.PluginDataProvider, error) {
if err := createCacheDir(container.CacheDirPath(), v3CachePluginRelDirPath); err != nil {
return nil, err
}
fullCacheDirPath := normalpath.Join(container.CacheDirPath(), v3CachePluginRelDirPath)
storageosProvider := storageos.NewProvider() // No symlinks.
cacheBucket, err := storageosProvider.NewReadWriteBucket(fullCacheDirPath)
if err != nil {
return nil, err
}
delegateModuleDataProvider := bufpluginapi.NewPluingDataProvider(
container.Logger(),
pluginClientProvider,
)
return bufplugincache.NewPluginDataProvider(
container.Logger(),
delegateModuleDataProvider,
bufpluginstore.NewPluginDataStore(
container.Logger(),
cacheBucket,
),
), nil
}

func createCacheDir(baseCacheDirPath string, relDirPath string) error {
baseCacheDirPath = normalpath.Unnormalize(baseCacheDirPath)
relDirPath = normalpath.Unnormalize(relDirPath)
Expand Down
9 changes: 9 additions & 0 deletions private/buf/bufcli/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ package bufcli
import (
"github.com/bufbuild/buf/private/buf/bufctl"
"github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmoduleapi"
"github.com/bufbuild/buf/private/bufpkg/bufplugin/bufpluginapi"
"github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule"
"github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiowner"
"github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiplugin"
"github.com/bufbuild/buf/private/pkg/app/appext"
)

Expand All @@ -39,6 +41,7 @@ func NewController(
}
moduleClientProvider := bufregistryapimodule.NewClientProvider(clientConfig)
ownerClientProvider := bufregistryapiowner.NewClientProvider(clientConfig)
pluginClientProvider := bufregistryapiplugin.NewClientProvider(clientConfig)
moduleDataProvider, err := newModuleDataProvider(container, moduleClientProvider, ownerClientProvider)
if err != nil {
return nil, err
Expand All @@ -47,6 +50,10 @@ func NewController(
if err != nil {
return nil, err
}
pluginDataProvider, err := newPluginDataProvider(container, pluginClientProvider)
if err != nil {
return nil, err
}
wktStore, err := NewWKTStore(container)
if err != nil {
return nil, err
Expand All @@ -58,6 +65,8 @@ func NewController(
bufmoduleapi.NewModuleKeyProvider(container.Logger(), moduleClientProvider),
moduleDataProvider,
commitProvider,
bufpluginapi.NewPluginKeyProvider(container.Logger(), pluginClientProvider),
pluginDataProvider,
wktStore,
// TODO FUTURE: Delete defaultHTTPClient and use the one from newConfig
defaultHTTPClient,
Expand Down
36 changes: 36 additions & 0 deletions private/buf/bufcli/plugin_key_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2020-2024 Buf Technologies, 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 bufcli

import (
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/bufpkg/bufplugin/bufpluginapi"
"github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiplugin"
"github.com/bufbuild/buf/private/pkg/app/appext"
)

// NewPluginKeyProvider returns a new PluginKeyProvider.
func NewPluginKeyProvider(container appext.Container) (bufplugin.PluginKeyProvider, error) {
clientConfig, err := NewConnectClientConfig(container)
if err != nil {
return nil, err
}
return bufpluginapi.NewPluginKeyProvider(
container.Logger(),
bufregistryapiplugin.NewClientProvider(
clientConfig,
),
), nil
}
11 changes: 11 additions & 0 deletions private/buf/bufctl/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufimage/bufimageutil"
"github.com/bufbuild/buf/private/bufpkg/bufmodule"
"github.com/bufbuild/buf/private/bufpkg/bufparse"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/bufpkg/bufreflect"
"github.com/bufbuild/buf/private/gen/data/datawkt"
imagev1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/image/v1"
Expand Down Expand Up @@ -136,6 +137,8 @@ func NewController(
moduleKeyProvider bufmodule.ModuleKeyProvider,
moduleDataProvider bufmodule.ModuleDataProvider,
commitProvider bufmodule.CommitProvider,
pluginKeyProvider bufplugin.PluginKeyProvider,
pluginDataProvider bufplugin.PluginDataProvider,
wktStore bufwktstore.Store,
httpClient *http.Client,
httpauthAuthenticator httpauth.Authenticator,
Expand All @@ -149,6 +152,8 @@ func NewController(
moduleKeyProvider,
moduleDataProvider,
commitProvider,
pluginKeyProvider,
pluginDataProvider,
wktStore,
httpClient,
httpauthAuthenticator,
Expand All @@ -170,6 +175,8 @@ type controller struct {
moduleDataProvider bufmodule.ModuleDataProvider
graphProvider bufmodule.GraphProvider
commitProvider bufmodule.CommitProvider
pluginKeyProvider bufplugin.PluginKeyProvider
pluginDataProvider bufplugin.PluginDataProvider
wktStore bufwktstore.Store

disableSymlinks bool
Expand All @@ -192,6 +199,8 @@ func newController(
moduleKeyProvider bufmodule.ModuleKeyProvider,
moduleDataProvider bufmodule.ModuleDataProvider,
commitProvider bufmodule.CommitProvider,
pluginKeyProvider bufplugin.PluginKeyProvider,
pluginDataProvider bufplugin.PluginDataProvider,
wktStore bufwktstore.Store,
httpClient *http.Client,
httpauthAuthenticator httpauth.Authenticator,
Expand All @@ -204,6 +213,8 @@ func newController(
graphProvider: graphProvider,
moduleDataProvider: moduleDataProvider,
commitProvider: commitProvider,
pluginKeyProvider: pluginKeyProvider,
pluginDataProvider: pluginDataProvider,
wktStore: wktStore,
}
for _, option := range options {
Expand Down
2 changes: 2 additions & 0 deletions private/buf/bufmigrate/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ func (m *migrator) buildBufYAMLAndBufLockFiles(
bufLock, err = bufconfig.NewBufLockFile(
bufconfig.FileVersionV2,
resolvedLockEntries,
nil,
)
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -444,6 +445,7 @@ func (m *migrator) buildBufYAMLAndBufLockFiles(
bufLock, err = bufconfig.NewBufLockFile(
bufconfig.FileVersionV2,
resolvedDepModuleKeys,
nil, // Plugins are not supported in v1.
)
if err != nil {
return nil, nil, err
Expand Down
Loading
Loading