Skip to content

Commit e454601

Browse files
committed
Merge branch 'master' into update-flygo-version
2 parents a6a1d79 + 154fb98 commit e454601

File tree

33 files changed

+403
-321
lines changed

33 files changed

+403
-321
lines changed

.golangci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "2"
22
run:
33
concurrency: 4
4-
go: "1.21"
4+
go: "1.24"
55
issues-exit-code: 1
66
tests: true
77
linters:
@@ -52,7 +52,7 @@ linters:
5252
rules:
5353
- linters:
5454
- lll
55-
source: '^//go:generate '
55+
source: "^//go:generate "
5656
paths:
5757
- third_party$
5858
- builtin$

.pre-commit-config.yaml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
4-
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.4.0
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v6.0.0
66
hooks:
7-
- id: trailing-whitespace
8-
- id: end-of-file-fixer
9-
- id: check-yaml
10-
- id: check-added-large-files
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-added-large-files
1111

12-
- repo: https://github.com/tekwizely/pre-commit-golang
13-
rev: v1.0.0-rc.1
12+
- repo: https://github.com/tekwizely/pre-commit-golang
13+
rev: v1.0.0-rc.2
1414
hooks:
15-
- id: go-mod-tidy
15+
- id: go-mod-tidy
1616

17-
# NOTE: This pre-commit hook is ignored when running on Github Workflow
18-
# because goalngci-lint github action is much more useful than the pre-commit action.
19-
# The trick is to run github action only for "manual" hook stage
20-
- repo: https://github.com/golangci/golangci-lint
21-
rev: v1.24.0
17+
# NOTE: This pre-commit hook is ignored when running on Github Workflow
18+
# because goalngci-lint github action is much more useful than the pre-commit action.
19+
# The trick is to run github action only for "manual" hook stage
20+
- repo: https://github.com/golangci/golangci-lint
21+
rev: v2.5.0
2222
hooks:
23-
- id: golangci-lint
23+
- id: golangci-lint
2424
stages: [pre-commit]

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ require (
8989
go.uber.org/mock v0.6.0
9090
golang.org/x/crypto v0.42.0
9191
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f
92-
golang.org/x/mod v0.27.0
93-
golang.org/x/net v0.43.0
92+
golang.org/x/mod v0.28.0
93+
golang.org/x/net v0.44.0
9494
golang.org/x/sync v0.17.0
9595
golang.org/x/sys v0.36.0
9696
golang.org/x/term v0.35.0
9797
golang.org/x/text v0.29.0
98-
golang.org/x/time v0.12.0
98+
golang.org/x/time v0.13.0
9999
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173
100100
google.golang.org/grpc v1.75.0
101101
gopkg.in/yaml.v2 v2.4.0

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,8 @@ golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
749749
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
750750
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
751751
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
752-
golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ=
753-
golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc=
752+
golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U=
753+
golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI=
754754
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
755755
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
756756
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
@@ -768,8 +768,8 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
768768
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
769769
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
770770
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
771-
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
772-
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
771+
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
772+
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
773773
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
774774
golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=
775775
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -844,8 +844,8 @@ golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
844844
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
845845
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
846846
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
847-
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
848-
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
847+
golang.org/x/time v0.13.0 h1:eUlYslOIt32DgYD6utsuUeHs4d7AsEYLuIAdg7FlYgI=
848+
golang.org/x/time v0.13.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
849849
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
850850
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
851851
golang.org/x/tools v0.0.0-20190930201159-7c411dea38b0/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=

internal/appconfig/config.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package appconfig
44

55
import (
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

1720
const (
@@ -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

181187
type 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

194199
type 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.
251291
func (c *Config) IsUsingGPU() bool {
252292
for _, vm := range c.Compute {

internal/appconfig/definition_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,11 @@ func TestToDefinition(t *testing.T) {
304304
},
305305
},
306306
"mounts": []any{map[string]any{
307-
"source": "data",
308-
"destination": "/data",
309-
"initial_size": "30gb",
310-
"snapshot_retention": int64(17),
307+
"source": "data",
308+
"destination": "/data",
309+
"initial_size": "30gb",
310+
"snapshot_retention": int64(17),
311+
"scheduled_snapshots": true,
311312
}},
312313
"processes": map[string]any{
313314
"web": "run web",

internal/appconfig/serde_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,11 @@ func TestLoadTOMLAppConfigReferenceFormat(t *testing.T) {
592592
},
593593

594594
Mounts: []Mount{{
595-
Source: "data",
596-
Destination: "/data",
597-
InitialSize: "30gb",
598-
SnapshotRetention: fly.Pointer(17),
595+
Source: "data",
596+
Destination: "/data",
597+
InitialSize: "30gb",
598+
SnapshotRetention: fly.Pointer(17),
599+
ScheduledSnapshots: fly.BoolPointer(true),
599600
}},
600601

601602
Processes: map[string]string{

internal/appconfig/testdata/full-reference.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ host_dedication_id = "06031957"
128128
initial_size = "30gb"
129129
destination = "/data"
130130
snapshot_retention = 17
131+
scheduled_snapshots = true
131132

132133
[[vm]]
133134
size = "shared-cpu-1x"

internal/appconfig/validation.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/logrusorgru/aurora"
1414
fly "github.com/superfly/fly-go"
1515
"github.com/superfly/flyctl/helpers"
16+
"github.com/superfly/flyctl/internal/flag/validation"
1617
"github.com/superfly/flyctl/internal/sentry"
1718
)
1819

@@ -36,6 +37,7 @@ func (c *Config) Validate(ctx context.Context) (err error, extra_info string) {
3637
c.validateConsoleCommand,
3738
c.validateMounts,
3839
c.validateRestartPolicy,
40+
c.validateCompression,
3941
}
4042

4143
extra_info = fmt.Sprintf("Validating %s\n", c.ConfigFilePath())
@@ -175,7 +177,7 @@ func (c *Config) validateServicesSection() (extraInfo string, err error) {
175177
"Check docs at https://fly.io/docs/reference/configuration/#services-ports \n " +
176178
"Validation for _services without ports_ will hard fail after February 15, 2024.",
177179
)
178-
//err = ValidationError
180+
// err = ValidationError
179181
}
180182

181183
for _, check := range service.TCPChecks {
@@ -355,3 +357,23 @@ func (c *Config) validateRestartPolicy() (extraInfo string, err error) {
355357

356358
return
357359
}
360+
361+
func (c *Config) validateCompression() (extraInfo string, err error) {
362+
if c.Build != nil {
363+
if c.Build.Compression != "" {
364+
if vErr := validation.ValidateCompressionFlag(c.Build.Compression); vErr != nil {
365+
extraInfo += fmt.Sprintf("%s\n", vErr.Error())
366+
err = ValidationError
367+
}
368+
}
369+
370+
if c.Build.CompressionLevel != nil {
371+
if vErr := validation.ValidateCompressionLevelFlag(*c.Build.CompressionLevel); vErr != nil {
372+
extraInfo += fmt.Sprintf("%s\n", vErr.Error())
373+
err = ValidationError
374+
}
375+
}
376+
}
377+
378+
return
379+
}

internal/appsecrets/secrets.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package appsecrets
22

33
import (
44
"context"
5+
crand "crypto/rand"
6+
"encoding/hex"
7+
"fmt"
58

69
"github.com/superfly/fly-go"
710

@@ -45,3 +48,15 @@ func Update(ctx context.Context, client flapsutil.FlapsClient, appName string, s
4548
}
4649
return nil
4750
}
51+
52+
// Sync sets the min version for the app to the current min version, allowing
53+
// any previously set secret to be visible in deploys.
54+
func Sync(ctx context.Context, client flapsutil.FlapsClient, appName string) error {
55+
// This is somewhat of a hack -- we unset an non-existent secret and
56+
// we get back the latest min version after the unset.
57+
rand := make([]byte, 8)
58+
_, _ = crand.Read(rand)
59+
bogusDummySecret := fmt.Sprintf("BogusDummySecret_%s", hex.EncodeToString(rand))
60+
unsetSecrets := []string{bogusDummySecret}
61+
return Update(ctx, client, appName, nil, unsetSecrets)
62+
}

0 commit comments

Comments
 (0)