diff --git a/dktest.go b/dktest.go index 21c8da7..4fbabb1 100644 --- a/dktest.go +++ b/dktest.go @@ -31,11 +31,14 @@ const ( label = "dktest" ) -func pullImage(ctx context.Context, lgr Logger, dc client.ImageAPIClient, imgName, platform string) error { +func pullImage(ctx context.Context, lgr Logger, dc client.ImageAPIClient, registryAuth, imgName, platform string) error { lgr.Log("Pulling image:", imgName) // lgr.Log(dc.ImageList(ctx, types.ImageListOptions{All: true})) - resp, err := dc.ImagePull(ctx, imgName, image.PullOptions{Platform: platform}) + resp, err := dc.ImagePull(ctx, imgName, image.PullOptions{ + Platform: platform, + RegistryAuth: registryAuth, + }) if err != nil { return err } @@ -202,7 +205,7 @@ func RunContext(ctx context.Context, logger Logger, imgName string, opts Options pullCtx, pullTimeoutCancelFunc := context.WithTimeout(ctx, opts.PullTimeout) defer pullTimeoutCancelFunc() - if err := pullImage(pullCtx, logger, dc, imgName, opts.Platform); err != nil { + if err := pullImage(pullCtx, logger, dc, opts.PullRegistryAuth, imgName, opts.Platform); err != nil { return fmt.Errorf("error pulling image: %v error: %w", imgName, err) } diff --git a/dktest_internal_test.go b/dktest_internal_test.go index 5547bdd..15d95f1 100644 --- a/dktest_internal_test.go +++ b/dktest_internal_test.go @@ -63,7 +63,7 @@ func TestPullImage(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { client := tc.client - err := pullImage(ctx, t, &client, imageName, tc.platform) + err := pullImage(ctx, t, &client, "", imageName, tc.platform) testErr(t, err, tc.expectErr) }) } diff --git a/options.go b/options.go index 09f2910..6ff1337 100644 --- a/options.go +++ b/options.go @@ -12,6 +12,8 @@ import ( type Options struct { // PullTimeout is the timeout used when pulling images PullTimeout time.Duration + // PullRegistryAuth is the base64 encoded credentials for the registry + PullRegistryAuth string // Timeout is the timeout used when starting a container and checking if it's ready Timeout time.Duration // ReadyTimeout is the timeout used for each container ready check.