-
Notifications
You must be signed in to change notification settings - Fork 246
/
remote_image_resolver.go
57 lines (45 loc) · 1.46 KB
/
remote_image_resolver.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package imgsrc
import (
"context"
"fmt"
"strconv"
"github.com/superfly/flyctl/internal/flyutil"
"github.com/superfly/flyctl/internal/tracing"
"github.com/superfly/flyctl/iostreams"
"go.opentelemetry.io/otel/trace"
)
type remoteImageResolver struct {
flyApi flyutil.Client
}
func (*remoteImageResolver) Name() string {
return "Remote Image Reference"
}
func (s *remoteImageResolver) Run(ctx context.Context, _ *dockerClientFactory, streams *iostreams.IOStreams, opts RefOptions, build *build) (*DeploymentImage, string, error) {
ctx, span := tracing.GetTracer().Start(ctx, "remote_image_resolver", trace.WithAttributes(opts.ToSpanAttributes()...))
defer span.End()
fmt.Fprintf(streams.ErrOut, "Searching for image '%s' remotely...\n", opts.ImageRef)
build.BuildStart()
img, err := s.flyApi.ResolveImageForApp(ctx, opts.AppName, opts.ImageRef)
build.BuildFinish()
if err != nil {
tracing.RecordError(span, err, "failed to resolve image")
return nil, "", err
}
if img == nil {
span.AddEvent("no image found and no error occurred")
return nil, "no image found and no error occurred", nil
}
fmt.Fprintf(streams.ErrOut, "image found: %s\n", img.ID)
size, err := strconv.ParseUint(img.CompressedSize, 10, 64)
if err != nil {
tracing.RecordError(span, err, "failed to parse size")
return nil, "", err
}
di := &DeploymentImage{
ID: img.ID,
Tag: img.Ref,
Size: int64(size),
}
span.SetAttributes(di.ToSpanAttributes()...)
return di, "", nil
}