MCPcopy Create free account
hub / github.com/Scalingo/cli / Create

Function Create

apps/create.go:13–50  ·  view source on GitHub ↗
(ctx context.Context, appName, remote, buildpack, projectID string, hdsResource bool)

Source from the content-addressed store, hash-verified

11)
12
13func Create(ctx context.Context, appName, remote, buildpack, projectID string, hdsResource bool) error {
14 c, err := config.ScalingoClient(ctx)
15 if err != nil {
16 return errors.Wrapf(ctx, err, "fail to get Scalingo client")
17 }
18
19 app, err := c.AppsCreate(ctx, scalingo.AppsCreateOpts{Name: appName, ProjectID: projectID, HDSResource: hdsResource})
20 if err != nil {
21 if utils.IsRegionDisabledError(err) {
22 return handleRegionDisabledError(ctx, appName, c)
23 }
24 if !utils.IsPaymentRequiredAndFreeTrialExceededError(err) {
25 return errors.Wrapf(ctx, err, "fail to create the application")
26 }
27 // If error is Payment Required and user tries to exceed its free trial
28 return utils.AskAndStopFreeTrial(ctx, c, func() error {
29 return Create(ctx, appName, remote, buildpack, projectID, hdsResource)
30 })
31 }
32
33 if buildpack != "" {
34 fmt.Println("Installing custom buildpack...")
35 _, err := c.VariableSet(ctx, app.Name, "BUILDPACK_URL", buildpack)
36 if err != nil {
37 fmt.Println("Failed to set custom buildpack. Please add BUILDPACK_URL=" + buildpack + " to your application environment")
38 }
39 }
40
41 fmt.Printf("App '%s' has been created\n", app.Name)
42 mainBranch := utils.MainBranchName(ctx)
43 _, ok := utils.DetectGit()
44 if ok && utils.AddGitRemote(ctx, app.GitURL, remote) == nil {
45 fmt.Printf("Git repository detected: remote %s added\n→ 'git push %s %s' to deploy your app\n", remote, remote, mainBranch)
46 } else {
47 fmt.Printf("To deploy your application, run these commands in your Git repository:\n→ git remote add %s %s\n→ git push %s %s\n", remote, app.GitURL, remote, mainBranch)
48 }
49 return nil
50}
51
52func handleRegionDisabledError(ctx context.Context, appName string, c *scalingo.Client) error {
53 regions, rerr := c.RegionsList(ctx)

Callers 1

create.goFile · 0.92

Calls 8

ScalingoClientFunction · 0.92
IsRegionDisabledErrorFunction · 0.92
AskAndStopFreeTrialFunction · 0.92
MainBranchNameFunction · 0.92
DetectGitFunction · 0.92
AddGitRemoteFunction · 0.92

Tested by

no test coverage detected