Skip to content

Commit 9825f66

Browse files
authored
Use a retrieved CNAME target rather than using the app preview domain (#4495)
* Use a retrieved CNAME target rather than using the app preview domain * mod tidy * Fixup inmem & mock
1 parent db4d3b0 commit 9825f66

File tree

9 files changed

+72
-6
lines changed

9 files changed

+72
-6
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ require (
7676
github.com/spf13/pflag v1.0.6
7777
github.com/spf13/viper v1.20.1
7878
github.com/stretchr/testify v1.10.0
79-
github.com/superfly/fly-go v0.1.48
79+
github.com/superfly/fly-go v0.1.49
8080
github.com/superfly/graphql v0.2.6
8181
github.com/superfly/lfsc-go v0.1.1
8282
github.com/superfly/macaroon v0.3.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
628628
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
629629
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
630630
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
631-
github.com/superfly/fly-go v0.1.48 h1:NZxdRYVK6ZiDArGa35gSITYgz/ThMXmZZzAS9q4Hyc8=
632-
github.com/superfly/fly-go v0.1.48/go.mod h1:YcVyr0bQm6cdydoMsqIHDPZDQqbmErwCSIuJI4pNwZM=
631+
github.com/superfly/fly-go v0.1.49 h1:nC+apgggqVRdf42N+ucd97JS8QF8dQfr4o1LLSDZDlU=
632+
github.com/superfly/fly-go v0.1.49/go.mod h1:YcVyr0bQm6cdydoMsqIHDPZDQqbmErwCSIuJI4pNwZM=
633633
github.com/superfly/graphql v0.2.6 h1:zppbodNerWecoXEdjkhrqaNaSjGqobhXNlViHFuZzb4=
634634
github.com/superfly/graphql v0.2.6/go.mod h1:CVfDl31srm8HnJ9udwLu6hFNUW/P6GUM2dKcG1YQ8jc=
635635
github.com/superfly/lfsc-go v0.1.1 h1:dGjLgt81D09cG+aR9lJZIdmonjZSR5zYCi7s54+ZU2Q=

gql/generated.go

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gql/genqclient.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ fragment AppData on App {
147147
name
148148
deployed
149149
platformVersion
150+
cnameTarget
150151
secrets {
151152
name
152153
}

gql/schema.graphql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,11 @@ type App implements Node {
792792
"""
793793
last: Int
794794
): AppChangeConnection!
795+
796+
"""
797+
Target to use for for CNAME DNS records
798+
"""
799+
cnameTarget: String
795800
config: AppConfig!
796801
createdAt: ISO8601DateTime!
797802
currentLock: AppLock

internal/command/certificates/root.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ func reportNextStepCert(ctx context.Context, hostname string, cert *fly.AppCerti
282282
return err
283283
}
284284

285+
cnameTarget, err := apiClient.GetAppCNAMETarget(ctx, appName)
286+
if err != nil {
287+
return err
288+
}
289+
285290
var ipV4 fly.IPAddress
286291
var ipV6 fly.IPAddress
287292
var configuredipV4 bool
@@ -354,6 +359,7 @@ func reportNextStepCert(ctx context.Context, hostname string, cert *fly.AppCerti
354359
Certificate: cert,
355360
IPv4Address: ipV4,
356361
IPv6Address: ipV6,
362+
CNAMETarget: cnameTarget,
357363
ExternalProxyDetected: externalProxyHint,
358364
})
359365
} else {
@@ -373,6 +379,7 @@ func reportNextStepCert(ctx context.Context, hostname string, cert *fly.AppCerti
373379
Certificate: cert,
374380
IPv4Address: ipV4,
375381
IPv6Address: ipV6,
382+
CNAMETarget: cnameTarget,
376383
ExternalProxyDetected: externalProxyHint,
377384
})
378385
}
@@ -388,6 +395,7 @@ func reportNextStepCert(ctx context.Context, hostname string, cert *fly.AppCerti
388395
Certificate: cert,
389396
IPv4Address: ipV4,
390397
IPv6Address: ipV6,
398+
CNAMETarget: cnameTarget,
391399
ExternalProxyDetected: externalProxyHint,
392400
})
393401
} else {
@@ -426,13 +434,13 @@ type DNSSetupFlags struct {
426434
Certificate *fly.AppCertificate
427435
IPv4Address fly.IPAddress
428436
IPv6Address fly.IPAddress
437+
CNAMETarget string
429438
ExternalProxyDetected bool
430439
}
431440

432441
func printDNSSetupOptions(opts DNSSetupFlags) error {
433442
io := iostreams.FromContext(opts.Context)
434443
colorize := io.ColorScheme()
435-
appName := appconfig.NameFromContext(opts.Context)
436444
hasIPv4 := opts.IPv4Address.Address != ""
437445
hasIPv6 := opts.IPv6Address.Address != ""
438446
promoteExtProxy := opts.ExternalProxyDetected && !opts.Certificate.IsWildcard
@@ -491,9 +499,9 @@ func printDNSSetupOptions(opts DNSSetupFlags) error {
491499
fmt.Fprintln(io.Out)
492500
optionNum++
493501

494-
if !opts.Certificate.IsApex && (hasIPv4 || hasIPv6) {
502+
if !opts.Certificate.IsApex && (hasIPv4 || hasIPv6) && opts.CNAMETarget != "" {
495503
fmt.Fprintf(io.Out, colorize.Cyan("%d. CNAME record\n\n"), optionNum)
496-
fmt.Fprintf(io.Out, " CNAME %s → %s.fly.dev\n", getRecordName(opts.Hostname), appName)
504+
fmt.Fprintf(io.Out, " CNAME %s → %s\n", getRecordName(opts.Hostname), opts.CNAMETarget)
497505
fmt.Fprintln(io.Out)
498506
optionNum++
499507
}

internal/flyutil/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type Client interface {
5151
GetAppCertificates(ctx context.Context, appName string) ([]fly.AppCertificateCompact, error)
5252
GetAppCompact(ctx context.Context, appName string) (*fly.AppCompact, error)
5353
GetAppCurrentReleaseMachines(ctx context.Context, appName string) (*fly.Release, error)
54+
GetAppCNAMETarget(ctx context.Context, appName string) (string, error)
5455
GetAppHostIssues(ctx context.Context, appName string) ([]fly.HostIssue, error)
5556
GetAppLimitedAccessTokens(ctx context.Context, appName string) ([]fly.LimitedAccessToken, error)
5657
GetAppLogs(ctx context.Context, appName, token, region, instanceID string) (entries []fly.LogEntry, nextToken string, err error)

internal/inmem/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ func (m *Client) GetAppCurrentReleaseMachines(ctx context.Context, appName strin
216216
panic("TODO")
217217
}
218218

219+
func (m *Client) GetAppCNAMETarget(ctx context.Context, appName string) (string, error) {
220+
panic("TODO")
221+
}
222+
219223
func (m *Client) GetAppHostIssues(ctx context.Context, appName string) ([]fly.HostIssue, error) {
220224
panic("TODO")
221225
}

internal/mock/client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type Client struct {
5353
GetAppCompactFunc func(ctx context.Context, appName string) (*fly.AppCompact, error)
5454
GetDeployerAppByOrgFunc func(ctx context.Context, orgID string) (*fly.App, error)
5555
GetAppCurrentReleaseMachinesFunc func(ctx context.Context, appName string) (*fly.Release, error)
56+
GetAppCNAMETargetFunc func(ctx context.Context, appName string) (string, error)
5657
GetAppHostIssuesFunc func(ctx context.Context, appName string) ([]fly.HostIssue, error)
5758
GetAppLimitedAccessTokensFunc func(ctx context.Context, appName string) ([]fly.LimitedAccessToken, error)
5859
GetAppLogsFunc func(ctx context.Context, appName, token, region, instanceID string) (entries []fly.LogEntry, nextToken string, err error)
@@ -263,6 +264,10 @@ func (m *Client) GetAppCurrentReleaseMachines(ctx context.Context, appName strin
263264
return m.GetAppCurrentReleaseMachinesFunc(ctx, appName)
264265
}
265266

267+
func (m *Client) GetAppCNAMETarget(ctx context.Context, appName string) (string, error) {
268+
return m.GetAppCNAMETargetFunc(ctx, appName)
269+
}
270+
266271
func (m *Client) GetAppHostIssues(ctx context.Context, appName string) ([]fly.HostIssue, error) {
267272
return m.GetAppHostIssuesFunc(ctx, appName)
268273
}

0 commit comments

Comments
 (0)