MCPcopy
hub / github.com/loft-sh/devpod / Run

Method Run

cmd/agent/workspace/build.go:41–102  ·  view source on GitHub ↗

Run runs the command logic

(ctx context.Context)

Source from the content-addressed store, hash-verified

39
40// Run runs the command logic
41func (cmd *BuildCmd) Run(ctx context.Context) error {
42 // write workspace info
43 shouldExit, workspaceInfo, err := agent.WriteWorkspaceInfoAndDeleteOld(cmd.WorkspaceInfo, func(workspaceInfo *provider2.AgentWorkspaceInfo, log log.Logger) error {
44 return deleteWorkspace(ctx, workspaceInfo, log)
45 }, log.Default.ErrorStreamOnly())
46 if err != nil {
47 return err
48 } else if shouldExit {
49 return nil
50 }
51
52 // make sure daemon does shut us down while we are doing things
53 agent.CreateWorkspaceBusyFile(workspaceInfo.Origin)
54 defer agent.DeleteWorkspaceBusyFile(workspaceInfo.Origin)
55
56 // initialize the workspace
57 cancelCtx, cancel := context.WithCancel(ctx)
58 defer cancel()
59 _, logger, credentialsDir, err := initWorkspace(cancelCtx, cancel, workspaceInfo, cmd.Debug, false)
60 if err != nil {
61 return err
62 } else if credentialsDir != "" {
63 defer func() {
64 _ = os.RemoveAll(credentialsDir)
65 }()
66 }
67
68 runner, err := CreateRunner(workspaceInfo, nil, logger)
69 if err != nil {
70 return err
71 }
72
73 // if there is no platform specified, we use empty to let
74 // the builder find out itself.
75 platforms := workspaceInfo.CLIOptions.Platform
76 if len(platforms) == 0 {
77 platforms = []string{""}
78 }
79
80 // build and push images
81 for _, platform := range platforms {
82 // build the image
83 imageName, err := runner.Build(ctx, provider2.BuildOptions{
84 CLIOptions: workspaceInfo.CLIOptions,
85 RegistryCache: workspaceInfo.RegistryCache,
86 Platform: platform,
87 ExportCache: true,
88 })
89 if err != nil {
90 logger.Errorf("Error building image: %v", err)
91 return errors.Wrap(err, "build")
92 }
93
94 if workspaceInfo.CLIOptions.SkipPush {
95 logger.Donef("Successfully build image %s", imageName)
96 } else {
97 logger.Donef("Successfully build and pushed image %s", imageName)
98 }

Callers 1

NewBuildCmdFunction · 0.95

Calls 10

CreateWorkspaceBusyFileFunction · 0.92
DeleteWorkspaceBusyFileFunction · 0.92
deleteWorkspaceFunction · 0.85
initWorkspaceFunction · 0.85
CreateRunnerFunction · 0.85
BuildMethod · 0.65
ErrorStreamOnlyMethod · 0.45
ErrorfMethod · 0.45
DonefMethod · 0.45

Tested by

no test coverage detected