Skip to content

Commit

Permalink
fix: keep the digest of an image on fly m create
Browse files Browse the repository at this point in the history
This change fixes `fly pg create` too.
  • Loading branch information
kzys committed Jan 30, 2025
1 parent ba7ebb3 commit 568c347
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
15 changes: 10 additions & 5 deletions internal/build/imgsrc/remote_image_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import (
"fmt"
"strconv"

"github.com/superfly/flyctl/internal/flyutil"
"github.com/superfly/fly-go"
"github.com/superfly/flyctl/internal/tracing"
"github.com/superfly/flyctl/iostreams"
"go.opentelemetry.io/otel/trace"
)

type flyClient interface {
ResolveImageForApp(ctx context.Context, appName, imageRef string) (*fly.Image, error)
}

type remoteImageResolver struct {
flyApi flyutil.Client
flyApi flyClient
}

func (*remoteImageResolver) Name() string {
Expand Down Expand Up @@ -46,9 +50,10 @@ func (s *remoteImageResolver) Run(ctx context.Context, _ *dockerClientFactory, s
}

di := &DeploymentImage{
ID: img.ID,
Tag: img.Ref,
Size: int64(size),
ID: img.ID,
Tag: img.Ref,
Digest: img.Digest,
Size: int64(size),
}

span.SetAttributes(di.ToSpanAttributes()...)
Expand Down
8 changes: 8 additions & 0 deletions internal/build/imgsrc/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,19 @@ func (ro RefOptions) ToSpanAttributes() []attribute.KeyValue {
type DeploymentImage struct {
ID string
Tag string
Digest string
Size int64
BuildID string
Labels map[string]string
}

func (image *DeploymentImage) String() string {
if image.Digest == "" {
return image.Tag
}
return fmt.Sprintf("%s@%s", image.Tag, image.Digest)
}

func (di DeploymentImage) ToSpanAttributes() []attribute.KeyValue {
attrs := []attribute.KeyValue{
attribute.String("image.id", di.ID),
Expand Down
13 changes: 13 additions & 0 deletions internal/build/imgsrc/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ import (
"github.com/superfly/flyctl/internal/config"
)

func TestDeploymentImage(t *testing.T) {
image := &DeploymentImage{
ID: "img_8rlxp2nzn32np3jq",
Tag: "docker-hub-mirror.fly.io/flyio/postgres-flex:16",
Digest: "sha256:f107dbfaa732063b31ee94aa728c4f5648a672259fd62bfaa245f9b7a53b5479",
Size: 123,
}
assert.Equal(t, "docker-hub-mirror.fly.io/flyio/postgres-flex:16@sha256:f107dbfaa732063b31ee94aa728c4f5648a672259fd62bfaa245f9b7a53b5479", image.String())

image.Digest = ""
assert.Equal(t, "docker-hub-mirror.fly.io/flyio/postgres-flex:16", image.String())
}

func TestHeartbeat(t *testing.T) {
dc, err := client.NewClientWithOpts()
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion internal/command/command_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func DetermineImage(ctx context.Context, appName string, imageOrPath string) (im
return nil, errors.New("could not find an image to deploy")
}

fmt.Fprintf(io.Out, "Image: %s\n", img.Tag)
fmt.Fprintf(io.Out, "Image: %s\n", img.String())
fmt.Fprintf(io.Out, "Image size: %s\n\n", humanize.Bytes(uint64(img.Size)))

return img, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/command/machine/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ func determineMachineConfig(
if err != nil {
return machineConf, err
}
machineConf.Image = img.Tag
machineConf.Image = img.String()
}

// Service updates
Expand Down

0 comments on commit 568c347

Please sign in to comment.