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

Function Deploy

deployments/deploy.go:26–75  ·  view source on GitHub ↗
(ctx context.Context, app, archivePath, gitRef string, opts DeployOpts)

Source from the content-addressed store, hash-verified

24}
25
26func Deploy(ctx context.Context, app, archivePath, gitRef string, opts DeployOpts) error {
27 client, err := config.ScalingoClient(ctx)
28 if err != nil {
29 return errors.Wrapf(ctx, err, "fail to get Scalingo client")
30 }
31
32 var archiveURL string
33 // If archivePath is a remote resource
34 if strings.HasPrefix(archivePath, "http://") || strings.HasPrefix(archivePath, "https://") {
35 archiveURL = archivePath
36 } else { // if archivePath is a file
37 archiveURL, err = uploadArchivePath(ctx, client, archivePath)
38 if err != nil {
39 return errors.Wrapf(ctx, err, "upload archive path")
40 }
41 }
42
43 params := &scalingo.DeploymentsCreateParams{
44 SourceURL: archiveURL,
45 }
46
47 // gitRef cannot be anything. It is used in the docker tag image. For example, it cannot
48 // start with a dash
49 if strings.TrimSpace(gitRef) != "" {
50 params.GitRef = &gitRef
51 }
52 deployment, err := client.DeploymentsCreate(ctx, app, params)
53 if err != nil {
54 return errors.Wrapf(ctx, err, "create archive deployment")
55 }
56
57 scalingoio.Status("Your deployment has been queued and is going to start…")
58
59 if opts.NoFollow {
60 scalingoio.Statusf("The no-follow flag is passed. You can check deployment logs with scalingo --app %s deployment-follow", app)
61 return nil
62 }
63
64 go showQueuedWarnings(ctx, client, app, deployment.ID)
65 debug.Println("Streaming deployment logs of", app, ":", deployment.ID)
66 err = Stream(ctx, &StreamOpts{
67 AppName: app,
68 DeploymentID: deployment.ID,
69 })
70 if err != nil {
71 return errors.Wrapf(ctx, err, "stream archive deployment logs")
72 }
73
74 return nil
75}
76
77func uploadArchivePath(ctx context.Context, client *scalingo.Client, archivePath string) (string, error) {
78 archiveFd, err := os.OpenFile(archivePath, os.O_RDONLY, 0640)

Callers 2

deployments.goFile · 0.92
DeployWarFunction · 0.85

Calls 4

ScalingoClientFunction · 0.92
uploadArchivePathFunction · 0.85
showQueuedWarningsFunction · 0.85
StreamFunction · 0.70

Tested by

no test coverage detected