33package appconfig
44
55import (
6+ "context"
67 "encoding/base64"
78 "fmt"
89 "net/url"
@@ -12,6 +13,8 @@ import (
1213 "slices"
1314
1415 fly "github.com/superfly/fly-go"
16+ "github.com/superfly/flyctl/internal/flag"
17+ "github.com/superfly/flyctl/internal/launchdarkly"
1518)
1619
1720const (
@@ -155,6 +158,7 @@ type Mount struct {
155158 Destination string `toml:"destination,omitempty" json:"destination,omitempty"`
156159 InitialSize string `toml:"initial_size,omitempty" json:"initial_size,omitempty"`
157160 SnapshotRetention * int `toml:"snapshot_retention,omitempty" json:"snapshot_retention,omitempty"`
161+ ScheduledSnapshots * bool `toml:"scheduled_snapshots,omitempty" json:"scheduled_snapshots,omitempty"`
158162 AutoExtendSizeThreshold int `toml:"auto_extend_size_threshold,omitempty" json:"auto_extend_size_threshold,omitempty"`
159163 AutoExtendSizeIncrement string `toml:"auto_extend_size_increment,omitempty" json:"auto_extend_size_increment,omitempty"`
160164 AutoExtendSizeLimit string `toml:"auto_extend_size_limit,omitempty" json:"auto_extend_size_limit,omitempty"`
@@ -176,6 +180,8 @@ type Build struct {
176180 Ignorefile string `toml:"ignorefile,omitempty" json:"ignorefile,omitempty"`
177181 DockerBuildTarget string `toml:"build-target,omitempty" json:"build-target,omitempty"`
178182 Compose * BuildCompose `toml:"compose,omitempty" json:"compose,omitempty"`
183+ Compression string `toml:"compression,omitempty" json:"compression,omitempty"`
184+ CompressionLevel * int `toml:"compression_level,omitempty" json:"compression_level,omitempty"`
179185}
180186
181187type Experimental struct {
@@ -188,7 +194,6 @@ type Experimental struct {
188194 LazyLoadImages bool `toml:"lazy_load_images,omitempty" json:"lazy_load_images,omitempty"`
189195 Attached Attached `toml:"attached,omitempty" json:"attached,omitempty"`
190196 MachineConfig string `toml:"machine_config,omitempty" json:"machine_config,omitempty"`
191- UseZstd bool `toml:"use_zstd,omitempty" json:"use_zstd,omitempty"`
192197}
193198
194199type Attached struct {
@@ -247,6 +252,41 @@ func (c *Config) DetermineIPType(ipType string) string {
247252 return "shared"
248253}
249254
255+ func (c * Config ) DetermineCompression (ctx context.Context ) (compression string , compressionLevel int ) {
256+ // Set default values
257+ compression = "gzip"
258+ compressionLevel = 7
259+
260+ // LaunchDarkly provides the base settings
261+ ldClient := launchdarkly .ClientFromContext (ctx )
262+ if ldClient .UseZstdEnabled () {
263+ compression = "zstd"
264+ }
265+ if strength , ok := ldClient .GetCompressionStrength ().(float64 ); ok {
266+ compressionLevel = int (strength )
267+ }
268+
269+ // fly.toml overrides LaunchDarkly
270+ if c .Build != nil {
271+ if c .Build .Compression != "" {
272+ compression = c .Build .Compression
273+ }
274+ if c .Build .CompressionLevel != nil {
275+ compressionLevel = * c .Build .CompressionLevel
276+ }
277+ }
278+
279+ // CLI flags override everything
280+ if flag .IsSpecified (ctx , "compression" ) {
281+ compression = flag .GetString (ctx , "compression" )
282+ }
283+ if flag .IsSpecified (ctx , "compression-level" ) {
284+ compressionLevel = flag .GetInt (ctx , "compression-level" )
285+ }
286+
287+ return
288+ }
289+
250290// IsUsingGPU returns true if any VMs have a gpu-kind set.
251291func (c * Config ) IsUsingGPU () bool {
252292 for _ , vm := range c .Compute {
0 commit comments