-
Notifications
You must be signed in to change notification settings - Fork 318
/
setup.go
72 lines (64 loc) · 2.18 KB
/
setup.go
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
package devcontainer
import (
"context"
"encoding/json"
"fmt"
"io"
"runtime"
"github.com/loft-sh/devpod/pkg/agent"
"github.com/loft-sh/devpod/pkg/compress"
"github.com/loft-sh/devpod/pkg/devcontainer/config"
provider2 "github.com/loft-sh/devpod/pkg/provider"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
func (r *Runner) setupContainer(containerDetails *config.ContainerDetails, mergedConfig *config.MergedDevContainerConfig) error {
// inject agent
err := agent.InjectAgent(context.TODO(), func(ctx context.Context, command string, stdin io.Reader, stdout io.Writer, stderr io.Writer) error {
return r.Driver.CommandDevContainer(ctx, containerDetails.ID, "root", command, stdin, stdout, stderr)
}, false, agent.ContainerDevPodHelperLocation, agent.DefaultAgentDownloadURL(), false, r.Log)
if err != nil {
return errors.Wrap(err, "inject agent")
}
r.Log.Debugf("Injected into container")
defer r.Log.Debugf("Done setting up container")
// compress info
marshalled, err := json.Marshal(&config.Result{
ContainerDetails: containerDetails,
MergedConfig: mergedConfig,
SubstitutionContext: r.SubstitutionContext,
})
if err != nil {
return err
}
compressed, err := compress.Compress(string(marshalled))
if err != nil {
return err
}
// compress workspace info
workspaceConfigRaw, err := json.Marshal(r.WorkspaceConfig)
if err != nil {
return err
}
workspaceConfigCompressed, err := compress.Compress(string(workspaceConfigRaw))
if err != nil {
return err
}
writer := r.Log.Writer(logrus.InfoLevel, false)
defer writer.Close()
// execute docker command
r.Log.Infof("Setup container...")
command := fmt.Sprintf("'%s' agent container setup --setup-info '%s' --workspace-info '%s'", agent.ContainerDevPodHelperLocation, compressed, workspaceConfigCompressed)
if runtime.GOOS == "linux" || r.WorkspaceConfig.Agent.Driver == provider2.KubernetesDriver {
command += " --chown-workspace"
}
if r.Log.GetLevel() == logrus.DebugLevel {
command += " --debug"
}
r.Log.Debugf("Run command: %s", command)
err = r.Driver.CommandDevContainer(context.TODO(), containerDetails.ID, "root", command, nil, writer, writer)
if err != nil {
return err
}
return nil
}