Skip to content

Commit 0e2cf78

Browse files
authored
Merge pull request #42 from wybczu/luk/add-auth-support
feat: pass registry auth option to `imagePull` func
2 parents a1beb96 + 66dd568 commit 0e2cf78

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

dktest.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ const (
3131
label = "dktest"
3232
)
3333

34-
func pullImage(ctx context.Context, lgr Logger, dc client.ImageAPIClient, imgName, platform string) error {
34+
func pullImage(ctx context.Context, lgr Logger, dc client.ImageAPIClient, registryAuth, imgName, platform string) error {
3535
lgr.Log("Pulling image:", imgName)
3636
// lgr.Log(dc.ImageList(ctx, types.ImageListOptions{All: true}))
3737

38-
resp, err := dc.ImagePull(ctx, imgName, image.PullOptions{Platform: platform})
38+
resp, err := dc.ImagePull(ctx, imgName, image.PullOptions{
39+
Platform: platform,
40+
RegistryAuth: registryAuth,
41+
})
3942
if err != nil {
4043
return err
4144
}
@@ -202,7 +205,7 @@ func RunContext(ctx context.Context, logger Logger, imgName string, opts Options
202205
pullCtx, pullTimeoutCancelFunc := context.WithTimeout(ctx, opts.PullTimeout)
203206
defer pullTimeoutCancelFunc()
204207

205-
if err := pullImage(pullCtx, logger, dc, imgName, opts.Platform); err != nil {
208+
if err := pullImage(pullCtx, logger, dc, opts.PullRegistryAuth, imgName, opts.Platform); err != nil {
206209
return fmt.Errorf("error pulling image: %v error: %w", imgName, err)
207210
}
208211

dktest_internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestPullImage(t *testing.T) {
6363
for _, tc := range testCases {
6464
t.Run(tc.name, func(t *testing.T) {
6565
client := tc.client
66-
err := pullImage(ctx, t, &client, imageName, tc.platform)
66+
err := pullImage(ctx, t, &client, "", imageName, tc.platform)
6767
testErr(t, err, tc.expectErr)
6868
})
6969
}

options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
type Options struct {
1313
// PullTimeout is the timeout used when pulling images
1414
PullTimeout time.Duration
15+
// PullRegistryAuth is the base64 encoded credentials for the registry
16+
PullRegistryAuth string
1517
// Timeout is the timeout used when starting a container and checking if it's ready
1618
Timeout time.Duration
1719
// ReadyTimeout is the timeout used for each container ready check.

0 commit comments

Comments
 (0)