MCPcopy Index your code
hub / github.com/devspace-sh/devspace / AddImage

Method AddImage

pkg/devspace/configure/image.go:29–221  ·  view source on GitHub ↗

AddImage adds an image to the provided config

(imageName, image, projectNamespace, dockerfile string)

Source from the content-addressed store, hash-verified

27
28// AddImage adds an image to the provided config
29func (m *manager) AddImage(imageName, image, projectNamespace, dockerfile string) error {
30 var (
31 useDockerHub = "Use " + dockerHubHostname
32 useGithubRegistry = "Use GitHub image registry"
33 useOtherRegistry = "Use other registry"
34 skipRegistry = "Skip Registry"
35 registryDefaultOption = skipRegistry
36 registryUsernameHint = " => you are logged in as %s"
37 rootLevelDockerfile = "Use this existing Dockerfile: " + dockerfile
38 differentDockerfile = "Use a different Dockerfile (e.g. ./backend/Dockerfile)"
39 subPathDockerfile = "Use an existing Dockerfile within this project"
40 customBuild = "Use alternative build tool (e.g. jib, bazel)"
41 skip = "Skip / I don't know"
42 err error
43 )
44
45 imageConfig := &latest.Image{
46 Image: strings.ToLower(image),
47 Dockerfile: dockerfile,
48 }
49
50 buildMethods := []string{subPathDockerfile}
51
52 stat, err := os.Stat(imageConfig.Dockerfile)
53 if err == nil && !stat.IsDir() {
54 buildMethods = []string{rootLevelDockerfile, differentDockerfile}
55 }
56
57 buildMethod, err := m.log.Question(&survey.QuestionOptions{
58 Question: "How should DevSpace build the container image for this project?",
59 DefaultValue: buildMethods[0],
60 Options: append(buildMethods, customBuild, skip),
61 })
62 if err != nil {
63 return err
64 }
65
66 if buildMethod == customBuild {
67 buildCommand, err := m.log.Question(&survey.QuestionOptions{
68 Question: "Please enter your build command without the image (e.g. `gradle jib --image` => DevSpace will append the image name automatically)",
69 })
70 if err != nil {
71 return err
72 }
73
74 imageConfig.Custom = &latest.CustomConfig{
75 Command: buildCommand + " --tag=$(get_image --only=tag " + imageName + ")",
76 }
77 } else {
78 if buildMethod != skip && buildMethod != rootLevelDockerfile {
79 imageConfig.Dockerfile, err = m.log.Question(&survey.QuestionOptions{
80 Question: "Please enter the path to this Dockerfile: (Enter to skip)",
81 ValidationFunc: func(value string) error {
82 if value == "" {
83 return nil
84 }
85
86 stat, err := os.Stat(value)

Callers

nothing calls this directly

Calls 8

addPullSecretConfigMethod · 0.95
NewDefaultClientFunction · 0.92
QuestionMethod · 0.65
GetAuthConfigMethod · 0.65
EnvironMethod · 0.65
IsDirMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected