@@ -9,9 +9,11 @@ import (
99
1010 "github.com/replicate/go/uuid"
1111
12+ "github.com/replicate/cog/pkg/coglog"
1213 "github.com/replicate/cog/pkg/config"
1314 "github.com/replicate/cog/pkg/docker"
1415 "github.com/replicate/cog/pkg/global"
16+ "github.com/replicate/cog/pkg/http"
1517 "github.com/replicate/cog/pkg/image"
1618 "github.com/replicate/cog/pkg/util/console"
1719)
@@ -44,8 +46,17 @@ func newPushCommand() *cobra.Command {
4446func push (cmd * cobra.Command , args []string ) error {
4547 ctx := cmd .Context ()
4648
49+ command := docker .NewDockerCommand ()
50+ client , err := http .ProvideHTTPClient (ctx , command )
51+ if err != nil {
52+ return err
53+ }
54+ logClient := coglog .NewClient (client )
55+ logCtx := logClient .StartPush (buildFast , buildLocalImage )
56+
4757 cfg , projectDir , err := config .GetConfig (projectDirFlag )
4858 if err != nil {
59+ logClient .EndPush (ctx , err , logCtx )
4960 return err
5061 }
5162 if cfg .Build .Fast {
@@ -58,17 +69,23 @@ func push(cmd *cobra.Command, args []string) error {
5869 }
5970
6071 if imageName == "" {
61- return fmt .Errorf ("To push images, you must either set the 'image' option in cog.yaml or pass an image name as an argument. For example, 'cog push r8.im/your-username/hotdog-detector'" )
72+ err = fmt .Errorf ("To push images, you must either set the 'image' option in cog.yaml or pass an image name as an argument. For example, 'cog push r8.im/your-username/hotdog-detector'" )
73+ logClient .EndPush (ctx , err , logCtx )
74+ return err
6275 }
6376
6477 replicatePrefix := fmt .Sprintf ("%s/" , global .ReplicateRegistryHost )
6578 if strings .HasPrefix (imageName , replicatePrefix ) {
6679 if err := docker .ManifestInspect (ctx , imageName ); err != nil && strings .Contains (err .Error (), `"code":"NAME_UNKNOWN"` ) {
67- return fmt .Errorf ("Unable to find Replicate existing model for %s. Go to replicate.com and create a new model before pushing." , imageName )
80+ err = fmt .Errorf ("Unable to find Replicate existing model for %s. Go to replicate.com and create a new model before pushing." , imageName )
81+ logClient .EndPush (ctx , err , logCtx )
82+ return err
6883 }
6984 } else {
7085 if buildLocalImage {
71- return fmt .Errorf ("Unable to push a local image model to a non replicate host, please disable the local image flag before pushing to this host." )
86+ err = fmt .Errorf ("Unable to push a local image model to a non replicate host, please disable the local image flag before pushing to this host." )
87+ logClient .EndPush (ctx , err , logCtx )
88+ return err
7289 }
7390 }
7491
@@ -83,7 +100,7 @@ func push(cmd *cobra.Command, args []string) error {
83100
84101 startBuildTime := time .Now ()
85102
86- if err := image .Build (ctx , cfg , projectDir , imageName , buildSecrets , buildNoCache , buildSeparateWeights , buildUseCudaBaseImage , buildProgressOutput , buildSchemaFile , buildDockerfileFile , DetermineUseCogBaseImage (cmd ), buildStrip , buildPrecompile , buildFast , annotations , buildLocalImage ); err != nil {
103+ if err := image .Build (ctx , cfg , projectDir , imageName , buildSecrets , buildNoCache , buildSeparateWeights , buildUseCudaBaseImage , buildProgressOutput , buildSchemaFile , buildDockerfileFile , DetermineUseCogBaseImage (cmd ), buildStrip , buildPrecompile , buildFast , annotations , buildLocalImage , command ); err != nil {
87104 return err
88105 }
89106
@@ -94,14 +111,13 @@ func push(cmd *cobra.Command, args []string) error {
94111 console .Info ("Fast push enabled." )
95112 }
96113
97- command := docker .NewDockerCommand ()
98114 err = docker .Push (ctx , imageName , buildFast , projectDir , command , docker.BuildInfo {
99115 BuildTime : buildDuration ,
100116 BuildID : buildID .String (),
101- })
117+ }, client )
102118 if err != nil {
103119 if strings .Contains (err .Error (), "404" ) {
104- return fmt .Errorf ("Unable to find existing Replicate model for %s. " +
120+ err = fmt .Errorf ("Unable to find existing Replicate model for %s. " +
105121 "Go to replicate.com and create a new model before pushing." +
106122 "\n \n " +
107123 "If the model already exists, you may be getting this error " +
@@ -110,15 +126,20 @@ func push(cmd *cobra.Command, args []string) error {
110126 "or `sudo cog push` instead of `cog push`, " +
111127 "which causes Docker to use the wrong Docker credentials." ,
112128 imageName )
129+ logClient .EndPush (ctx , err , logCtx )
130+ return err
113131 }
114- return fmt .Errorf ("Failed to push image: %w" , err )
132+ err = fmt .Errorf ("Failed to push image: %w" , err )
133+ logClient .EndPush (ctx , err , logCtx )
134+ return err
115135 }
116136
117137 console .Infof ("Image '%s' pushed" , imageName )
118138 if strings .HasPrefix (imageName , replicatePrefix ) {
119139 replicatePage := fmt .Sprintf ("https://%s" , strings .Replace (imageName , global .ReplicateRegistryHost , global .ReplicateWebsiteHost , 1 ))
120140 console .Infof ("\n Run your model on Replicate:\n %s" , replicatePage )
121141 }
142+ logClient .EndPush (ctx , nil , logCtx )
122143
123144 return nil
124145}
0 commit comments