@@ -12,6 +12,7 @@ import (
1212 "github.com/spf13/cobra"
1313
1414 "github.com/replicate/cog/pkg/api"
15+ "github.com/replicate/cog/pkg/coglog"
1516 "github.com/replicate/cog/pkg/docker"
1617 "github.com/replicate/cog/pkg/http"
1718 "github.com/replicate/cog/pkg/util/console"
@@ -117,9 +118,24 @@ func imageToDir(image string, projectDir string) string {
117118func pull (cmd * cobra.Command , args []string ) error {
118119 ctx := cmd .Context ()
119120
121+ // Create the clients
122+ dockerClient , err := docker .NewClient (ctx )
123+ if err != nil {
124+ return err
125+ }
126+
127+ client , err := http .ProvideHTTPClient (ctx , dockerClient )
128+ if err != nil {
129+ return err
130+ }
131+
132+ logClient := coglog .NewClient (client )
133+ logCtx := logClient .StartPull ()
134+
120135 // Find image name
121136 projectDir , err := os .Getwd ()
122137 if err != nil {
138+ logClient .EndPull (ctx , err , logCtx )
123139 return err
124140 }
125141 image := args [0 ]
@@ -128,32 +144,27 @@ func pull(cmd *cobra.Command, args []string) error {
128144 projectDir = imageToDir (image , projectDir )
129145 err = os .MkdirAll (projectDir , 0o755 )
130146 if err != nil {
131- return err
132- }
133-
134- // Create the clients
135- dockerClient , err := docker .NewClient (ctx )
136- if err != nil {
147+ logClient .EndPull (ctx , err , logCtx )
137148 return err
138149 }
139150
140151 // Check if we are in a pipeline
141152 if ! pushPipeline {
142- return errors .New ("Please use docker pull " + image + " to download this model." )
143- }
144-
145- client , err := http .ProvideHTTPClient (ctx , dockerClient )
146- if err != nil {
153+ err = errors .New ("Please use docker pull " + image + " to download this model." )
154+ logClient .EndPull (ctx , err , logCtx )
147155 return err
148156 }
157+
149158 webClient := web .NewClient (dockerClient , client )
150159 apiClient := api .NewClient (dockerClient , client , webClient )
151160
152161 // Pull the source
153162 err = apiClient .PullSource (ctx , image , extractTarFile (projectDir ))
154163 if err != nil {
164+ logClient .EndPull (ctx , err , logCtx )
155165 return err
156166 }
157167
168+ logClient .EndPull (ctx , nil , logCtx )
158169 return nil
159170}
0 commit comments