forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
push.go
641 lines (543 loc) · 19.8 KB
/
push.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
package application
import (
"fmt"
"os"
"regexp"
"strconv"
"strings"
. "github.com/cloudfoundry/cli/cf/i18n"
"github.com/cloudfoundry/cli/fileutils"
"github.com/cloudfoundry/cli/cf/actors"
"github.com/cloudfoundry/cli/cf/api"
"github.com/cloudfoundry/cli/cf/api/applications"
"github.com/cloudfoundry/cli/cf/api/authentication"
"github.com/cloudfoundry/cli/cf/api/stacks"
"github.com/cloudfoundry/cli/cf/app_files"
"github.com/cloudfoundry/cli/cf/command_metadata"
"github.com/cloudfoundry/cli/cf/commands/service"
"github.com/cloudfoundry/cli/cf/configuration/core_config"
"github.com/cloudfoundry/cli/cf/errors"
"github.com/cloudfoundry/cli/cf/flag_helpers"
"github.com/cloudfoundry/cli/cf/formatters"
"github.com/cloudfoundry/cli/cf/manifest"
"github.com/cloudfoundry/cli/cf/models"
"github.com/cloudfoundry/cli/cf/requirements"
"github.com/cloudfoundry/cli/cf/terminal"
"github.com/cloudfoundry/cli/words/generator"
"github.com/codegangsta/cli"
)
type Push struct {
ui terminal.UI
config core_config.Reader
manifestRepo manifest.ManifestRepository
appStarter ApplicationStarter
appStopper ApplicationStopper
serviceBinder service.ServiceBinder
appRepo applications.ApplicationRepository
domainRepo api.DomainRepository
routeRepo api.RouteRepository
serviceRepo api.ServiceRepository
stackRepo stacks.StackRepository
authRepo authentication.AuthenticationRepository
wordGenerator generator.WordGenerator
actor actors.PushActor
zipper app_files.Zipper
app_files app_files.AppFiles
}
func NewPush(ui terminal.UI, config core_config.Reader, manifestRepo manifest.ManifestRepository,
starter ApplicationStarter, stopper ApplicationStopper, binder service.ServiceBinder,
appRepo applications.ApplicationRepository, domainRepo api.DomainRepository, routeRepo api.RouteRepository,
stackRepo stacks.StackRepository, serviceRepo api.ServiceRepository,
authRepo authentication.AuthenticationRepository, wordGenerator generator.WordGenerator,
actor actors.PushActor, zipper app_files.Zipper, app_files app_files.AppFiles) *Push {
return &Push{
ui: ui,
config: config,
manifestRepo: manifestRepo,
appStarter: starter,
appStopper: stopper,
serviceBinder: binder,
appRepo: appRepo,
domainRepo: domainRepo,
routeRepo: routeRepo,
serviceRepo: serviceRepo,
stackRepo: stackRepo,
authRepo: authRepo,
wordGenerator: wordGenerator,
actor: actor,
zipper: zipper,
app_files: app_files,
}
}
func (cmd *Push) Metadata() command_metadata.CommandMetadata {
return command_metadata.CommandMetadata{
Name: "push",
ShortName: "p",
Description: T("Push a new app or sync changes to an existing app"),
Usage: T("Push a single app (with or without a manifest):\n") + T(" CF_NAME push APP_NAME [-b BUILDPACK_NAME] [-c COMMAND] [-d DOMAIN] [-f MANIFEST_PATH]\n") + T(" [-i NUM_INSTANCES] [-k DISK] [-m MEMORY] [-n HOST] [-p PATH] [-s STACK] [-t TIMEOUT]\n") +
" [--no-hostname] [--no-manifest] [--no-route] [--no-start]\n" +
"\n" + T(" Push multiple apps with a manifest:\n") + T(" CF_NAME push [-f MANIFEST_PATH]\n"),
Flags: []cli.Flag{
flag_helpers.NewStringFlag("b", T("Custom buildpack by name (e.g. my-buildpack) or GIT URL (e.g. 'https://github.com/heroku/heroku-buildpack-play.git') or GIT BRANCH URL (e.g. 'https://github.com/heroku/heroku-buildpack-play.git#develop' for 'develop' branch). Use built-in buildpacks only by setting value to 'null' or 'default'")),
flag_helpers.NewStringFlag("c", T("Startup command, set to null to reset to default start command")),
flag_helpers.NewStringFlag("d", T("Domain (e.g. example.com)")),
flag_helpers.NewStringFlag("f", T("Path to manifest")),
flag_helpers.NewIntFlag("i", T("Number of instances")),
flag_helpers.NewStringFlag("k", T("Disk limit (e.g. 256M, 1024M, 1G)")),
flag_helpers.NewStringFlag("m", T("Memory limit (e.g. 256M, 1024M, 1G)")),
flag_helpers.NewStringFlag("n", T("Hostname (e.g. my-subdomain)")),
flag_helpers.NewStringFlag("p", T("Path to app directory or file")),
flag_helpers.NewStringFlag("s", T("Stack to use (a stack is a pre-built file system, including an operating system, that can run apps)")),
flag_helpers.NewStringFlag("t", T("Maximum time (in seconds) for CLI to wait for application start, other server side timeouts may apply")),
cli.BoolFlag{Name: "no-hostname", Usage: T("Map the root domain to this app")},
cli.BoolFlag{Name: "no-manifest", Usage: T("Ignore manifest file")},
cli.BoolFlag{Name: "no-route", Usage: T("Do not map a route to this app and remove routes from previous pushes of this app.")},
cli.BoolFlag{Name: "no-start", Usage: T("Do not start an app after pushing")},
cli.BoolFlag{Name: "random-route", Usage: T("Create a random route for this app")},
},
}
}
func (cmd *Push) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) > 1 {
cmd.ui.FailWithUsage(c)
}
reqs = []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
requirementsFactory.NewTargetedSpaceRequirement(),
}
return
}
func (cmd *Push) Run(c *cli.Context) {
appSet := cmd.findAndValidateAppsToPush(c)
_, apiErr := cmd.authRepo.RefreshAuthToken()
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
routeActor := actors.NewRouteActor(cmd.ui, cmd.routeRepo)
for _, appParams := range appSet {
cmd.fetchStackGuid(&appParams)
app := cmd.createOrUpdateApp(appParams)
cmd.updateRoutes(routeActor, app, appParams)
cmd.ui.Say(T("Uploading {{.AppName}}...",
map[string]interface{}{"AppName": terminal.EntityNameColor(app.Name)}))
apiErr := cmd.uploadApp(app.Guid, *appParams.Path)
if apiErr != nil {
cmd.ui.Failed(fmt.Sprintf(T("Error uploading application.\n{{.ApiErr}}",
map[string]interface{}{"ApiErr": apiErr.Error()})))
return
}
cmd.ui.Ok()
if appParams.ServicesToBind != nil {
cmd.bindAppToServices(*appParams.ServicesToBind, app)
}
cmd.restart(app, appParams, c)
}
}
func (cmd *Push) updateRoutes(routeActor actors.RouteActor, app models.Application, appParams models.AppParams) {
defaultRouteAcceptable := len(app.Routes) == 0
routeDefined := appParams.Domains != nil || !appParams.IsHostEmpty() || appParams.NoHostname
if appParams.NoRoute {
cmd.removeRoutes(app, routeActor)
return
}
if routeDefined || defaultRouteAcceptable {
if appParams.Domains == nil {
cmd.processDomainsAndBindRoutes(appParams, routeActor, app, cmd.findDomain(nil))
} else {
for _, d := range *(appParams.Domains) {
cmd.processDomainsAndBindRoutes(appParams, routeActor, app, cmd.findDomain(&d))
}
}
}
}
func (cmd *Push) processDomainsAndBindRoutes(appParams models.AppParams, routeActor actors.RouteActor, app models.Application, domain models.DomainFields) {
if appParams.IsHostEmpty() {
cmd.createAndBindRoute(nil, appParams.UseRandomHostname, routeActor, app, appParams.NoHostname, domain)
} else {
for _, host := range *(appParams.Hosts) {
cmd.createAndBindRoute(&host, appParams.UseRandomHostname, routeActor, app, appParams.NoHostname, domain)
}
}
}
func (cmd *Push) createAndBindRoute(host *string, UseRandomHostname bool, routeActor actors.RouteActor, app models.Application, noHostName bool, domain models.DomainFields) {
hostname := cmd.hostnameForApp(host, UseRandomHostname, app.Name, noHostName)
route := routeActor.FindOrCreateRoute(hostname, domain)
routeActor.BindRoute(app, route)
}
func (cmd *Push) removeRoutes(app models.Application, routeActor actors.RouteActor) {
if len(app.Routes) == 0 {
cmd.ui.Say(T("App {{.AppName}} is a worker, skipping route creation",
map[string]interface{}{"AppName": terminal.EntityNameColor(app.Name)}))
} else {
routeActor.UnbindAll(app)
}
}
func (cmd *Push) hostnameForApp(host *string, useRandomHostName bool, name string, noHostName bool) string {
if noHostName {
return ""
}
if host != nil {
return *host
} else if useRandomHostName {
return hostNameForString(name) + "-" + cmd.wordGenerator.Babble()
} else {
return hostNameForString(name)
}
}
var forbiddenHostCharRegex = regexp.MustCompile("[^a-z0-9-]")
var whitespaceRegex = regexp.MustCompile(`[\s_]+`)
func hostNameForString(name string) string {
name = strings.ToLower(name)
name = whitespaceRegex.ReplaceAllString(name, "-")
name = forbiddenHostCharRegex.ReplaceAllString(name, "")
return name
}
func (cmd *Push) findDomain(domainName *string) (domain models.DomainFields) {
domain, error := cmd.domainRepo.FirstOrDefault(cmd.config.OrganizationFields().Guid, domainName)
if error != nil {
cmd.ui.Failed(error.Error())
}
return
}
func (cmd *Push) bindAppToServices(services []string, app models.Application) {
for _, serviceName := range services {
serviceInstance, err := cmd.serviceRepo.FindInstanceByName(serviceName)
if err != nil {
cmd.ui.Failed(T("Could not find service {{.ServiceName}} to bind to {{.AppName}}",
map[string]interface{}{"ServiceName": serviceName, "AppName": app.Name}))
return
}
cmd.ui.Say(T("Binding service {{.ServiceName}} to app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...",
map[string]interface{}{
"ServiceName": terminal.EntityNameColor(serviceInstance.Name),
"AppName": terminal.EntityNameColor(app.Name),
"OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"Username": terminal.EntityNameColor(cmd.config.Username())}))
err = cmd.serviceBinder.BindApplication(app, serviceInstance)
switch httpErr := err.(type) {
case errors.HttpError:
if httpErr.ErrorCode() == errors.APP_ALREADY_BOUND {
err = nil
}
}
if err != nil {
cmd.ui.Failed(T("Could not bind to service {{.ServiceName}}\nError: {{.Err}}",
map[string]interface{}{"ServiceName": serviceName, "Err": err.Error()}))
}
cmd.ui.Ok()
}
}
func (cmd *Push) fetchStackGuid(appParams *models.AppParams) {
if appParams.StackName == nil {
return
}
stackName := *appParams.StackName
cmd.ui.Say(T("Using stack {{.StackName}}...",
map[string]interface{}{"StackName": terminal.EntityNameColor(stackName)}))
stack, apiErr := cmd.stackRepo.FindByName(stackName)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
return
}
cmd.ui.Ok()
appParams.StackGuid = &stack.Guid
}
func (cmd *Push) restart(app models.Application, params models.AppParams, c *cli.Context) {
if app.State != T("stopped") {
cmd.ui.Say("")
app, _ = cmd.appStopper.ApplicationStop(app, cmd.config.OrganizationFields().Name, cmd.config.SpaceFields().Name)
}
cmd.ui.Say("")
if c.Bool("no-start") {
return
}
if params.HealthCheckTimeout != nil {
cmd.appStarter.SetStartTimeoutInSeconds(*params.HealthCheckTimeout)
}
//here we instantiate a new noaa object on every restart
//reusing an existing noaa connection to re-connect multiple times might not be successful,
//we have seen CLI stalls because noaa is not calling back on connect.
cmd.appStarter.RenewNoaaConsumer()
cmd.appStarter.ApplicationStart(app, cmd.config.OrganizationFields().Name, cmd.config.SpaceFields().Name)
}
func (cmd *Push) createOrUpdateApp(appParams models.AppParams) (app models.Application) {
if appParams.Name == nil {
cmd.ui.Failed(T("Error: No name found for app"))
}
app, apiErr := cmd.appRepo.Read(*appParams.Name)
switch apiErr.(type) {
case nil:
app = cmd.updateApp(app, appParams)
case *errors.ModelNotFoundError:
app = cmd.createApp(appParams)
default:
cmd.ui.Failed(apiErr.Error())
}
return
}
func (cmd *Push) createApp(appParams models.AppParams) (app models.Application) {
spaceGuid := cmd.config.SpaceFields().Guid
appParams.SpaceGuid = &spaceGuid
cmd.ui.Say(T("Creating app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...",
map[string]interface{}{
"AppName": terminal.EntityNameColor(*appParams.Name),
"OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"Username": terminal.EntityNameColor(cmd.config.Username())}))
app, apiErr := cmd.appRepo.Create(appParams)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
}
cmd.ui.Ok()
cmd.ui.Say("")
return
}
func (cmd *Push) updateApp(app models.Application, appParams models.AppParams) (updatedApp models.Application) {
cmd.ui.Say(T("Updating app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...",
map[string]interface{}{
"AppName": terminal.EntityNameColor(app.Name),
"OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"Username": terminal.EntityNameColor(cmd.config.Username())}))
if appParams.EnvironmentVars != nil {
for key, val := range app.EnvironmentVars {
if _, ok := (*appParams.EnvironmentVars)[key]; !ok {
(*appParams.EnvironmentVars)[key] = val
}
}
}
var apiErr error
updatedApp, apiErr = cmd.appRepo.Update(app.Guid, appParams)
if apiErr != nil {
cmd.ui.Failed(apiErr.Error())
}
cmd.ui.Ok()
cmd.ui.Say("")
return
}
func (cmd *Push) findAndValidateAppsToPush(c *cli.Context) []models.AppParams {
appsFromManifest := cmd.getAppParamsFromManifest(c)
appFromContext := cmd.getAppParamsFromContext(c)
return cmd.createAppSetFromContextAndManifest(appFromContext, appsFromManifest)
}
func (cmd *Push) getAppParamsFromManifest(c *cli.Context) []models.AppParams {
if c.Bool("no-manifest") {
return []models.AppParams{}
}
var path string
if c.String("f") != "" {
path = c.String("f")
} else {
var err error
path, err = os.Getwd()
if err != nil {
cmd.ui.Failed(T("Could not determine the current working directory!"), err)
}
}
m, err := cmd.manifestRepo.ReadManifest(path)
if err != nil {
if m.Path == "" && c.String("f") == "" {
return []models.AppParams{}
} else {
cmd.ui.Failed(T("Error reading manifest file:\n{{.Err}}", map[string]interface{}{"Err": err.Error()}))
}
}
apps, err := m.Applications()
if err != nil {
cmd.ui.Failed("Error reading manifest file:\n%s", err)
}
cmd.ui.Say(T("Using manifest file {{.Path}}\n",
map[string]interface{}{"Path": terminal.EntityNameColor(m.Path)}))
return apps
}
func (cmd *Push) createAppSetFromContextAndManifest(contextApp models.AppParams, manifestApps []models.AppParams) (apps []models.AppParams) {
var err error
switch len(manifestApps) {
case 0:
if contextApp.Name == nil {
err = errors.New(T("Manifest file is not found in the current directory, please provide either an app name or manifest"))
} else {
err = addApp(&apps, contextApp)
}
case 1:
manifestApps[0].Merge(&contextApp)
err = addApp(&apps, manifestApps[0])
default:
selectedAppName := contextApp.Name
contextApp.Name = nil
if !contextApp.IsEmpty() {
cmd.ui.Failed("%s", T("Incorrect Usage. Command line flags (except -f) cannot be applied when pushing multiple apps from a manifest file."))
}
if selectedAppName != nil {
var manifestApp models.AppParams
manifestApp, err = findAppWithNameInManifest(*selectedAppName, manifestApps)
if err == nil {
addApp(&apps, manifestApp)
}
} else {
for _, manifestApp := range manifestApps {
addApp(&apps, manifestApp)
}
}
}
if err != nil {
cmd.ui.Failed(T("Error: {{.Err}}", map[string]interface{}{"Err": err.Error()}))
}
return
}
func addApp(apps *[]models.AppParams, app models.AppParams) (err error) {
if app.Name == nil {
err = errors.New(T("App name is a required field"))
}
if app.Path == nil {
cwd, _ := os.Getwd()
app.Path = &cwd
}
*apps = append(*apps, app)
return
}
func findAppWithNameInManifest(name string, manifestApps []models.AppParams) (app models.AppParams, err error) {
for _, appParams := range manifestApps {
if appParams.Name != nil && *appParams.Name == name {
app = appParams
return
}
}
err = errors.New(T("Could not find app named '{{.AppName}}' in manifest",
map[string]interface{}{"AppName": name}))
return
}
func (cmd *Push) getAppParamsFromContext(c *cli.Context) (appParams models.AppParams) {
if len(c.Args()) > 0 {
appParams.Name = &c.Args()[0]
}
appParams.NoRoute = c.Bool("no-route")
appParams.UseRandomHostname = c.Bool("random-route")
appParams.NoHostname = c.Bool("no-hostname")
if c.String("n") != "" {
appParams.Hosts = &[]string{c.String("n")}
}
if c.String("b") != "" {
buildpack := c.String("b")
if buildpack == "null" || buildpack == "default" {
buildpack = ""
}
appParams.BuildpackUrl = &buildpack
}
if c.String("c") != "" {
command := c.String("c")
if command == "null" || command == "default" {
command = ""
}
appParams.Command = &command
}
if c.String("d") != "" {
appParams.Domains = &[]string{c.String("d")}
}
if c.IsSet("i") {
instances := c.Int("i")
if instances < 1 {
cmd.ui.Failed(T("Invalid instance count: {{.InstancesCount}}\nInstance count must be a positive integer",
map[string]interface{}{"InstancesCount": instances}))
}
appParams.InstanceCount = &instances
}
if c.String("k") != "" {
diskQuota, err := formatters.ToMegabytes(c.String("k"))
if err != nil {
cmd.ui.Failed(T("Invalid disk quota: {{.DiskQuota}}\n{{.Err}}",
map[string]interface{}{"DiskQuota": c.String("k"), "Err": err.Error()}))
}
appParams.DiskQuota = &diskQuota
}
if c.String("m") != "" {
memory, err := formatters.ToMegabytes(c.String("m"))
if err != nil {
cmd.ui.Failed(T("Invalid memory limit: {{.MemLimit}}\n{{.Err}}",
map[string]interface{}{"MemLimit": c.String("m"), "Err": err.Error()}))
}
appParams.Memory = &memory
}
if c.String("p") != "" {
path := c.String("p")
appParams.Path = &path
}
if c.String("s") != "" {
stackName := c.String("s")
appParams.StackName = &stackName
}
if c.String("t") != "" {
timeout, err := strconv.Atoi(c.String("t"))
if err != nil {
cmd.ui.Failed("Error: %s", errors.NewWithFmt(T("Invalid timeout param: {{.Timeout}}\n{{.Err}}",
map[string]interface{}{"Timeout": c.String("t"), "Err": err.Error()})))
}
appParams.HealthCheckTimeout = &timeout
}
return
}
func (cmd *Push) uploadApp(appGuid string, appDir string) (apiErr error) {
fileutils.TempDir("apps", func(uploadDir string, err error) {
if err != nil {
apiErr = err
return
}
presentFiles, err := cmd.actor.GatherFiles(appDir, uploadDir)
if err != nil {
apiErr = err
return
}
fileutils.TempFile("uploads", func(zipFile *os.File, err error) {
err = cmd.zipAppFiles(zipFile, appDir, uploadDir)
if err != nil {
apiErr = err
return
}
err = cmd.actor.UploadApp(appGuid, zipFile, presentFiles)
if err != nil {
apiErr = err
return
}
})
return
})
return
}
func (cmd *Push) zipAppFiles(zipFile *os.File, appDir string, uploadDir string) (zipErr error) {
zipErr = cmd.zipWithBetterErrors(uploadDir, zipFile)
if zipErr != nil {
return
}
zipFileSize, zipErr := cmd.zipper.GetZipSize(zipFile)
if zipErr != nil {
return
}
zipFileCount := cmd.app_files.CountFiles(uploadDir)
cmd.describeUploadOperation(appDir, zipFileSize, zipFileCount)
return
}
func (cmd *Push) zipWithBetterErrors(uploadDir string, zipFile *os.File) error {
zipError := cmd.zipper.Zip(uploadDir, zipFile)
switch err := zipError.(type) {
case nil:
return nil
case *errors.EmptyDirError:
zipFile = nil
return zipError
default:
return errors.NewWithError(T("Error zipping application"), err)
}
}
func (cmd *Push) describeUploadOperation(path string, zipFileBytes, fileCount int64) {
if fileCount > 0 {
cmd.ui.Say(T("Uploading app files from: {{.Path}}", map[string]interface{}{"Path": path}))
cmd.ui.Say(T("Uploading {{.ZipFileBytes}}, {{.FileCount}} files",
map[string]interface{}{
"ZipFileBytes": formatters.ByteSize(zipFileBytes),
"FileCount": fileCount}))
} else {
cmd.ui.Warn(T("None of your application files have changed. Nothing will be uploaded."))
}
}