@@ -22,6 +22,7 @@ import (
22
22
"io/ioutil"
23
23
"time"
24
24
25
+ "github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
25
26
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
26
27
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
27
28
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
@@ -56,55 +57,75 @@ func doDiagnose(out io.Writer) error {
56
57
fmt .Fprintln (out , "Configuration version:" , config .APIVersion )
57
58
fmt .Fprintln (out , "Number of artifacts:" , len (config .Build .Artifacts ))
58
59
59
- fmt .Fprintln (out , "\n Running a diagnostic on artifacts and their dependencies:" )
60
-
61
60
if err := diagnoseArtifacts (out , config .Build .Artifacts ); err != nil {
62
61
return errors .Wrap (err , "running diagnostic on artifacts" )
63
62
}
64
63
65
- fmt .Fprintln (out , "\n Second run (that benefits from cache):" )
66
-
67
- if err := diagnoseArtifacts (out , config .Build .Artifacts ); err != nil {
68
- return errors .Wrap (err , "running second diagnostic on artifacts" )
69
- }
70
-
71
64
return nil
72
65
}
73
66
74
67
func diagnoseArtifacts (out io.Writer , artifacts []* latest.Artifact ) error {
75
68
for _ , artifact := range artifacts {
76
- start := time .Now ()
77
- deps , err := runner .DependenciesForArtifact (artifact )
78
- if err != nil {
79
- return errors .Wrap (err , "listing artifact dependencies" )
80
- }
81
-
82
- fmt .Fprintln (out , "Type:" , typeOfArtifact (artifact ))
83
- fmt .Fprintln (out , " - Dependencies to watch:" , len (deps ))
84
- fmt .Fprintln (out , " - Time to list dependencies:" , time .Since (start ))
69
+ color .Default .Fprintf (out , "\n %s: %s\n " , typeOfArtifact (artifact ), artifact .ImageName )
85
70
86
71
if artifact .DockerArtifact != nil {
87
- size , err := sizeOfTheDockerContext (artifact )
72
+ size , err := sizeOfDockerContext (artifact )
88
73
if err != nil {
89
74
return errors .Wrap (err , "computing the size of the Docker context" )
90
75
}
91
76
92
- fmt .Fprintln (out , " - Size of the Docker context:" , size )
77
+ fmt .Fprintf (out , " - Size of the context: %vbytes \n " , size )
93
78
}
94
79
95
- start = time .Now ()
96
- _ , err = watch .Stat (func () ([]string , error ) { return deps , nil })
80
+ timeDeps1 , deps , err := timeToListDependencies (artifact )
81
+ if err != nil {
82
+ return errors .Wrap (err , "listing artifact dependencies" )
83
+ }
84
+ timeDeps2 , _ , err := timeToListDependencies (artifact )
85
+ if err != nil {
86
+ return errors .Wrap (err , "listing artifact dependencies" )
87
+ }
88
+
89
+ fmt .Fprintln (out , " - Dependencies:" , len (deps ), "files" )
90
+ fmt .Fprintf (out , " - Time to list dependencies: %v (2nd time: %v)\n " , timeDeps1 , timeDeps2 )
91
+
92
+ timeMTimes1 , err := timeToComputeMTimes (deps )
93
+ if err != nil {
94
+ return errors .Wrap (err , "computing modTimes" )
95
+ }
96
+ timeMTimes2 , err := timeToComputeMTimes (deps )
97
97
if err != nil {
98
98
return errors .Wrap (err , "computing modTimes" )
99
99
}
100
100
101
- fmt .Fprintln (out , " - Time to compute mTimes for all dependencies:" , time . Since ( start ) )
101
+ fmt .Fprintf (out , " - Time to compute mTimes on dependencies: %v (2nd time: %v) \n " , timeMTimes1 , timeMTimes2 )
102
102
}
103
103
104
104
return nil
105
105
}
106
106
107
- func sizeOfTheDockerContext (a * latest.Artifact ) (int64 , error ) {
107
+ func timeToListDependencies (a * latest.Artifact ) (time.Duration , []string , error ) {
108
+ start := time .Now ()
109
+
110
+ deps , err := runner .DependenciesForArtifact (a )
111
+ if err != nil {
112
+ return 0 , nil , errors .Wrap (err , "listing artifact dependencies" )
113
+ }
114
+
115
+ return time .Since (start ), deps , nil
116
+ }
117
+
118
+ func timeToComputeMTimes (deps []string ) (time.Duration , error ) {
119
+ start := time .Now ()
120
+
121
+ if _ , err := watch .Stat (func () ([]string , error ) { return deps , nil }); err != nil {
122
+ return 0 , errors .Wrap (err , "computing modTimes" )
123
+ }
124
+
125
+ return time .Since (start ), nil
126
+ }
127
+
128
+ func sizeOfDockerContext (a * latest.Artifact ) (int64 , error ) {
108
129
buildCtx , buildCtxWriter := io .Pipe ()
109
130
go func () {
110
131
err := docker .CreateDockerTarContext (buildCtxWriter , a .Workspace , a .DockerArtifact )
@@ -121,10 +142,10 @@ func sizeOfTheDockerContext(a *latest.Artifact) (int64, error) {
121
142
func typeOfArtifact (a * latest.Artifact ) string {
122
143
switch {
123
144
case a .DockerArtifact != nil :
124
- return "Docker"
145
+ return "Docker artifact "
125
146
case a .BazelArtifact != nil :
126
- return "Bazel"
147
+ return "Bazel artifact "
127
148
default :
128
- return "Unknown"
149
+ return "Unknown artifact "
129
150
}
130
151
}
0 commit comments