Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( AddressFlag = cli.StringFlag{ Name: "address", Value: api.DefaultAddress, Usage: "Nullstone API Address", } ApiKeyFlag = cli.StringFlag{ Name: "api-key", Value: "", Usage: "Nullstone API Key", } )
View Source
var Configure = cli.Command{ Name: "configure", Flags: []cli.Flag{ AddressFlag, ApiKeyFlag, }, Action: func(c *cli.Context) error { apiKey := c.String(ApiKeyFlag.Name) if apiKey == "" { fmt.Print("Enter API Key: ") rawApiKey, err := terminal.ReadPassword(int(syscall.Stdin)) if err != nil { return fmt.Errorf("error reading password: %w", err) } fmt.Println() apiKey = string(rawApiKey) } profile := config.Profile{ Name: GetProfile(c), Address: c.String(AddressFlag.Name), ApiKey: apiKey, } if err := profile.Save(); err != nil { return fmt.Errorf("error configuring profile: %w", err) } fmt.Fprintln(os.Stderr, "nullstone configured successfully!") return nil }, }
View Source
var Deploy = func(providers app.Providers) cli.Command { return cli.Command{ Name: "deploy", Usage: "Deploy application", UsageText: "nullstone deploy <app-name> <env-name> [options]", Flags: []cli.Flag{ cli.StringFlag{ Name: "image-tag", Usage: "Update the docker image tag for apps defined as 'app/container'. If not specified, will force a deployment.", }, }, Action: func(c *cli.Context) error { profile, err := config.LoadProfile(GetProfile(c)) if err != nil { return err } if c.NArg() != 2 { return cli.ShowCommandHelp(c, "deploy") } appName := c.Args().Get(0) envName := c.Args().Get(1) userConfig := map[string]string{ "imageTag": c.String("image-tag"), } config := api.DefaultConfig() config.BaseAddress = profile.Address config.ApiKey = profile.ApiKey config.OrgName = GetOrg(c, *profile) if config.OrgName == "" { return ErrMissingOrg } client := api.Client{Config: config} app, err := client.Apps().Get(appName) if err != nil { return fmt.Errorf("error retrieving application %q: %w", appName, err) } else if app == nil { return fmt.Errorf("application %q does not exist", appName) } workspace, err := client.Workspaces().Get(app.StackName, app.Block.Name, envName) if err != nil { return fmt.Errorf("error retrieving workspace: %w", err) } else if workspace == nil { return fmt.Errorf("workspace %q does not exist", err) } if workspace.Status != types.WorkspaceStatusProvisioned { return fmt.Errorf("app %q has not been provisioned in %q environment yet", app.Name, workspace.EnvName) } if workspace.Module == nil { return fmt.Errorf("unknown module for workspace, cannot perform deployment") } provider := providers.Find(workspace.Module.Category, workspace.Module.Type) if provider == nil { return fmt.Errorf("unable to deploy, this CLI does not support category=%s, type=%s", workspace.Module.Category, workspace.Module.Type) } return provider.Deploy(config, app, workspace, userConfig) }, } }
View Source
var (
ErrMissingOrg = errors.New("An organization has not been configured with this profile. See 'nullstone set-org -h' for more details.")
)
View Source
var OrgFlag = cli.StringFlag{
Name: "org",
EnvVar: "NULLSTONE_ORG",
Usage: `Nullstone organization name used to contextualize API calls. If this flag is not specified, the nullstone CLI will use ~/.nullstone/<profile>/org file.`,
}
OrgFlag defines a flag that the CLI uses
to contextualize API calls by that organization within Nullstone
The organization takes the following precedence:
`--org` flag `NULLSTONE_ORG` env var `~/.nullstone/<profile>/org` file
View Source
var ProfileFlag = cli.StringFlag{
Name: "profile",
EnvVar: "NULLSTONE_PROFILE",
Value: "default",
Usage: "Name of profile",
}
View Source
var Push = func(providers app.Providers) cli.Command { return cli.Command{ Name: "push", Usage: "Push artifact", UsageText: "nullstone push <app-name> <env-name> [options]", Flags: []cli.Flag{ cli.StringFlag{ Name: "source", Usage: "The source docker image to push. This follows the same syntax as `docker push NAME[:TAG]`.", Required: true, }, cli.StringFlag{ Name: "image-tag", Usage: "Push the image with this tag instead of the source. If not specified, will use the source tag.", Value: "latest", }, }, Action: func(c *cli.Context) error { profile, err := config.LoadProfile(GetProfile(c.Parent())) if err != nil { return err } if c.NArg() != 2 { return cli.ShowCommandHelp(c, "push") } appName := c.Args().Get(0) envName := c.Args().Get(1) userConfig := map[string]string{ "source": c.String("source"), "imageTag": c.String("image-tag"), } config := api.DefaultConfig() config.BaseAddress = profile.Address config.ApiKey = profile.ApiKey config.OrgName = GetOrg(c, *profile) if config.OrgName == "" { return ErrMissingOrg } client := api.Client{Config: config} app, err := client.Apps().Get(appName) if err != nil { return fmt.Errorf("error retrieving application %q: %w", appName, err) } else if app == nil { return fmt.Errorf("application %q does not exist", appName) } workspace, err := client.Workspaces().Get(app.StackName, app.Block.Name, envName) if err != nil { return fmt.Errorf("error retrieving workspace: %w", err) } else if workspace == nil { return fmt.Errorf("workspace %q does not exist", err) } if workspace.Status != types.WorkspaceStatusProvisioned { return fmt.Errorf("app %q has not been provisioned in %q environment yet", app.Name, workspace.EnvName) } if workspace.Module == nil { return fmt.Errorf("unknown module for workspace, cannot perform deployment") } provider := providers.Find(workspace.Module.Category, workspace.Module.Type) if provider == nil { return fmt.Errorf("unable to push, this CLI does not support category=%s, type=%s", workspace.Module.Category, workspace.Module.Type) } return provider.Push(config, app, workspace, userConfig) }, } }
Push command performs a docker push to an authenticated image registry configured against an app/container
View Source
var SetOrg = cli.Command{ Name: "set-org", Usage: "Set the organization for the CLI", UsageText: `Most Nullstone CLI commands require a configured nullstone organization to operate. This command will set the organization for the current profile. If you wish to set the organization per command, use the global --org flag instead.`, Flags: []cli.Flag{}, Action: func(c *cli.Context) error { profile, err := config.LoadProfile(GetProfile(c)) if err != nil { return err } if c.NArg() != 1 { return cli.ShowCommandHelp(c, "set-org") } orgName := c.Args().Get(0) if err := profile.SaveOrg(orgName); err != nil { return err } fmt.Fprintf(os.Stderr, "Organization set to %s for %s profile\n", orgName, profile.Name) return nil }, }
Functions ¶
func GetProfile ¶ added in v0.0.4
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.