Skip to content

Commit c8f04f9

Browse files
authored
use os cmd to pull (#2413)
use os cmd to pull
1 parent e80214f commit c8f04f9

File tree

3 files changed

+14
-27
lines changed

3 files changed

+14
-27
lines changed

framework/.changeset/v0.14.5.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Use docker pull command to work with creds in CI via env vars

framework/cmd/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,13 @@ Be aware that any TODO requires your attention before your run the final test!
363363
// reverse and skip current version
364364
slices.Reverse(tags)
365365
tags = tags[1:]
366-
// TODO: remove it with real tags when they match
367366
for _, tag := range tags {
368367
tagToPull := strings.ReplaceAll(tag, "+compat", "")
369368
for i := range nodes {
370-
err := framework.UpgradeContainer(
369+
if err := framework.UpgradeContainer(
371370
c.Context,
372371
fmt.Sprintf("don-node%d", i),
373-
fmt.Sprintf("%s:%s", registry, tagToPull))
374-
if err != nil {
372+
fmt.Sprintf("%s:%s", registry, tagToPull)); err != nil {
375373
return err
376374
}
377375
}

framework/compat.go

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@ import (
66
"fmt"
77
"io"
88
"net/http"
9-
"os"
109
"sort"
1110
"strings"
1211

1312
"github.com/docker/docker/api/types/container"
14-
"github.com/docker/docker/api/types/image"
1513
"github.com/docker/docker/api/types/network"
1614
"github.com/docker/docker/client"
17-
"github.com/rs/zerolog"
1815

1916
"github.com/Masterminds/semver/v3"
2017
)
@@ -26,11 +23,11 @@ import (
2623

2724
// UpgradeContainer stops a container, removes it, and creates a new one with the specified image
2825
func UpgradeContainer(ctx context.Context, containerName, newImage string) error {
29-
L = L.With().
26+
l := L.With().
3027
Str("Container", containerName).
3128
Str("Image", newImage).
3229
Logger()
33-
L.Info().Msg("Upgrading container")
30+
l.Info().Msg("Upgrading container")
3431
cli, err := client.NewClientWithOpts(
3532
client.FromEnv,
3633
client.WithAPIVersionNegotiation(),
@@ -43,31 +40,22 @@ func UpgradeContainer(ctx context.Context, containerName, newImage string) error
4340
if err != nil {
4441
return fmt.Errorf("failed to inspect container %s: %w", containerName, err)
4542
}
46-
L.Debug().Msg("Stopping container")
43+
l.Debug().Msg("Stopping container")
4744
stopOpts := container.StopOptions{}
4845
if err := cli.ContainerStop(ctx, containerName, stopOpts); err != nil {
4946
return fmt.Errorf("failed to stop container %s: %w", containerName, err)
5047
}
51-
L.Debug().Msg("Removing container")
48+
l.Debug().Msg("Removing container")
5249
// keep the volumes
5350
removeOpts := container.RemoveOptions{RemoveVolumes: false}
5451
if err := cli.ContainerRemove(ctx, containerName, removeOpts); err != nil {
5552
return fmt.Errorf("failed to remove container %s: %w", containerName, err)
5653
}
57-
L.Debug().Msg("Pulling new image")
58-
pullReader, err := cli.ImagePull(ctx, newImage, image.PullOptions{})
59-
if err != nil {
54+
l.Debug().Msg("Pulling new image")
55+
if _, err := ExecCmdWithContext(ctx, fmt.Sprintf("docker pull %s", newImage)); err != nil {
6056
return fmt.Errorf("failed to pull image %s: %w", newImage, err)
6157
}
62-
defer pullReader.Close()
63-
64-
// log pull process for debug
65-
if L.GetLevel() <= zerolog.DebugLevel {
66-
_, _ = io.Copy(os.Stdout, pullReader)
67-
} else {
68-
_, _ = io.Copy(io.Discard, pullReader)
69-
}
70-
L.Debug().Msg("Image pulled successfully")
58+
l.Debug().Msg("Image pulled successfully")
7159

7260
inspect.Config.Image = newImage
7361

@@ -89,15 +77,15 @@ func UpgradeContainer(ctx context.Context, containerName, newImage string) error
8977
if err != nil {
9078
return fmt.Errorf("failed to create container with image %s: %w", newImage, err)
9179
}
92-
L.Debug().
80+
l.Debug().
9381
Str("ContainerID", createResp.ID).
9482
Msg("Container created")
95-
L.Debug().Msg("Starting new container")
83+
l.Debug().Msg("Starting new container")
9684
startOpts := container.StartOptions{}
9785
if err := cli.ContainerStart(ctx, createResp.ID, startOpts); err != nil {
9886
return fmt.Errorf("failed to start container %s: %w", containerName, err)
9987
}
100-
L.Info().
88+
l.Info().
10189
Str("ContainerID", createResp.ID[:12]).
10290
Msg("Container successfully rebooted with new image")
10391
return nil
@@ -290,4 +278,4 @@ func matchesFilter(version string, include, exclude []string) bool {
290278
}
291279
}
292280
return false
293-
}
281+
}

0 commit comments

Comments
 (0)