Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cmd/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/skevetter/devpod/cmd/agent/container"
"github.com/skevetter/devpod/cmd/agent/workspace"
"github.com/skevetter/devpod/cmd/flags"
"github.com/skevetter/devpod/pkg/client/clientimplementation"
"github.com/skevetter/devpod/pkg/config"
"github.com/skevetter/devpod/pkg/envfile"
"github.com/skevetter/log"
Expand Down Expand Up @@ -63,12 +62,12 @@ func AgentPersistentPreRunE(
log.Default.SetLevel(logrus.FatalLevel)
} else if globalFlags.Debug {
log.Default.SetLevel(logrus.DebugLevel)
} else if os.Getenv(clientimplementation.DevPodDebug) == "true" {
} else if os.Getenv(config.EnvDebug) == config.BoolTrue {
log.Default.SetLevel(logrus.DebugLevel)
}

if globalFlags.DevPodHome != "" {
_ = os.Setenv(config.DEVPOD_HOME, globalFlags.DevPodHome)
_ = os.Setenv(config.EnvHome, globalFlags.DevPodHome)
}

// apply environment
Expand Down
8 changes: 4 additions & 4 deletions cmd/agent/container/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

"github.com/sirupsen/logrus"
"github.com/skevetter/devpod/pkg/agent"
config2 "github.com/skevetter/devpod/pkg/config"
agentd "github.com/skevetter/devpod/pkg/daemon/agent"
"github.com/skevetter/devpod/pkg/devcontainer/config"
"github.com/skevetter/devpod/pkg/platform/client"
"github.com/skevetter/devpod/pkg/ts"
"github.com/skevetter/log"
Expand All @@ -25,8 +25,8 @@ import (
)

const (
RootDir = "/var/devpod"
DaemonConfigPath = "/var/run/secrets/devpod/daemon_config"
RootDir = agent.ContainerDataDir
DaemonConfigPath = "/var/run/secrets/" + config2.BinaryName + "/daemon_config"
)

type DaemonCmd struct {
Expand Down Expand Up @@ -142,7 +142,7 @@ func (cmd *DaemonCmd) loadConfig() error {
if err != nil {
if errors.Is(err, os.ErrNotExist) {
// check environment variable
encodedCfg = os.Getenv(config.WorkspaceDaemonConfigExtraEnvVar)
encodedCfg = os.Getenv(config2.EnvWorkspaceDaemonConfig)
} else {
return fmt.Errorf("get daemon config file %s: %w", DaemonConfigPath, err)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/agent/container/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,10 @@ func (cmd *SetupContainerCmd) startContainerDaemon(
return nil
}

return command.StartBackgroundOnce("devpod.daemon", func() (*exec.Cmd, error) {
return command.StartBackgroundOnce(config2.BinaryName+".daemon", func() (*exec.Cmd, error) {
logger.Debugf(
"start devpod container daemon with inactivity timeout %s",
"start %s container daemon with inactivity timeout %s",
config2.BinaryName,
workspaceInfo.ContainerTimeout,
)
binaryPath, err := os.Executable()
Expand Down Expand Up @@ -630,7 +631,7 @@ func configureSystemGitCredentials(
}

gitCredentials := fmt.Sprintf("!'%s' agent git-credentials --port %d", binaryPath, serverPort)
_ = os.Setenv("DEVPOD_GIT_HELPER_PORT", strconv.Itoa(serverPort))
_ = os.Setenv(config2.EnvGitHelperPort, strconv.Itoa(serverPort))

err = git.CommandContext(ctx, git.GetDefaultExtraEnv(false), "config", "--system", "--add",
"credential.helper", gitCredentials).
Expand Down
6 changes: 4 additions & 2 deletions cmd/agent/container/ssh_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (

"github.com/sirupsen/logrus"
"github.com/skevetter/devpod/cmd/flags"
"github.com/skevetter/devpod/pkg/agent"
"github.com/skevetter/devpod/pkg/config"
helperssh "github.com/skevetter/devpod/pkg/ssh/server"
"github.com/skevetter/devpod/pkg/ssh/server/port"
"github.com/skevetter/log"
"github.com/spf13/cobra"
)

const BaseLogDir = "/var/devpod"
var BaseLogDir = agent.ContainerDataDir

// SSHServerCmd holds the ssh server cmd flags.
type SSHServerCmd struct {
Expand Down Expand Up @@ -74,7 +76,7 @@ func getFileLogger(remoteUser string, debug bool) log.Logger {
}
fallback := log.NewDiscardLogger(logLevel)

targetFolder := filepath.Join(os.TempDir(), ".devpod")
targetFolder := filepath.Join(os.TempDir(), config.ConfigDirName)
if remoteUser != "" {
targetFolder = filepath.Join(BaseLogDir, remoteUser)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/agent/container_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/skevetter/devpod/cmd/agent/workspace"
"github.com/skevetter/devpod/cmd/flags"
"github.com/skevetter/devpod/pkg/agent"
pkgconfig "github.com/skevetter/devpod/pkg/config"
"github.com/skevetter/devpod/pkg/devcontainer"
"github.com/skevetter/devpod/pkg/devcontainer/config"
"github.com/skevetter/devpod/pkg/devcontainer/setup"
"github.com/skevetter/devpod/pkg/encoding"
provider2 "github.com/skevetter/devpod/pkg/provider"
"github.com/skevetter/log"
Expand Down Expand Up @@ -127,7 +127,7 @@ func startDevContainer(
} else if encoding.IsLegacyUID(workspaceConfig.Workspace.UID) {
// make sure workspace result is in devcontainer
buf := &bytes.Buffer{}
err = runner.Command(ctx, "root", "cat "+setup.ResultLocation, nil, buf, buf)
err = runner.Command(ctx, "root", "cat "+pkgconfig.DevContainerResultPath, nil, buf, buf)
if err != nil {
// start container
_, err = StartContainer(ctx, runner, log, workspaceConfig)
Expand Down
11 changes: 6 additions & 5 deletions cmd/agent/workspace/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/skevetter/devpod/pkg/agent/tunnelserver"
"github.com/skevetter/devpod/pkg/client/clientimplementation"
"github.com/skevetter/devpod/pkg/command"
"github.com/skevetter/devpod/pkg/config"
"github.com/skevetter/devpod/pkg/credentials"
agentdaemon "github.com/skevetter/devpod/pkg/daemon/agent"
"github.com/skevetter/devpod/pkg/devcontainer"
Expand Down Expand Up @@ -645,8 +646,8 @@ type credentialsConfig struct {
}

func configureCredentials(cfg credentialsConfig) (string, string, error) {
if cfg.workspaceInfo.Agent.InjectDockerCredentials != "true" &&
cfg.workspaceInfo.Agent.InjectGitCredentials != "true" {
if cfg.workspaceInfo.Agent.InjectDockerCredentials != config.BoolTrue &&
cfg.workspaceInfo.Agent.InjectGitCredentials != config.BoolTrue {
return "", "", nil
}

Expand All @@ -665,7 +666,7 @@ func configureCredentials(cfg credentialsConfig) (string, string, error) {
}

dockerCredentials := ""
if cfg.workspaceInfo.Agent.InjectDockerCredentials == "true" {
if cfg.workspaceInfo.Agent.InjectDockerCredentials == config.BoolTrue {
dockerCredentials, err = dockercredentials.ConfigureCredentialsMachine(
cfg.workspaceInfo.Origin,
serverPort,
Expand All @@ -677,13 +678,13 @@ func configureCredentials(cfg credentialsConfig) (string, string, error) {
}

gitCredentials := ""
if cfg.workspaceInfo.Agent.InjectGitCredentials == "true" {
if cfg.workspaceInfo.Agent.InjectGitCredentials == config.BoolTrue {
gitCredentials = fmt.Sprintf(
"!'%s' agent git-credentials --port %d",
binaryPath,
serverPort,
)
_ = os.Setenv("DEVPOD_GIT_HELPER_PORT", strconv.Itoa(serverPort))
_ = os.Setenv(config.EnvGitHelperPort, strconv.Itoa(serverPort))
}

return dockerCredentials, gitCredentials, nil
Expand Down
6 changes: 4 additions & 2 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ func NewBuildCmd(flags *flags.GlobalFlags) *cobra.Command {
}
}

if devPodConfig.ContextOption(config.ContextOptionSSHStrictHostKeyChecking) == "true" {
if devPodConfig.ContextOption(
config.ContextOptionSSHStrictHostKeyChecking,
) == config.BoolTrue {
cmd.StrictHostKeyChecking = true
}

// create a temporary workspace
exists := workspace2.Exists(ctx, devPodConfig, args, "", cmd.Owner, log.Default)
sshConfigFile, err := os.CreateTemp("", "devpodssh.config")
sshConfigFile, err := os.CreateTemp("", config.BinaryName+"ssh.config")
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (cmd *DeleteCmd) Run(cobraCmd *cobra.Command, args []string) error {

func (cmd *DeleteCmd) loadConfig() (*config.Config, error) {
_, err := clientimplementation.DecodeOptionsFromEnv(
clientimplementation.DevPodFlagsDelete,
config.EnvFlagsDelete,
&cmd.DeleteOptions,
)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/flags/flags.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package flags

import (
"github.com/skevetter/devpod/pkg/config"
"github.com/skevetter/devpod/pkg/platform"
flag "github.com/spf13/pflag"
)
Expand All @@ -24,7 +25,7 @@ func SetGlobalFlags(flags *flag.FlagSet) *GlobalFlags {

flags.StringVar(
&globalFlags.DevPodHome,
"devpod-home",
config.BinaryName+"-home",
"",
"If defined will override the default devpod home",
)
Expand Down
8 changes: 5 additions & 3 deletions cmd/helper/get_workspace_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (cmd *GetWorkspaceConfigCommand) Run(
level = logrus.DebugLevel
}
var logger log.Logger = log.NewStdoutLogger(os.Stdin, os.Stdout, os.Stderr, level)
if os.Getenv("DEVPOD_UI") == "true" {
if os.Getenv(config.EnvUI) == config.BoolTrue {
logger = log.Discard
}
logger.Debugf("Resolving devcontainer config for source: %s", rawSource)
Expand All @@ -85,7 +85,7 @@ func (cmd *GetWorkspaceConfigCommand) Run(
done := make(chan *devcontainer.GetWorkspaceConfigResult, 1)
errChan := make(chan error, 1)

tmpDir, err := os.MkdirTemp("", "devpod")
tmpDir, err := os.MkdirTemp("", config.BinaryName)
if err != nil {
return err
}
Expand All @@ -98,7 +98,9 @@ func (cmd *GetWorkspaceConfigCommand) Run(
rawSource,
tmpDir,
cmd.maxDepth,
devPodConfig.ContextOption(config.ContextOptionSSHStrictHostKeyChecking) == "true",
devPodConfig.ContextOption(
config.ContextOptionSSHStrictHostKeyChecking,
) == config.BoolTrue,
logger,
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/ide/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func setOptions(
userOptions = options2.InheritOptionsFromEnvironment(
userOptions,
ideOptions,
"DEVPOD_IDE_"+ide+"_",
config.EnvIDEPrefix+ide+"_",
)

optionValues, err := ideparse.ParseOptions(userOptions, ideOptions)
Expand Down
2 changes: 1 addition & 1 deletion cmd/pro/daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (cmd *StartCmd) Run(
devPodConfig *config.Config,
provider *providerpkg.ProviderConfig,
) error {
isDesktopControlled := os.Getenv("DEVPOD_UI") == "true"
isDesktopControlled := os.Getenv(config.EnvUI) == config.BoolTrue
dir, err := ensureDaemonDir(devPodConfig.DefaultContext, provider.Name)
if err != nil {
return err
Expand Down
11 changes: 5 additions & 6 deletions cmd/pro/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

const (
PROVIDER_BINARY = "PRO_PROVIDER"
providerRepo = "skevetter/devpod"
)

// LoginCmd holds the login cmd flags.
Expand Down Expand Up @@ -126,7 +125,7 @@ func (cmd *LoginCmd) Run(ctx context.Context, fullURL string, log log.Logger) er
} else {
// find a provider name
if cmd.Provider == "" {
cmd.Provider = "devpod-pro"
cmd.Provider = config.ProReleaseName
}
cmd.Provider = provider.ToProInstanceID(cmd.Provider)

Expand All @@ -139,7 +138,7 @@ func (cmd *LoginCmd) Run(ctx context.Context, fullURL string, log log.Logger) er
// provider already exists?
if providers[cmd.Provider] != nil {
// alternative name
cmd.Provider = provider.ToProInstanceID("devpod-" + host)
cmd.Provider = provider.ToProInstanceID(config.BinaryName + "-" + host)
if providers[cmd.Provider] != nil {
return fmt.Errorf(
"provider %s already exists, please choose a different name via --provider",
Expand Down Expand Up @@ -257,7 +256,7 @@ func (cmd *LoginCmd) addLoftProvider(
log.Infof("Add DevPod Pro provider...")

// is development?
if cmd.ProviderSource == providerRepo+"@v0.0.0" {
if cmd.ProviderSource == config.RepoSlug+"@v0.0.0" {
log.Debugf("Add development provider")
_, err = workspace.AddProviderRaw(workspace.ProviderParams{
DevPodConfig: devPodConfig,
Expand All @@ -284,15 +283,15 @@ func (cmd *LoginCmd) resolveProviderSource(url string) error {
return nil
}
if cmd.Version != "" {
cmd.ProviderSource = providerRepo + "@" + cmd.Version
cmd.ProviderSource = config.RepoSlug + "@" + cmd.Version
return nil
}

version, err := platform.GetDevPodVersion(url)
if err != nil {
return fmt.Errorf("get version: %w", err)
}
cmd.ProviderSource = providerRepo + "@" + version
cmd.ProviderSource = config.RepoSlug + "@" + version

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/pro/pro.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewProCmd(flags *flags.GlobalFlags, streamLogger *log.StreamLogger) *cobra.
streamLogger.SetLevel(logrus.DebugLevel)
}

if os.Getenv("DEVPOD_DEBUG") == "true" {
if os.Getenv(config.EnvDebug) == config.BoolTrue {
log.Default.SetLevel(logrus.DebugLevel)
}
if flags.LogOutput == "json" {
Expand Down
9 changes: 5 additions & 4 deletions cmd/pro/provider/create/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

managementv1 "github.com/loft-sh/api/v4/pkg/apis/management/v1"
"github.com/skevetter/devpod/cmd/pro/flags"
"github.com/skevetter/devpod/pkg/config"
"github.com/skevetter/devpod/pkg/platform"
"github.com/skevetter/devpod/pkg/platform/client"
"github.com/skevetter/devpod/pkg/platform/form"
Expand Down Expand Up @@ -81,10 +82,10 @@ func (cmd *WorkspaceCmd) Run(
}

// Info through env, right now only used by CLI
workspaceID := os.Getenv(provider.WORKSPACE_ID)
workspaceUID := os.Getenv(provider.WORKSPACE_UID)
workspaceFolder := os.Getenv(provider.WORKSPACE_FOLDER)
workspaceContext := os.Getenv(provider.WORKSPACE_CONTEXT)
workspaceID := os.Getenv(config.EnvProviderWorkspaceID)
workspaceUID := os.Getenv(config.EnvProviderWorkspaceUID)
workspaceFolder := os.Getenv(config.EnvProviderWorkspaceFolder)
workspaceContext := os.Getenv(config.EnvProviderWorkspaceContext)
workspacePicture := os.Getenv(platform.WorkspacePictureEnv)
workspaceSource := os.Getenv(platform.WorkspaceSourceEnv)
if workspaceUID == "" || workspaceID == "" || workspaceFolder == "" {
Expand Down
6 changes: 3 additions & 3 deletions cmd/pro/provider/get/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ func (cmd *VersionCmd) Run(
return err
}

providerContext := os.Getenv(provider.PROVIDER_CONTEXT)
providerContext := os.Getenv(config.EnvProviderContext)
if providerContext == "" {
providerContext = config.DefaultContext
}
providerID := os.Getenv(provider.PROVIDER_ID)
providerID := os.Getenv(config.EnvProviderID)
if providerID == "" {
return fmt.Errorf("provider ID %s not defined", providerID)
return fmt.Errorf("provider ID env var %s not defined", config.EnvProviderID)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

// get our own version
Expand Down
4 changes: 2 additions & 2 deletions cmd/pro/provider/list/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (

managementv1 "github.com/loft-sh/api/v4/pkg/apis/management/v1"
"github.com/skevetter/devpod/cmd/pro/flags"
"github.com/skevetter/devpod/pkg/config"
"github.com/skevetter/devpod/pkg/platform"
"github.com/skevetter/devpod/pkg/platform/client"
"github.com/skevetter/devpod/pkg/platform/labels"
"github.com/skevetter/devpod/pkg/platform/project"
"github.com/skevetter/devpod/pkg/provider"
"github.com/skevetter/log"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -66,7 +66,7 @@ func (cmd *WorkspacesCmd) Run(ctx context.Context) error {
)
}

filterByOwner := os.Getenv(provider.LOFT_FILTER_BY_OWNER) == "true"
filterByOwner := os.Getenv(config.EnvLoftFilterByOwner) == config.BoolTrue
workspaces := []*managementv1.DevPodWorkspaceInstance{}
for _, p := range projectList.Items {
ns := project.ProjectNamespace(p.GetName())
Expand Down
Loading