Skip to content

Commit

Permalink
Merge pull request #822 from FabianKramm/driver-refactor
Browse files Browse the repository at this point in the history
fix: small fixes in dockerless & init content folder
  • Loading branch information
FabianKramm authored Nov 30, 2023
2 parents 589504f + e1fa6a3 commit 0059954
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
4 changes: 1 addition & 3 deletions cmd/agent/container/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,13 @@ func dockerlessBuild(

// write output to log
writer := log.Writer(logrus.InfoLevel, false)
errwriter := log.Writer(logrus.ErrorLevel, false)
defer writer.Close()
defer errwriter.Close()

// start building
log.Infof("Start dockerless building %s %s", "/.dockerless/dockerless", strings.Join(args, " "))
cmd := exec.CommandContext(ctx, "/.dockerless/dockerless", args...)
cmd.Stdout = writer
cmd.Stderr = errwriter
cmd.Stderr = writer
cmd.Env = os.Environ()
err = cmd.Run()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/container_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (cmd *ContainerTunnelCmd) Run(ctx context.Context, log log.Logger) error {
}

// make sure content folder exists
err = workspace.InitContentFolder(workspaceInfo, log)
_, err = workspace.InitContentFolder(workspaceInfo, log)
if err != nil {
return err
}
Expand Down
23 changes: 11 additions & 12 deletions cmd/agent/workspace/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,11 @@ func (cmd *UpCmd) up(ctx context.Context, workspaceInfo *provider2.AgentWorkspac

func prepareWorkspace(ctx context.Context, workspaceInfo *provider2.AgentWorkspaceInfo, client tunnel.TunnelClient, helper string, log log.Logger) error {
// make sure content folder exists
err := InitContentFolder(workspaceInfo, log)
exists, err := InitContentFolder(workspaceInfo, log)
if err != nil {
return err
}

// check if we should init
if workspaceInfo.LastDevContainerConfig != nil {
log.Debugf("Workspace was already executed, skip downloading")
} else if exists {
log.Debugf("Workspace exists, skip downloading")
return nil
}

Expand All @@ -209,33 +206,33 @@ func prepareWorkspace(ctx context.Context, workspaceInfo *provider2.AgentWorkspa
return fmt.Errorf("either workspace repository, image or local-folder is required")
}

func InitContentFolder(workspaceInfo *provider2.AgentWorkspaceInfo, log log.Logger) error {
func InitContentFolder(workspaceInfo *provider2.AgentWorkspaceInfo, log log.Logger) (bool, error) {
// check if workspace content folder exists
_, err := os.Stat(workspaceInfo.ContentFolder)
if err == nil {
log.Debugf("Workspace Folder already exists %s", workspaceInfo.ContentFolder)
return nil
return true, nil
}

// make content dir
log.Debugf("Create content folder %s", workspaceInfo.ContentFolder)
err = os.MkdirAll(workspaceInfo.ContentFolder, 0777)
if err != nil {
return errors.Wrap(err, "make workspace folder")
return false, errors.Wrap(err, "make workspace folder")
}

// download provider
binariesDir, err := agent.GetAgentBinariesDir(workspaceInfo.Agent.DataPath, workspaceInfo.Workspace.Context, workspaceInfo.Workspace.ID)
if err != nil {
_ = os.RemoveAll(workspaceInfo.ContentFolder)
return fmt.Errorf("error getting workspace %s binaries dir: %w", workspaceInfo.Workspace.ID, err)
return false, fmt.Errorf("error getting workspace %s binaries dir: %w", workspaceInfo.Workspace.ID, err)
}

// download binaries
_, err = binaries.DownloadBinaries(workspaceInfo.Agent.Binaries, binariesDir, log)
if err != nil {
_ = os.RemoveAll(workspaceInfo.ContentFolder)
return fmt.Errorf("error downloading workspace %s binaries: %w", workspaceInfo.Workspace.ID, err)
return false, fmt.Errorf("error downloading workspace %s binaries: %w", workspaceInfo.Workspace.ID, err)
}

// if workspace was already executed, we skip this part
Expand All @@ -245,9 +242,11 @@ func InitContentFolder(workspaceInfo *provider2.AgentWorkspaceInfo, log log.Logg
if err != nil {
log.Errorf("Ensure devcontainer.json: %v", err)
}

return true, nil
}

return nil
return false, nil
}

func ensureLastDevContainerJson(workspaceInfo *provider2.AgentWorkspaceInfo) error {
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/up/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ var _ = DevPodDescribe("devpod up test suite", func() {
framework.ExpectNoError(err)
})

ginkgo.FIt("run devpod in Kubernetes", func() {
ginkgo.It("run devpod in Kubernetes", func() {
ctx := context.Background()
f := framework.NewDefaultFramework(initialDir + "/bin")
tempDir, err := framework.CopyToTempDir("tests/up/testdata/kubernetes")
Expand Down
7 changes: 3 additions & 4 deletions pkg/devcontainer/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func SetupContainer(setupInfo *config.Result, extraWorkspaceEnv []string, chownW
}

// chown agent sock file
err = ChownAgentSock(setupInfo, log)
err = ChownAgentSock(setupInfo)
if err != nil {
return errors.Wrap(err, "chown ssh agent sock file")
}
Expand Down Expand Up @@ -213,13 +213,12 @@ func PatchEtcEnvironment(mergedConfig *config.MergedDevContainerConfig, log log.
return nil
}

func ChownAgentSock(setupInfo *config.Result, log log.Logger) error {
func ChownAgentSock(setupInfo *config.Result) error {
user := config.GetRemoteUser(setupInfo)

agentSockFile := os.Getenv("SSH_AUTH_SOCK")
if agentSockFile != "" {
err := copy2.ChownR(filepath.Dir(agentSockFile), user)
if err != nil {
if err != nil && !os.IsNotExist(err) {
return err
}
}
Expand Down

0 comments on commit 0059954

Please sign in to comment.