-
Notifications
You must be signed in to change notification settings - Fork 696
Expand file tree
/
Copy pathdebug.go
More file actions
76 lines (63 loc) · 1.45 KB
/
Copy pathdebug.go
File metadata and controls
76 lines (63 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package cli
import (
"fmt"
"io/ioutil"
"os"
"path"
"github.com/spf13/cobra"
"github.com/replicate/cog/pkg/docker"
"github.com/replicate/cog/pkg/files"
"github.com/replicate/cog/pkg/global"
"github.com/replicate/cog/pkg/model"
)
func newDebugCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "debug",
Hidden: true,
RunE: cmdDockerfile,
}
debug := &cobra.Command{
Use: "debug",
Short: "Generate a Dockerfile from " + global.ConfigFilename,
Hidden: true,
}
cmd.Flags().StringP("arch", "a", "cpu", "Architecture (cpu/gpu)")
cmd.AddCommand(debug)
return cmd
}
func cmdDockerfile(cmd *cobra.Command, args []string) error {
projectDir, err := os.Getwd()
if err != nil {
return err
}
configPath := path.Join(projectDir, global.ConfigFilename)
exists, err := files.FileExists(configPath)
if err != nil {
return err
}
if !exists {
return fmt.Errorf("%s does not exist in %s. Are you in the right directory?", global.ConfigFilename, projectDir)
}
contents, err := ioutil.ReadFile(configPath)
if err != nil {
return err
}
config, err := model.ConfigFromYAML(contents)
if err != nil {
return err
}
if err := config.ValidateAndCompleteConfig(); err != nil {
return err
}
arch, err := cmd.Flags().GetString("arch")
if err != nil {
return err
}
generator := &docker.DockerfileGenerator{Config: config, Arch: arch}
out, err := generator.Generate()
if err != nil {
return err
}
fmt.Print(out)
return nil
}