Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compute/deploy): support --service-name for publishing to a non-manifest specific service #979

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"fmt"
"io"

"github.com/fastly/go-fastly/v8/fastly"
"github.com/fastly/kingpin"

"github.com/fastly/cli/pkg/api"
"github.com/fastly/cli/pkg/env"
fsterr "github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/global"
"github.com/fastly/cli/pkg/manifest"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/go-fastly/v8/fastly"
"github.com/fastly/kingpin"
)

// Command is an interface that abstracts over all of the concrete command
Expand Down Expand Up @@ -161,12 +162,15 @@ func ServiceID(serviceName OptionalServiceNameID, data manifest.Data, client api
return serviceID, source, flag, err
}

flag = "--service-name"
serviceID, err = serviceName.Parse(client)
if err != nil && li != nil {
li.Add(err)
if err != nil {
if li != nil {
li.Add(err)
}
} else {
source = manifest.SourceFlag
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bug. We should have only overridden the source if there was no errors.

}
flag = "--service-name"
source = manifest.SourceFlag
}

return serviceID, source, flag, err
Expand Down
29 changes: 23 additions & 6 deletions pkg/commands/compute/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ func serviceManagement(
serviceID, serviceVersion, err = manageNoServiceIDFlow(
c.Globals.Flags, in, out,
c.Globals.APIClient, c.Package, c.Globals.ErrLog,
&c.Manifest.File, fnActivateTrial, spinner,
&c.Manifest.File, fnActivateTrial, spinner, c.ServiceName,
)
if err != nil {
return newService, "", nil, false, err
Expand All @@ -461,6 +461,21 @@ func serviceManagement(
return newService, "", nil, false, nil // user declined service creation prompt
}
} else {
// There is a scenario where a user already has a Service ID within the
// fastly.toml manifest but they want to deploy their project to a different
// service (e.g. deploy to a staging service).
//
// In this scenario we end up here because we have found a Service ID in the
// manifest but if the --service-name flag is set, then we need to ignore
// what's set in the manifest and instead identify the ID of the service
// name the user has provided.
if c.ServiceName.WasSet {
serviceID, err = c.ServiceName.Parse(c.Globals.APIClient)
if err != nil {
return false, "", nil, false, err
}
}

serviceVersion, err = manageExistingServiceFlow(serviceID, c.ServiceVersion, c.Globals.APIClient, c.Globals.Verbose(), out, c.Globals.ErrLog)
if err != nil {
return false, "", nil, false, err
Expand All @@ -481,6 +496,7 @@ func manageNoServiceIDFlow(
manifestFile *manifest.File,
fnActivateTrial activator,
spinner text.Spinner,
serviceNameFlag cmd.OptionalServiceNameID,
) (serviceID string, serviceVersion *fastly.Version, err error) {
if !f.AutoYes && !f.NonInteractive {
text.Output(out, "There is no Fastly service associated with this package. To connect to an existing service add the Service ID to the fastly.toml file, otherwise follow the prompts to create a service now.")
Expand All @@ -507,7 +523,12 @@ func manageNoServiceIDFlow(
defaultServiceName := manifestFile.Name
var serviceName string

if !f.AcceptDefaults && !f.NonInteractive {
// The service name will be whatever is set in the --service-name flag.
// If the flag isn't set, and we're able to prompt, we'll ask the user.
// If the flag isn't set, and we're non-interactive, we'll use the default.
if serviceNameFlag.WasSet {
serviceName = serviceNameFlag.Value
} else if !f.AcceptDefaults && !f.NonInteractive {
serviceName, err = text.Input(out, text.BoldYellow(fmt.Sprintf("Service name: [%s] ", defaultServiceName)), in)
if err != nil || serviceName == "" {
serviceName = defaultServiceName
Expand Down Expand Up @@ -561,10 +582,6 @@ func createService(
errLog fsterr.LogInterface,
out io.Writer,
) (serviceID string, serviceVersion *fastly.Version, err error) {
if !f.AcceptDefaults && !f.NonInteractive {
text.Break(out)
}

err = spinner.Start()
if err != nil {
return "", nil, err
Expand Down