Merge pull request #441 from tonistiigi/buildkit-pull-creds2

refactor driver auth for easier passing
This commit is contained in:
Tõnis Tiigi
2020-12-05 00:02:38 -08:00
committed by GitHub
9 changed files with 23 additions and 18 deletions

View File

@@ -32,12 +32,12 @@ type Driver struct {
env []string
}
func (d *Driver) Bootstrap(ctx context.Context, auth driver.Auth, l progress.Logger) error {
func (d *Driver) Bootstrap(ctx context.Context, l progress.Logger) error {
return progress.Wrap("[internal] booting buildkit", l, func(sub progress.SubLogger) error {
_, err := d.DockerAPI.ContainerInspect(ctx, d.Name)
if err != nil {
if dockerclient.IsErrNotFound(err) {
return d.create(ctx, auth, sub)
return d.create(ctx, sub)
}
return err
}
@@ -53,14 +53,14 @@ func (d *Driver) Bootstrap(ctx context.Context, auth driver.Auth, l progress.Log
})
}
func (d *Driver) create(ctx context.Context, auth driver.Auth, l progress.SubLogger) error {
func (d *Driver) create(ctx context.Context, l progress.SubLogger) error {
imageName := bkimage.DefaultImage
if d.image != "" {
imageName = d.image
}
if err := l.Wrap("pulling image "+imageName, func() error {
ra, err := imagetools.RegistryAuthForRef(imageName, auth)
ra, err := imagetools.RegistryAuthForRef(imageName, d.Auth)
if err != nil {
return err
}

View File

@@ -15,7 +15,7 @@ type Driver struct {
driver.InitConfig
}
func (d *Driver) Bootstrap(ctx context.Context, _ driver.Auth, l progress.Logger) error {
func (d *Driver) Bootstrap(ctx context.Context, l progress.Logger) error {
return nil
}

View File

@@ -51,7 +51,7 @@ type Auth interface {
type Driver interface {
Factory() Factory
Bootstrap(context.Context, Auth, progress.Logger) error
Bootstrap(context.Context, progress.Logger) error
Info(context.Context) (*Info, error)
Stop(ctx context.Context, force bool) error
Rm(ctx context.Context, force bool) error
@@ -59,7 +59,7 @@ type Driver interface {
Features() map[Feature]bool
}
func Boot(ctx context.Context, d Driver, auth Auth, pw progress.Writer) (*client.Client, error) {
func Boot(ctx context.Context, d Driver, pw progress.Writer) (*client.Client, error) {
try := 0
for {
info, err := d.Info(ctx)
@@ -71,7 +71,7 @@ func Boot(ctx context.Context, d Driver, auth Auth, pw progress.Writer) (*client
if try > 2 {
return nil, errors.Errorf("failed to bootstrap %T driver in attempts", d)
}
if err := d.Bootstrap(ctx, auth, func(s *client.SolveStatus) {
if err := d.Bootstrap(ctx, func(s *client.SolveStatus) {
if pw != nil {
pw.Status() <- s
}

View File

@@ -44,7 +44,7 @@ type Driver struct {
podChooser podchooser.PodChooser
}
func (d *Driver) Bootstrap(ctx context.Context, auth driver.Auth, l progress.Logger) error {
func (d *Driver) Bootstrap(ctx context.Context, l progress.Logger) error {
return progress.Wrap("[internal] booting buildkit", l, func(sub progress.SubLogger) error {
_, err := d.deploymentClient.Get(ctx, d.deployment.Name, metav1.GetOptions{})
if err != nil {

View File

@@ -52,6 +52,7 @@ type InitConfig struct {
BuildkitFlags []string
ConfigFile string
DriverOpts map[string]string
Auth Auth
// ContextPathHash can be used for determining pods in the driver instance
ContextPathHash string
}
@@ -98,7 +99,7 @@ func GetFactory(name string, instanceRequired bool) Factory {
return nil
}
func GetDriver(ctx context.Context, name string, f Factory, api dockerclient.APIClient, kcc KubeClientConfig, flags []string, config string, do map[string]string, contextPathHash string) (Driver, error) {
func GetDriver(ctx context.Context, name string, f Factory, api dockerclient.APIClient, auth Auth, kcc KubeClientConfig, flags []string, config string, do map[string]string, contextPathHash string) (Driver, error) {
ic := InitConfig{
DockerAPI: api,
KubeClientConfig: kcc,
@@ -106,6 +107,7 @@ func GetDriver(ctx context.Context, name string, f Factory, api dockerclient.API
BuildkitFlags: flags,
ConfigFile: config,
DriverOpts: do,
Auth: auth,
ContextPathHash: contextPathHash,
}
if f == nil {