Skip to content

Commit

Permalink
add experimental feature to enable zstd for depot builds (#4065)
Browse files Browse the repository at this point in the history
  • Loading branch information
jipperinbham authored Nov 15, 2024
1 parent 2c7e827 commit cafc23d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/appconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ type Experimental struct {
LazyLoadImages bool `toml:"lazy_load_images,omitempty" json:"lazy_load_images,omitempty"`
Attached Attached `toml:"attached,omitempty" json:"attached,omitempty"`
MachineConfig string `toml:"machine_config,omitempty" json:"machine_config,omitempty"`
UseZstd bool `toml:"use_zstd,omitempty" json:"use_zstd,omitempty"`
}

type Attached struct {
Expand Down
6 changes: 6 additions & 0 deletions internal/build/imgsrc/depot.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ func buildImage(ctx context.Context, buildkitClient *client.Client, opts ImageOp
exportEntry.Attrs["push"] = "true"
}

if opts.UseZstd {
exportEntry.Attrs["compression"] = "zstd"
exportEntry.Attrs["compression-level"] = "3"
exportEntry.Attrs["force-compression"] = "true"
}

ch := make(chan *client.SolveStatus)
eg, ctx := errgroup.WithContext(ctx)
eg.Go(func() error {
Expand Down
2 changes: 2 additions & 0 deletions internal/build/imgsrc/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type ImageOptions struct {
BuildpacksDockerHost string
BuildpacksVolumes []string
UseOverlaybd bool
UseZstd bool
}

func (io ImageOptions) ToSpanAttributes() []attribute.KeyValue {
Expand All @@ -72,6 +73,7 @@ func (io ImageOptions) ToSpanAttributes() []attribute.KeyValue {
attribute.String("imageoptions.buildpacks_docker_host", io.BuildpacksDockerHost),
attribute.StringSlice("imageoptions.buildpacks", io.Buildpacks),
attribute.StringSlice("imageoptions.buildpacks_volumes", io.BuildpacksVolumes),
attribute.Bool("imageoptions.use_zstd", io.UseZstd),
}

if io.BuildArgs != nil {
Expand Down
9 changes: 9 additions & 0 deletions internal/command/command_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ func DetermineImage(ctx context.Context, appName string, imageOrPath string) (im
}
opts.BuildArgs = extraArgs

if cfg != nil && cfg.Experimental != nil {
opts.UseZstd = cfg.Experimental.UseZstd
}

// use-zstd passed through flags takes precedence over the one set in config
if flag.IsSpecified(ctx, "use-zstd") {
opts.UseZstd = flag.GetBool(ctx, "use-zstd")
}

img, err = resolver.BuildImage(ctx, io, opts)
if err != nil {
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions internal/command/deploy/deploy_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ func determineImage(ctx context.Context, appConfig *appconfig.Config, useWG, rec

if appConfig.Experimental != nil {
opts.UseOverlaybd = appConfig.Experimental.LazyLoadImages

opts.UseZstd = appConfig.Experimental.UseZstd
}

// flyctl supports key=value form while Docker supports id=key,src=/path/to/secret form.
Expand Down
4 changes: 4 additions & 0 deletions internal/command/machine/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ var runOrCreateFlags = flag.Set{
Description: "Enable LSVD for this machine",
Hidden: true,
},
flag.Bool{
Name: "use-zstd",
Description: "Enable zstd compression for the image",
},
}

func soManyErrors(args ...interface{}) error {
Expand Down

0 comments on commit cafc23d

Please sign in to comment.