Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement pre-build repository check for Replicate images #1733

Merged
merged 4 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pkg/cli/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ func push(cmd *cobra.Command, args []string) error {
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'")
}

replicatePrefix := fmt.Sprintf("%s/", global.ReplicateRegistryHost)
if strings.HasPrefix(imageName, replicatePrefix) {
if err := docker.ManifestInspect(imageName); err != nil && strings.Contains(err.Error(), `"code":"NAME_UNKNOWN"`) {
return fmt.Errorf("Unable to find Replicate existing model for %s. Go to replicate.com and create a new model before pushing.", imageName)
}
}

if err := image.Build(cfg, projectDir, imageName, buildSecrets, buildNoCache, buildSeparateWeights, buildUseCudaBaseImage, buildProgressOutput, buildSchemaFile, buildDockerfileFile, buildUseCogBaseImage); err != nil {
return err
}
Expand All @@ -58,7 +65,6 @@ func push(cmd *cobra.Command, args []string) error {
exitStatus := docker.Push(imageName)
if exitStatus == nil {
console.Infof("Image '%s' pushed", imageName)
replicatePrefix := fmt.Sprintf("%s/", global.ReplicateRegistryHost)
if strings.HasPrefix(imageName, replicatePrefix) {
replicatePage := fmt.Sprintf("https://%s", strings.Replace(imageName, global.ReplicateRegistryHost, global.ReplicateWebsiteHost, 1))
console.Infof("\nRun your model on Replicate:\n %s", replicatePage)
Expand Down
27 changes: 27 additions & 0 deletions pkg/docker/manifest_inspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package docker

import (
"os/exec"
"strings"

"github.com/replicate/cog/pkg/util/console"
)

func ManifestInspect(image string) error {
cmd := exec.Command("docker", "manifest", "inspect", image)
var out strings.Builder
cmd.Stdout = &out
cmd.Stderr = &out

console.Debug("$ " + strings.Join(cmd.Args, " "))
err := cmd.Run()

if err != nil {
output := out.String()
if strings.Contains(output, "no such manifest") || strings.Contains(output, "manifest unknown") || strings.Contains(output, "not found") {
return nil
}
return err
}
return nil
}