-
Notifications
You must be signed in to change notification settings - Fork 18
/
pullhelper.go
41 lines (33 loc) · 1 KB
/
pullhelper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package pullhelper
import (
"context"
"github.com/cirruslabs/cirrus-cli/internal/executor/instance/containerbackend"
"github.com/cirruslabs/cirrus-cli/internal/executor/options"
"github.com/cirruslabs/cirrus-cli/pkg/api"
"github.com/cirruslabs/echelon"
"github.com/cirruslabs/echelon/renderers"
)
func PullHelper(
ctx context.Context,
reference string,
architecture *api.Architecture,
backend containerbackend.ContainerBackend,
copts options.ContainerOptions,
logger *echelon.Logger,
) error {
if !copts.ShouldPullImage(ctx, backend, reference) {
return nil
}
if logger == nil {
logger = echelon.NewLogger(echelon.ErrorLevel, &renderers.StubRenderer{})
}
dockerPullLogger := logger.Scoped("image pull")
dockerPullLogger.Infof("Pulling image %s...", reference)
if err := backend.ImagePull(ctx, reference, architecture); err != nil {
dockerPullLogger.Errorf("Failed to pull %s: %v", reference, err)
dockerPullLogger.Finish(false)
return err
}
dockerPullLogger.Finish(true)
return nil
}