Skip to content
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
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ require (
github.com/tonistiigi/go-csvvalue v0.0.0-20240814133006-030d3b2625d0
github.com/vincent-petithory/dataurl v1.0.0
github.com/xeipuuv/gojsonschema v1.2.0
github.com/xeonx/timeago v1.0.0-rc5
go.yaml.in/yaml/v4 v4.0.0-rc.4
golang.org/x/crypto v0.50.0
golang.org/x/exp v0.0.0-20250911091902-df9299821621
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
github.com/xeonx/timeago v1.0.0-rc5 h1:pwcQGpaH3eLfPtXeyPA4DmHWjoQt0Ea7/++FwpxqLxg=
github.com/xeonx/timeago v1.0.0-rc5/go.mod h1:qDLrYEFynLO7y5Ho7w3GwgtYgpy5UfhcXIIQvMKVDkA=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
Expand Down
8 changes: 0 additions & 8 deletions pkg/config/build_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,3 @@ type BuildOptions struct {
// If empty, inline caching is used instead of local cache.
XCachePath string
}

// DefaultBuildOptions returns BuildOptions with sensible defaults.
func DefaultBuildOptions() BuildOptions {
return BuildOptions{
SourceEpochTimestamp: -1,
XCachePath: "",
}
}
9 changes: 0 additions & 9 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,6 @@ type Config struct {
parsedEnvironment map[string]string
}

func defaultConfig() *Config {
return &Config{
Build: &Build{
GPU: false,
PythonVersion: "3.13",
},
}
}

func (r *RunItem) UnmarshalYAML(unmarshal func(any) error) error {
var commandOrMap any
if err := unmarshal(&commandOrMap); err != nil {
Expand Down
23 changes: 9 additions & 14 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,19 +589,14 @@ torch==1.12.1`

func TestBlankBuild(t *testing.T) {
// Naively, this turns into nil, so make sure it's a real build object
// Write a temp file
dir := t.TempDir()
configPath := path.Join(dir, "cog.yaml")
err := os.WriteFile(configPath, []byte(`build:`), 0o644)
require.NoError(t, err)

cfgFile, err := parseFile(configPath)
cfgFile, err := parseBytes([]byte(`build:`))
require.NoError(t, err)
// Note: `build:` by itself in YAML parses to Build: nil (empty map becomes nil pointer)
// The completion step should create a default Build

config, err := configFileToConfig(cfgFile)
require.NoError(t, err)
dir := t.TempDir()
require.NoError(t, config.Complete(dir))
require.NotNil(t, config.Build)
require.Equal(t, false, config.Build.GPU)
Expand Down Expand Up @@ -637,17 +632,17 @@ build:
run:
- command: "echo 'Hello, World!'"
`
dir := t.TempDir()
configPath := path.Join(dir, "cog.yaml")
err := os.WriteFile(configPath, []byte(yamlString), 0o644)
require.NoError(t, err)

_, err = parseFile(configPath)
_, err := parseBytes([]byte(yamlString))
require.NoError(t, err)
}

func TestConfigMarshal(t *testing.T) {
cfg := defaultConfig()
cfg := &Config{
Build: &Build{
GPU: false,
PythonVersion: "3.13",
},
}
data, err := yaml.Marshal(cfg)
require.NoError(t, err)
// yaml v4 uses 4-space indentation by default
Expand Down
39 changes: 0 additions & 39 deletions pkg/config/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ package config
import (
"fmt"
"io"
"os"
"path/filepath"

"go.yaml.in/yaml/v4"

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

// parse reads and parses YAML content from an io.Reader into a configFile.
Expand All @@ -23,41 +19,6 @@ func parse(r io.Reader) (*configFile, error) {
return parseBytes(contents)
}

// parseFile reads and parses a cog.yaml file into a configFile.
// This only does YAML parsing - no validation or defaults.
// Returns ParseError if the file cannot be read or parsed.
func parseFile(filename string) (*configFile, error) {
exists, err := files.Exists(filename)
if err != nil {
return nil, &ParseError{Filename: filename, Err: err}
}

if !exists {
return nil, &ParseError{
Filename: filename,
Err: fmt.Errorf("%s does not exist in %s", filepath.Base(filename), filepath.Dir(filename)),
}
}

f, err := os.Open(filename)
if err != nil {
return nil, &ParseError{Filename: filename, Err: err}
}
defer f.Close()

cfg, err := parse(f)
if err != nil {
// Add filename context to the error
if parseErr, ok := err.(*ParseError); ok {
parseErr.Filename = filename
return nil, parseErr
}
return nil, &ParseError{Filename: filename, Err: err}
}

return cfg, nil
}

// parseBytes parses YAML content into a configFile.
func parseBytes(contents []byte) (*configFile, error) {
cfg := &configFile{}
Expand Down
14 changes: 0 additions & 14 deletions pkg/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,6 @@ func WithProjectDir(dir string) ValidateOption {
}
}

// WithRequirementsFS sets the filesystem for reading python_requirements file.
func WithRequirementsFS(fsys fs.FS) ValidateOption {
return func(o *validateOptions) {
o.requirementsFS = fsys
}
}

// WithStrictDeprecations treats deprecation warnings as errors.
func WithStrictDeprecations() ValidateOption {
return func(o *validateOptions) {
o.strictDeprecations = true
}
}

// ValidateConfigFile checks a configFile for errors.
// Returns all validation errors and deprecation warnings.
// Does not mutate the input.
Expand Down
2 changes: 0 additions & 2 deletions pkg/docker/docker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,6 @@ func TestDockerClient(t *testing.T) {
// Try to push to the mock registry
err = dockerClient.Push(t.Context(), ref.String())
require.Error(t, err, "Push should fail with unreachable registry")

assert.True(t, isNetworkError(err), "Error should be a network error, got: %q", err.Error())
})

t.Run("missing image", func(t *testing.T) {
Expand Down
13 changes: 0 additions & 13 deletions pkg/docker/env.go

This file was deleted.

33 changes: 0 additions & 33 deletions pkg/docker/errors.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package docker

import (
"errors"
"strings"
)

Expand Down Expand Up @@ -47,35 +46,3 @@ func isMissingDeviceDriverError(err error) bool {
return strings.Contains(msg, "could not select device driver") ||
strings.Contains(msg, "nvidia-container-cli: initialization error")
}

// isNetworkError checks if the error is a network error. This is janky and intended for use in tests only
func isNetworkError(err error) bool {
// for both CLI and API clients, network errors are wrapped and lose the net.Error interface
// CLI client: wrapped by exec.Command as exec.ExitError
// API client: wrapped by JSON message stream processing
// Sad as it may be, we rely on string matching for common network error messages

msg := err.Error()
networkErrorStrings := []string{
"connection refused",
"connection reset by peer",
"dial tcp",
"EOF",
"no route to host",
"network is unreachable",
"server closed",
}

for _, errStr := range networkErrorStrings {
if strings.Contains(msg, errStr) {
return true
}
}

// also check wrapped errors
if unwrapped := errors.Unwrap(err); unwrapped != nil {
return isNetworkError(unwrapped)
}

return false
}
26 changes: 0 additions & 26 deletions pkg/docker/push.go

This file was deleted.

11 changes: 0 additions & 11 deletions pkg/dockerfile/version_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,9 @@ func parse(s string) (string, string, string) {
minor := m[versionRegex.SubexpIndex("minor")]
patch := m[versionRegex.SubexpIndex("patch")]
return major, minor, patch

}

func CheckMajorOnly(s string) bool {
major, minor, patch := parse(s)
return major != "" && minor == "" && patch == ""
}

func CheckMajorMinorOnly(s string) bool {
major, minor, patch := parse(s)
return major != "" && minor != "" && patch == ""
}

func CheckMajorMinorPatch(s string) bool {
major, minor, patch := parse(s)
return major != "" && minor != "" && patch != ""
}
26 changes: 0 additions & 26 deletions pkg/dockerignore/dockerignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,6 @@ func CreateMatcher(dir string) (*ignore.GitIgnore, error) {
return ignore.CompileIgnoreLines(patterns...), nil
}

func Walk(root string, ignoreMatcher *ignore.GitIgnore, fn filepath.WalkFunc) error {
return filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

// We ignore files ignored by .dockerignore
if ignoreMatcher != nil && ignoreMatcher.MatchesPath(path) {
if info.IsDir() {
return filepath.SkipDir
}
return nil
}

if info.IsDir() && info.Name() == ".cog" {
return filepath.SkipDir
}

if info.Name() == DockerIgnoreFilename {
return nil
}

return fn(path, info, err)
})
}

func readDockerIgnore(dockerIgnorePath string) ([]string, error) {
var patterns []string
file, err := os.Open(dockerIgnorePath)
Expand Down
56 changes: 0 additions & 56 deletions pkg/dockerignore/dockerignore_test.go

This file was deleted.

Loading
Loading