Skip to content

Commit a1f6ee4

Browse files
committed
init commit
1 parent a3be1a3 commit a1f6ee4

3 files changed

Lines changed: 115 additions & 24 deletions

File tree

pkg/commands/compute/deploy.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type DeployCommand struct {
5353
Dir string
5454
Domain string
5555
Env string
56+
NoDefaultDomain argparser.OptionalBool
5657
PackagePath string
5758
ServiceName argparser.OptionalServiceNameID
5859
ServiceVersion argparser.OptionalServiceVersion
@@ -93,6 +94,7 @@ func NewDeployCommand(parent argparser.Registerer, g *global.Data) *DeployComman
9394
c.CmdClause.Flag("dir", "Project directory (default: current directory)").Short('C').StringVar(&c.Dir)
9495
c.CmdClause.Flag("domain", "The name of the domain associated to the package").StringVar(&c.Domain)
9596
c.CmdClause.Flag("env", "The manifest environment config to use (e.g. 'stage' will attempt to read 'fastly.stage.toml')").StringVar(&c.Env)
97+
c.CmdClause.Flag("no-default-domain", "Skip automatic default domain creation").Action(c.NoDefaultDomain.Set).BoolVar(&c.NoDefaultDomain.Value)
9698
c.CmdClause.Flag("package", "Path to a package tar.gz").Short('p').StringVar(&c.PackagePath)
9799
c.CmdClause.Flag("status-check-code", "Set the expected status response for the service availability check").IntVar(&c.StatusCheckCode)
98100
c.CmdClause.Flag("status-check-off", "Disable the service availability check").BoolVar(&c.StatusCheckOff)
@@ -233,16 +235,17 @@ func (c *DeployCommand) Exec(in io.Reader, out io.Writer) (err error) {
233235
// It's part of the implementation so that we can utilise the same interface.
234236
// A domain is required regardless of whether it's a new service or existing.
235237
sr.domains = &setup.Domains{
236-
APIClient: c.Globals.APIClient,
237-
AcceptDefaults: c.Globals.Flags.AcceptDefaults,
238-
NonInteractive: c.Globals.Flags.NonInteractive,
239-
PackageDomain: c.Domain,
240-
RetryLimit: 5,
241-
ServiceID: serviceID,
242-
ServiceVersion: serviceVersionNumber,
243-
Stdin: in,
244-
Stdout: out,
245-
Verbose: c.Globals.Verbose(),
238+
APIClient: c.Globals.APIClient,
239+
AcceptDefaults: c.Globals.Flags.AcceptDefaults,
240+
NoDefaultDomain: c.NoDefaultDomain.WasSet,
241+
NonInteractive: c.Globals.Flags.NonInteractive,
242+
PackageDomain: c.Domain,
243+
RetryLimit: 5,
244+
ServiceID: serviceID,
245+
ServiceVersion: serviceVersionNumber,
246+
Stdin: in,
247+
Stdout: out,
248+
Verbose: c.Globals.Verbose(),
246249
}
247250
if err = sr.domains.Validate(); err != nil {
248251
errLogService(c.Globals.ErrLog, err, serviceID, serviceVersionNumber)
@@ -304,7 +307,7 @@ func (c *DeployCommand) Exec(in io.Reader, out io.Writer) (err error) {
304307
return err
305308
}
306309

307-
if !c.StatusCheckOff && noExistingService {
310+
if !c.StatusCheckOff && noExistingService && serviceURL != "" {
308311
c.StatusCheck(serviceURL, spinner, out)
309312
}
310313

@@ -345,7 +348,9 @@ func (c *DeployCommand) StatusCheck(serviceURL string, spinner text.Spinner, out
345348

346349
func displayDeployOutput(out io.Writer, manageServiceBaseURL, serviceID, serviceURL string, serviceVersion int) {
347350
text.Description(out, "Manage this service at", fmt.Sprintf("%s%s", manageServiceBaseURL, serviceID))
348-
text.Description(out, "View this service at", serviceURL)
351+
if serviceURL != "" {
352+
text.Description(out, "View this service at", serviceURL)
353+
}
349354
text.Success(out, "Deployed package (service %s, version %v)", serviceID, serviceVersion)
350355
}
351356

@@ -1065,6 +1070,9 @@ func (c *DeployCommand) GetServiceURL(serviceID string, serviceVersion int) (str
10651070
if err != nil {
10661071
return "", err
10671072
}
1073+
if len(latestDomains) == 0 {
1074+
return "", nil
1075+
}
10681076
name := fastly.ToValue(latestDomains[0].Name)
10691077
if segs := strings.Split(name, "*."); len(segs) > 1 {
10701078
name = segs[1]

pkg/commands/compute/deploy_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,79 @@ func TestDeploy(t *testing.T) {
697697
"Deployed package (service 123, version 4)",
698698
},
699699
},
700+
{
701+
name: "success with --no-default-domain flag for new service",
702+
args: args("compute deploy --no-default-domain --token 123"),
703+
api: mock.API{
704+
ActivateVersionFn: activateVersionOk,
705+
CreateBackendFn: createBackendOK,
706+
CreateServiceFn: createServiceOK,
707+
DeleteServiceFn: deleteServiceOK,
708+
GetPackageFn: getPackageOk,
709+
ListDomainsFn: listDomainsNone,
710+
UpdatePackageFn: updatePackageOk,
711+
},
712+
stdin: []string{
713+
"Y", // when prompted to create a new service
714+
},
715+
wantOutput: []string{
716+
"Deployed package (service 12345, version 1)",
717+
},
718+
dontWantOutput: []string{
719+
"Creating domain",
720+
"Domain:",
721+
},
722+
},
723+
{
724+
name: "success with --no-default-domain but explicit --domain provided",
725+
args: args("compute deploy --token 123 --no-default-domain --domain example.com"),
726+
api: mock.API{
727+
ActivateVersionFn: activateVersionOk,
728+
CreateBackendFn: createBackendOK,
729+
CreateDomainFn: createDomainOK,
730+
CreateServiceFn: createServiceOK,
731+
GetPackageFn: getPackageOk,
732+
ListDomainsFn: listDomainsNone,
733+
UpdatePackageFn: updatePackageOk,
734+
},
735+
httpClientRes: []*http.Response{
736+
mock.NewHTTPResponse(http.StatusNoContent, nil, nil),
737+
mock.NewHTTPResponse(http.StatusOK, nil, io.NopCloser(strings.NewReader("success"))),
738+
},
739+
httpClientErr: []error{
740+
nil,
741+
nil,
742+
},
743+
stdin: []string{
744+
"Y", // when prompted to create a new service
745+
},
746+
wantOutput: []string{
747+
"Creating domain 'example.com'",
748+
"Deployed package (service 12345, version 1)",
749+
},
750+
},
751+
{
752+
name: "success with --no-default-domain and existing service",
753+
args: args("compute deploy --service-id 123 --token 123 --no-default-domain"),
754+
api: mock.API{
755+
ActivateVersionFn: activateVersionOk,
756+
CloneVersionFn: testutil.CloneVersionResult(4),
757+
GetPackageFn: getPackageOk,
758+
GetServiceDetailsFn: getServiceDetailsWasm,
759+
GetServiceFn: getServiceOK,
760+
ListDomainsFn: listDomainsOk,
761+
ListVersionsFn: testutil.ListVersions,
762+
UpdatePackageFn: updatePackageOk,
763+
},
764+
wantOutput: []string{
765+
"Uploading package",
766+
"Activating service",
767+
"Deployed package (service 123, version 4)",
768+
},
769+
dontWantOutput: []string{
770+
"Creating domain",
771+
},
772+
},
700773
// The following test doesn't provide a Service ID by either a flag nor the
701774
// manifest, so this will result in the deploy script attempting to create
702775
// a new service. Our fastly.toml is configured with a [setup] section so

pkg/commands/compute/setup/domain.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@ var domainNameRegEx = regexp.MustCompile(`(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])
2626
// NOTE: It implements the setup.Interface interface.
2727
type Domains struct {
2828
// Public
29-
APIClient api.Interface
30-
AcceptDefaults bool
31-
NonInteractive bool
32-
PackageDomain string
33-
Spinner text.Spinner
34-
RetryLimit int
35-
ServiceID string
36-
ServiceVersion int
37-
Stdin io.Reader
38-
Stdout io.Writer
39-
Verbose bool
29+
APIClient api.Interface
30+
AcceptDefaults bool
31+
NoDefaultDomain bool
32+
NonInteractive bool
33+
PackageDomain string
34+
Spinner text.Spinner
35+
RetryLimit int
36+
ServiceID string
37+
ServiceVersion int
38+
Stdin io.Reader
39+
Stdout io.Writer
40+
Verbose bool
4041

4142
// Private
4243
available []*fastly.Domain
@@ -54,6 +55,12 @@ type Domain struct {
5455
//
5556
// NOTE: If --domain flag is used we'll use that as the domain to create.
5657
func (d *Domains) Configure() error {
58+
// Don't generate a domain if --no-default-domain is set and no domain is provided
59+
if d.NoDefaultDomain && d.PackageDomain == "" {
60+
d.missing = false
61+
return nil
62+
}
63+
5764
// PackageDomain is the --domain flag value.
5865
if d.PackageDomain != "" {
5966
d.required = append(d.required, Domain{
@@ -134,7 +141,10 @@ func (d *Domains) Validate() error {
134141
}
135142
d.available = available
136143
if len(d.available) == 0 {
137-
d.missing = true
144+
// Only mark as missing if we're not intentionally skipping domain creation
145+
if !(d.NoDefaultDomain && d.PackageDomain == "") {
146+
d.missing = true
147+
}
138148
}
139149
return nil
140150
}

0 commit comments

Comments
 (0)