Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/docs #1275

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion cmd/agent/container/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func fillContainerEnv(setupInfo *config.Result) error {
}

// merge config
newMergedConfig := &config.MergedDevContainerConfig{}
newMergedConfig := &config.MergedConfig{}
err := config.SubstituteContainerEnv(config.ListToObject(os.Environ()), setupInfo.MergedConfig, newMergedConfig)
if err != nil {
return errors.Wrap(err, "substitute container env")
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/workspace/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (cmd *LogsCmd) Run(ctx context.Context) error {
logger := log.Default.ErrorStreamOnly()

// create new runner
runner, err := devcontainer.NewRunner(agent.ContainerDevPodHelperLocation, agent.DefaultAgentDownloadURL(), workspaceInfo, logger)
runner, err := devcontainer.NewRunner(agent.DevPodBinary, agent.DefaultAgentDownloadURL(), workspaceInfo, logger)
if err != nil {
return fmt.Errorf("create runner: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/agent/workspace/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ func (cmd *UpCmd) Run(ctx context.Context) error {
}

// start up
err = cmd.up(ctx, workspaceInfo, tunnelClient, logger)
if err != nil {
if err = cmd.up(ctx, workspaceInfo, tunnelClient, logger); err != nil {
return errors.Wrap(err, "devcontainer up")
}

Expand Down Expand Up @@ -136,9 +135,10 @@ func (cmd *UpCmd) devPodUp(ctx context.Context, workspaceInfo *provider2.AgentWo
}

func CreateRunner(workspaceInfo *provider2.AgentWorkspaceInfo, log log.Logger) (devcontainer.Runner, error) {
return devcontainer.NewRunner(agent.ContainerDevPodHelperLocation, agent.DefaultAgentDownloadURL(), workspaceInfo, log)
return devcontainer.NewRunner(agent.DevPodBinary, agent.DefaultAgentDownloadURL(), workspaceInfo, log)
}

// InitContentFolder creates the working directory for the devpod agent to store binaries / config
func InitContentFolder(workspaceInfo *provider2.AgentWorkspaceInfo, log log.Logger) (bool, error) {
// check if workspace content folder exists
_, err := os.Stat(workspaceInfo.ContentFolder)
Expand Down Expand Up @@ -182,6 +182,7 @@ func InitContentFolder(workspaceInfo *provider2.AgentWorkspaceInfo, log log.Logg
return false, nil
}

// initWorkspace sets up a fresh workspace so it can run the devcontainer via devpod, setting up credentials, container runtime etc.
func initWorkspace(ctx context.Context, cancel context.CancelFunc, workspaceInfo *provider2.AgentWorkspaceInfo, debug, shouldInstallDaemon bool) (tunnel.TunnelClient, log.Logger, string, error) {
// create a grpc client
tunnelClient, err := tunnelserver.NewTunnelClient(os.Stdin, os.Stdout, true, 0)
Expand Down
35 changes: 10 additions & 25 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ type BuildCmd struct {
*flags.GlobalFlags
provider.CLIOptions

ProviderOptions []string
ProviderOptions []string // provider specific options overriding the context

SkipDelete bool
Machine string
SkipDelete bool // the command requires a workspace to run, setting true leaves this workspace running after building
Machine string // optional CLI arg to specify which machine to deploy devcontainer
}

// NewBuildCmd creates a new command
Expand Down Expand Up @@ -64,7 +64,7 @@ func NewBuildCmd(flags *flags.GlobalFlags) *cobra.Command {
// defer removal of temporary ssh config file
defer os.Remove(sshConfigPath)

baseWorkspaceClient, err := workspace2.ResolveWorkspace(
baseWorkspaceClient, err := workspace2.Resolve(
ctx,
devPodConfig,
"",
Expand Down Expand Up @@ -101,7 +101,7 @@ func NewBuildCmd(flags *flags.GlobalFlags) *cobra.Command {
return fmt.Errorf("building is currently not supported for proxy providers")
}

return cmd.Run(ctx, workspaceClient)
return cmd.Build(ctx, workspaceClient, log.Default)
},
}

Expand All @@ -123,32 +123,17 @@ func NewBuildCmd(flags *flags.GlobalFlags) *cobra.Command {
return buildCmd
}

func (cmd *BuildCmd) Run(ctx context.Context, client client.WorkspaceClient) error {
// build workspace
err := cmd.build(ctx, client, log.Default)
if err != nil {
return err
}

return nil
}

func (cmd *BuildCmd) build(ctx context.Context, workspaceClient client.WorkspaceClient, log log.Logger) error {
err := workspaceClient.Lock(ctx)
if err != nil {
// Build uses a workspaceClient to execute a build pipeline remotely in the workspace
func (cmd *BuildCmd) Build(ctx context.Context, workspaceClient client.WorkspaceClient, log log.Logger) (err error) {
if err = workspaceClient.Lock(ctx); err != nil {
return err
}
defer workspaceClient.Unlock()

err = startWait(ctx, workspaceClient, true, log)
if err != nil {
if err = startWait(ctx, workspaceClient, true, log); err != nil {
return err
}

return cmd.buildAgentClient(ctx, workspaceClient, log)
}

func (cmd *BuildCmd) buildAgentClient(ctx context.Context, workspaceClient client.WorkspaceClient, log log.Logger) error {
// compress info
workspaceInfo, wInfo, err := workspaceClient.AgentInfo(cmd.CLIOptions)
if err != nil {
Expand Down Expand Up @@ -187,7 +172,7 @@ func (cmd *BuildCmd) buildAgentClient(ctx context.Context, workspaceClient clien
writer := log.ErrorStreamOnly().Writer(logrus.InfoLevel, false)
defer writer.Close()

errChan <- agent.InjectAgentAndExecute(
errChan <- agent.Inject(
cancelCtx,
func(ctx context.Context, command string, stdin io.Reader, stdout io.Writer, stderr io.Writer) error {
return workspaceClient.Command(ctx, client.CommandOptions{
Expand Down
4 changes: 2 additions & 2 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewDeleteCmd(flags *flags.GlobalFlags) *cobra.Command {
// Run runs the command logic
func (cmd *DeleteCmd) Run(ctx context.Context, devPodConfig *config.Config, args []string) error {
// try to load workspace
client, err := workspace2.GetWorkspace(devPodConfig, args, false, log.Default)
client, err := workspace2.Get(devPodConfig, args, false, log.Default)
if err != nil {
if len(args) == 0 {
return fmt.Errorf("cannot delete workspace because there was an error loading the workspace: %w. Please specify the id of the workspace you want to delete. E.g. 'devpod delete my-workspace --force'", err)
Expand Down Expand Up @@ -141,7 +141,7 @@ func (cmd *DeleteCmd) deleteSingleMachine(ctx context.Context, client client2.Ba
}

// try to find other workspace with same machine
workspaces, err := workspace2.ListWorkspaces(devPodConfig, log.Default)
workspaces, err := workspace2.List(devPodConfig, log.Default)
if err != nil {
return false, errors.Wrap(err, "list workspaces")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewExportCmd(flags *flags.GlobalFlags) *cobra.Command {
func (cmd *ExportCmd) Run(ctx context.Context, devPodConfig *config.Config, args []string) error {
// try to load workspace
logger := log.Default.ErrorStreamOnly()
client, err := workspace2.GetWorkspace(devPodConfig, args, false, logger)
client, err := workspace2.Get(devPodConfig, args, false, logger)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/helper/get_workspace_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ func (cmd *GetWorkspaceNameCommand) Run(ctx context.Context, args []string) erro
return fmt.Errorf("workspace is missing")
}

fmt.Print(workspace.GetWorkspaceName(args))
fmt.Print(workspace.GetName(args))
return nil
}
2 changes: 1 addition & 1 deletion cmd/helper/sh.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ func (cmd *ShellCommand) Run(ctx context.Context, args []string) error {
cmd.Command = string(content)
}

return shell.ExecuteCommandWithShell(ctx, cmd.Command, os.Stdin, os.Stdout, os.Stderr, os.Environ())
return shell.Execute(ctx, cmd.Command, os.Stdin, os.Stdout, os.Stderr, os.Environ())
}
2 changes: 1 addition & 1 deletion cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (cmd *ImportCmd) importProvider(devPodConfig *config.Config, exportConfig *
}

func (cmd *ImportCmd) checkForConflictingIDs(exportConfig *provider.ExportConfig, devPodConfig *config.Config, log log.Logger) error {
workspaces, err := workspace.ListWorkspaces(devPodConfig, log)
workspaces, err := workspace.List(devPodConfig, log)
if err != nil {
return fmt.Errorf("error listing workspaces: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (cmd *ListCmd) Run(ctx context.Context) error {
return err
}

workspaces, err := workspace.ListWorkspaces(devPodConfig, log.Default)
workspaces, err := workspace.List(devPodConfig, log.Default)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (cmd *LogsCmd) Run(ctx context.Context, args []string) error {
return err
}

baseClient, err := workspace.GetWorkspace(devPodConfig, args, false, log.Default)
baseClient, err := workspace.Get(devPodConfig, args, false, log.Default)
if err != nil {
return err
}
Expand Down Expand Up @@ -82,7 +82,7 @@ func (cmd *LogsCmd) Run(ctx context.Context, args []string) error {
stderr := log.ErrorStreamOnly().Writer(logrus.DebugLevel, false)
defer stderr.Close()

errChan <- agent.InjectAgentAndExecute(
errChan <- agent.Inject(
ctx,
func(ctx context.Context, command string, stdin io.Reader, stdout io.Writer, stderr io.Writer) error {
return client.Command(ctx, clientpkg.CommandOptions{
Expand Down
2 changes: 1 addition & 1 deletion cmd/logs_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (cmd *LogsDaemonCmd) Run(ctx context.Context, args []string) error {
return err
}

baseClient, err := workspace.GetWorkspace(devPodConfig, args, false, log.Default)
baseClient, err := workspace.Get(devPodConfig, args, false, log.Default)
if err != nil {
return err
} else if baseClient.WorkspaceConfig().Machine.ID == "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/machine/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (cmd *DeleteCmd) Run(ctx context.Context, args []string) error {
}

// check if there are workspaces that still use this machine
workspaces, err := workspace.ListWorkspaces(devPodConfig, log.Default)
workspaces, err := workspace.List(devPodConfig, log.Default)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/machine/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (cmd *SSHCmd) Run(ctx context.Context, args []string) error {
if cmd.Debug {
command += " --debug"
}
return devagent.InjectAgentAndExecute(ctx, func(ctx context.Context, command string, stdin io.Reader, stdout io.Writer, stderr io.Writer) error {
return devagent.Inject(ctx, func(ctx context.Context, command string, stdin io.Reader, stdout io.Writer, stderr io.Writer) error {
return machineClient.Command(ctx, client.CommandOptions{
Command: command,
Stdin: stdin,
Expand Down
2 changes: 1 addition & 1 deletion cmd/provider/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (cmd *DeleteCmd) Run(ctx context.Context, args []string) error {

func DeleteProvider(devPodConfig *config.Config, provider string, ignoreNotFound bool) error {
// check if there are workspaces that still use this machine
workspaces, err := workspace.ListWorkspaces(devPodConfig, log.Default)
workspaces, err := workspace.List(devPodConfig, log.Default)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func NewSSHCmd(flags *flags.GlobalFlags) *cobra.Command {
return err
}

client, err := workspace2.GetWorkspace(devPodConfig, args, true, log.Default.ErrorStreamOnly())
client, err := workspace2.Get(devPodConfig, args, true, log.Default.ErrorStreamOnly())
if err != nil {
return err
}
Expand Down Expand Up @@ -385,7 +385,7 @@ func (cmd *SSHCmd) startTunnel(ctx context.Context, devPodConfig *config.Config,
}

log.Debugf("Run outer container tunnel")
command := fmt.Sprintf("'%s' helper ssh-server --track-activity --stdio --workdir '%s'", agent.ContainerDevPodHelperLocation, workdir)
command := fmt.Sprintf("'%s' helper ssh-server --track-activity --stdio --workdir '%s'", agent.DevPodBinary, workdir)
if cmd.Debug {
command += " --debug"
}
Expand Down Expand Up @@ -424,7 +424,7 @@ func (cmd *SSHCmd) startServices(
log log.Logger,
) {
if cmd.User != "" {
err := tunnel.RunInContainer(
err := tunnel.StartCredentialsServer(
ctx,
devPodConfig,
containerClient,
Expand Down Expand Up @@ -474,7 +474,7 @@ func (cmd *SSHCmd) startProxyServices(
writer := log.ErrorStreamOnly().Writer(logrus.DebugLevel, false)
defer writer.Close()

command := fmt.Sprintf("'%s' agent container credentials-server --user '%s'", agent.ContainerDevPodHelperLocation, cmd.User)
command := fmt.Sprintf("'%s' agent container credentials-server --user '%s'", agent.DevPodBinary, cmd.User)
if gitCredentials {
command += " --configure-git-helper"
}
Expand Down Expand Up @@ -572,7 +572,7 @@ func (cmd *SSHCmd) setupGPGAgent(
// Now we forward the agent socket to the remote, and setup remote gpg to use it
// fix eventual permissions and so on
forwardAgent := []string{
agent.ContainerDevPodHelperLocation,
agent.DevPodBinary,
}

if log.GetLevel() == logrus.DebugLevel {
Expand Down
2 changes: 1 addition & 1 deletion cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewStatusCmd(flags *flags.GlobalFlags) *cobra.Command {
}

logger := log.Default.ErrorStreamOnly()
client, err := workspace2.GetWorkspace(devPodConfig, args, false, logger)
client, err := workspace2.Get(devPodConfig, args, false, logger)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewStopCmd(flags *flags.GlobalFlags) *cobra.Command {
return err
}

client, err := workspace2.GetWorkspace(devPodConfig, args, false, log.Default)
client, err := workspace2.Get(devPodConfig, args, false, log.Default)
if err != nil {
return err
}
Expand Down Expand Up @@ -88,7 +88,7 @@ func (cmd *StopCmd) stopSingleMachine(ctx context.Context, client client2.BaseWo
}

// try to find other workspace with same machine
workspaces, err := workspace2.ListWorkspaces(devPodConfig, log.Default)
workspaces, err := workspace2.List(devPodConfig, log.Default)
if err != nil {
return false, errors.Wrap(err, "list workspaces")
}
Expand Down
Loading