@@ -72,11 +72,11 @@ func MakeDeployHandler(client *containerd.Client, cni gocni.CNI, secretMountPath
72
72
// prepull is an optimization which means an image can be pulled before a deployment
73
73
// request, since a deployment request first deletes the active function before
74
74
// trying to deploy a new one.
75
- func prepull (ctx context.Context , req types.FunctionDeployment , client * containerd.Client , alwaysPull bool ) error {
75
+ func prepull (ctx context.Context , req types.FunctionDeployment , client * containerd.Client , alwaysPull bool ) (containerd. Image , error ) {
76
76
start := time .Now ()
77
77
r , err := reference .ParseNormalizedNamed (req .Image )
78
78
if err != nil {
79
- return err
79
+ return nil , err
80
80
}
81
81
82
82
imgRef := reference .TagNameOnly (r ).String ()
@@ -88,38 +88,27 @@ func prepull(ctx context.Context, req types.FunctionDeployment, client *containe
88
88
89
89
image , err := service .PrepareImage (ctx , client , imgRef , snapshotter , alwaysPull )
90
90
if err != nil {
91
- return errors .Wrapf (err , "unable to pull image %s" , imgRef )
91
+ return nil , errors .Wrapf (err , "unable to pull image %s" , imgRef )
92
92
}
93
93
94
94
size , _ := image .Size (ctx )
95
- log .Printf ("[Prepull] Deploy %s size: %d, took: %fs\n " , image .Name (), size , time .Since (start ).Seconds ())
95
+ log .Printf ("Image for: %s size: %d, took: %fs\n " , image .Name (), size , time .Since (start ).Seconds ())
96
96
97
- return nil
97
+ return image , nil
98
98
}
99
99
100
100
func deploy (ctx context.Context , req types.FunctionDeployment , client * containerd.Client , cni gocni.CNI , secretMountPath string , alwaysPull bool ) error {
101
- start := time .Now ()
102
-
103
- r , err := reference .ParseNormalizedNamed (req .Image )
104
- if err != nil {
105
- return err
106
- }
107
-
108
- imgRef := reference .TagNameOnly (r ).String ()
109
101
110
102
snapshotter := ""
111
103
if val , ok := os .LookupEnv ("snapshotter" ); ok {
112
104
snapshotter = val
113
105
}
114
106
115
- image , err := service . PrepareImage (ctx , client , imgRef , snapshotter , alwaysPull )
107
+ image , err := prepull (ctx , req , client , alwaysPull )
116
108
if err != nil {
117
- return errors . Wrapf ( err , "unable to pull image %s" , imgRef )
109
+ return err
118
110
}
119
111
120
- size , _ := image .Size (ctx )
121
- log .Printf ("[deploy] Deploy %s size: %d, took: %fs\n " , image .Name (), size , time .Since (start ).Seconds ())
122
-
123
112
envs := prepareEnv (req .EnvProcess , req .EnvVars )
124
113
mounts := getMounts ()
125
114
0 commit comments