Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions cmd/config/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (cmd *ApplyCmd) prepareContainer(
return nil, nil, err
}

result, err := cmd.loadConfig(containerDetails)
result, err := cmd.loadConfig(ctx, containerDetails)
if err != nil {
emitErr(emitJSON, err)
return nil, nil, err
Expand Down Expand Up @@ -171,19 +171,20 @@ func (cmd *ApplyCmd) inspectRunningContainer(
}

func (cmd *ApplyCmd) loadConfig(
ctx context.Context,
containerDetails *devcconfig.ContainerDetails,
) (*devcconfig.Result, error) {
var devContainerConfig *devcconfig.DevContainerConfig
var err error

if cmd.Config != "" {
devContainerConfig, err = devcconfig.ParseDevContainerJSONFile(cmd.Config)
devContainerConfig, err = devcconfig.ParseDevContainerJSONFile(ctx, cmd.Config)
} else {
cwd, cwdErr := os.Getwd()
if cwdErr != nil {
return nil, fmt.Errorf("get working directory: %w", cwdErr)
}
devContainerConfig, err = devcconfig.ParseDevContainerJSON(cwd, "")
devContainerConfig, err = devcconfig.ParseDevContainerJSON(ctx, cwd, "")
}
if err != nil {
return nil, fmt.Errorf("parse devcontainer config: %w", err)
Expand Down
11 changes: 4 additions & 7 deletions cmd/config/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ func (cmd *ReadCmd) resolve(ctx context.Context) (
if len(cmd.IDLabels) > 0 {
return cmd.resolveConfigFromIDLabels(ctx)
}
return cmd.resolveConfig()
return cmd.resolveConfig(ctx)
}

func (cmd *ReadCmd) resolveConfig() (
func (cmd *ReadCmd) resolveConfig(ctx context.Context) (
*devcconfig.DevContainerConfig,
string,
error,
Expand All @@ -191,12 +191,9 @@ func (cmd *ReadCmd) resolveConfig() (

var parsedConfig *devcconfig.DevContainerConfig
if cmd.Config != "" {
parsedConfig, err = devcconfig.ParseDevContainerJSONFile(cmd.Config)
parsedConfig, err = devcconfig.ParseDevContainerJSONFile(ctx, cmd.Config)
} else {
parsedConfig, err = devcconfig.ParseDevContainerJSON(
workspaceFolder,
"",
)
parsedConfig, err = devcconfig.ParseDevContainerJSON(ctx, workspaceFolder, "")
}
if err != nil {
return nil, "", fmt.Errorf("parse devcontainer config: %w", err)
Expand Down
8 changes: 6 additions & 2 deletions cmd/feature/outdated.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ func (cmd *OutdatedCmd) loadConfig() (*devconfig.DevContainerConfig, error) {

var parsedConfig *devconfig.DevContainerConfig
if cmd.Config != "" {
parsedConfig, err = devconfig.ParseDevContainerJSONFile(cmd.Config)
parsedConfig, err = devconfig.ParseDevContainerJSONFile(context.Background(), cmd.Config)
} else {
parsedConfig, err = devconfig.ParseDevContainerJSON(workspaceFolder, "")
parsedConfig, err = devconfig.ParseDevContainerJSON(
context.Background(),
workspaceFolder,
"",
)
}
if err != nil {
return nil, fmt.Errorf("parse devcontainer config: %w", err)
Expand Down
5 changes: 3 additions & 2 deletions cmd/feature/resolvedeps.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package feature

import (
"context"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -122,15 +123,15 @@ func buildResolvedList(sorted []*config.FeatureSet) []resolvedFeature {

func (cmd *ResolveDepsCmd) loadConfig() (*config.DevContainerConfig, error) {
if cmd.Config != "" {
return config.ParseDevContainerJSONFile(cmd.Config)
return config.ParseDevContainerJSONFile(context.Background(), cmd.Config)
}

absPath, err := filepath.Abs(cmd.WorkspaceFolder)
if err != nil {
return nil, err
}

return config.ParseDevContainerJSON(absPath, "")
return config.ParseDevContainerJSON(context.Background(), absPath, "")
}

func (cmd *ResolveDepsCmd) printText(resolved []resolvedFeature) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/feature/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (cmd *UpgradeCmd) applyUpgrades(configPath string, outdated []outdatedEntry
old := entry.repo + ":" + entry.current
updated := entry.repo + ":" + entry.latest
content = strings.ReplaceAll(content, old, updated)
log.Infof("Upgraded %s: %s %s", entry.repo, entry.current, entry.latest)
log.Infof("Upgraded %s: %s to %s", entry.repo, entry.current, entry.latest)
}

//nolint:gosec // G306 -- matching existing file permissions in the codebase
Expand Down
4 changes: 1 addition & 3 deletions cmd/internal/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"github.com/spf13/cobra"
)

var AgentExecutedAnnotation = "devsy.sh/agent-executed"

// NewAgentCmd is the hidden parent for commands that run inside a workspace or
// container, invoked by the daemon over the agent tunnel.
func NewAgentCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
Expand Down Expand Up @@ -48,7 +46,7 @@ func agentPreRunE(globalFlags *flags.GlobalFlags) func(*cobra.Command, []string)
if root.Annotations == nil {
root.Annotations = map[string]string{}
}
root.Annotations[AgentExecutedAnnotation] = "true"
root.Annotations[config.AgentExecutedAnnotation] = "true"

log.Init(log.Config{
Quiet: globalFlags.Quiet,
Expand Down
16 changes: 13 additions & 3 deletions cmd/internal/runusercommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (cmd *RunUserCommandsCmd) runWithContainerID(ctx context.Context) error {
return err
}

result, err := cmd.loadContainerIDConfig(containerDetails)
result, err := cmd.loadContainerIDConfig(ctx, containerDetails)
if err != nil {
return err
}
Expand Down Expand Up @@ -265,14 +265,19 @@ func (cmd *RunUserCommandsCmd) inspectRunningContainer(
}

func (cmd *RunUserCommandsCmd) loadContainerIDConfig(
ctx context.Context,
containerDetails *devcconfig.ContainerDetails,
) (*devcconfig.Result, error) {
configFolder := cmd.WorkspaceFolder
if configFolder == "" {
configFolder = "."
}

devContainerConfig, err := devcconfig.ParseDevContainerJSON(configFolder, cmd.Config)
devContainerConfig, err := devcconfig.ParseDevContainerJSON(
ctx,
configFolder,
cmd.Config,
)
if err != nil {
_ = devcconfig.WriteErrorJSON(os.Stderr, err.Error())
return nil, fmt.Errorf("parse devcontainer config: %w", err)
Expand All @@ -290,7 +295,11 @@ func (cmd *RunUserCommandsCmd) loadContainerIDConfig(
}

if cmd.OverrideConfig != "" {
if err := devcconfig.MergeExtraRemoteEnv(mergedConfig, cmd.OverrideConfig); err != nil {
if err := devcconfig.MergeExtraRemoteEnv(
ctx,
mergedConfig,
cmd.OverrideConfig,
); err != nil {
_ = devcconfig.WriteErrorJSON(os.Stderr, err.Error())
return nil, fmt.Errorf("apply override config: %w", err)
}
Expand Down Expand Up @@ -353,6 +362,7 @@ func (cmd *RunUserCommandsCmd) resolveContainer(

if cmd.OverrideConfig != "" {
if err := devcconfig.MergeExtraRemoteEnv(
ctx,
result.MergedConfig,
cmd.OverrideConfig,
); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions cmd/pro/check_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"

cmdinternal "github.com/devsy-org/devsy/cmd/internal"
"github.com/devsy-org/devsy/cmd/pro/flags"
"github.com/devsy-org/devsy/cmd/pro/proutil"
"github.com/devsy-org/devsy/pkg/config"
Expand Down Expand Up @@ -54,8 +53,7 @@ func NewCheckUpdateCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
if root.Annotations == nil {
root.Annotations = map[string]string{}
}
// Don't print debug message
root.Annotations[cmdinternal.AgentExecutedAnnotation] = "true" //nolint:goconst
root.Annotations[config.AgentExecutedAnnotation] = "true" //nolint:goconst
},
}

Expand Down
4 changes: 1 addition & 3 deletions cmd/pro/daemon/netcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"strconv"

cmdinternal "github.com/devsy-org/devsy/cmd/internal"
"github.com/devsy-org/devsy/cmd/pro/completion"
proflags "github.com/devsy-org/devsy/cmd/pro/flags"
"github.com/devsy-org/devsy/cmd/pro/proutil"
Expand Down Expand Up @@ -53,8 +52,7 @@ func NewNetcheckCmd(flags *proflags.GlobalFlags) *cobra.Command {
if root.Annotations == nil {
root.Annotations = map[string]string{}
}
// Don't print debug message
root.Annotations[cmdinternal.AgentExecutedAnnotation] = "true"
root.Annotations[config.AgentExecutedAnnotation] = "true"
},
}

Expand Down
4 changes: 1 addition & 3 deletions cmd/pro/daemon/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"

cmdinternal "github.com/devsy-org/devsy/cmd/internal"
"github.com/devsy-org/devsy/cmd/pro/completion"
proflags "github.com/devsy-org/devsy/cmd/pro/flags"
"github.com/devsy-org/devsy/cmd/pro/proutil"
Expand Down Expand Up @@ -51,8 +50,7 @@ func NewStatusCmd(flags *proflags.GlobalFlags) *cobra.Command {
if root.Annotations == nil {
root.Annotations = map[string]string{}
}
// Don't print debug message
root.Annotations[cmdinternal.AgentExecutedAnnotation] = "true"
root.Annotations[config.AgentExecutedAnnotation] = "true"
},
}

Expand Down
4 changes: 1 addition & 3 deletions cmd/pro/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"

cmdinternal "github.com/devsy-org/devsy/cmd/internal"
"github.com/devsy-org/devsy/cmd/pro/flags"
"github.com/devsy-org/devsy/cmd/pro/proutil"
"github.com/devsy-org/devsy/pkg/client/clientimplementation"
Expand Down Expand Up @@ -56,8 +55,7 @@ func NewHealthCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
if root.Annotations == nil {
root.Annotations = map[string]string{}
}
// Don't print debug message
root.Annotations[cmdinternal.AgentExecutedAnnotation] = "true" //nolint:goconst
root.Annotations[config.AgentExecutedAnnotation] = "true" //nolint:goconst
},
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/pro/provider/list/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/devsy-org/devsy/pkg/log"
"github.com/devsy-org/devsy/pkg/platform"
"github.com/devsy-org/devsy/pkg/platform/client"
"github.com/devsy-org/devsy/pkg/platform/labels"
"github.com/devsy-org/devsy/pkg/platform/project"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -85,7 +84,7 @@ func (cmd *WorkspacesCmd) Run(ctx context.Context) error {
if instance.GetLabels() == nil {
instance.Labels = map[string]string{}
}
instance.Labels[labels.ProjectLabel] = p.GetName()
instance.Labels[config.K8sProjectLabel] = p.GetName()

workspaces = append(workspaces, instance)
}
Expand Down
6 changes: 1 addition & 5 deletions cmd/pro/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package provider
import (
"os"

cmdinternal "github.com/devsy-org/devsy/cmd/internal"
"github.com/devsy-org/devsy/cmd/pro/flags"
"github.com/devsy-org/devsy/cmd/pro/provider/create"
"github.com/devsy-org/devsy/cmd/pro/provider/get"
Expand Down Expand Up @@ -33,16 +32,13 @@ func NewProProviderCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
globalFlags.Debug = true
}

// Disable debug hints if we execute pro commands from Devsy Desktop
// We're reusing the cmdinternal.AgentExecutedAnnotation for simplicity, could rename in the future
if os.Getenv(config.EnvUI) == config.BoolTrue {
cmd.VisitParents(func(c *cobra.Command) {
// find the root command
if c.Name() == config.BinaryName {
if c.Annotations == nil {
c.Annotations = map[string]string{}
}
c.Annotations[cmdinternal.AgentExecutedAnnotation] = config.BoolTrue
c.Annotations[config.AgentExecutedAnnotation] = config.BoolTrue
}
})
}
Expand Down
17 changes: 9 additions & 8 deletions e2e/tests/up-docker-compose/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/devsy-org/devsy/e2e/framework"
"github.com/devsy-org/devsy/pkg/compose"
pkgconfig "github.com/devsy-org/devsy/pkg/config"
docker "github.com/devsy-org/devsy/pkg/docker"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
Expand Down Expand Up @@ -73,10 +74,10 @@ var _ = ginkgo.Describe(
ids, err = dockerHelper.FindContainer(ctx, []string{
fmt.Sprintf(
"%s=%s",
compose.ProjectLabel,
pkgconfig.ComposeProjectLabel,
composeHelper.GetProjectName(workspace.UID),
),
fmt.Sprintf("%s=%s", compose.ServiceLabel, "app"),
fmt.Sprintf("%s=%s", pkgconfig.ComposeServiceLabel, "app"),
})
if err != nil {
return 0
Expand Down Expand Up @@ -116,10 +117,10 @@ var _ = ginkgo.Describe(
ids2, err := dockerHelper.FindContainer(ctx, []string{
fmt.Sprintf(
"%s=%s",
compose.ProjectLabel,
pkgconfig.ComposeProjectLabel,
composeHelper.GetProjectName(workspace.UID),
),
fmt.Sprintf("%s=%s", compose.ServiceLabel, "app"),
fmt.Sprintf("%s=%s", pkgconfig.ComposeServiceLabel, "app"),
})
framework.ExpectNoError(err)
gomega.Expect(ids2[0]).To(gomega.Equal(ids[0]), "Should use original container")
Expand All @@ -146,10 +147,10 @@ var _ = ginkgo.Describe(
ids, err = dockerHelper.FindContainer(ctx, []string{
fmt.Sprintf(
"%s=%s",
compose.ProjectLabel,
pkgconfig.ComposeProjectLabel,
composeHelper.GetProjectName(workspace.UID),
),
fmt.Sprintf("%s=%s", compose.ServiceLabel, "app"),
fmt.Sprintf("%s=%s", pkgconfig.ComposeServiceLabel, "app"),
})
if err != nil {
return 0
Expand All @@ -168,10 +169,10 @@ var _ = ginkgo.Describe(
ids2, err := dockerHelper.FindContainer(ctx, []string{
fmt.Sprintf(
"%s=%s",
compose.ProjectLabel,
pkgconfig.ComposeProjectLabel,
composeHelper.GetProjectName(workspace.UID),
),
fmt.Sprintf("%s=%s", compose.ServiceLabel, "app"),
fmt.Sprintf("%s=%s", pkgconfig.ComposeServiceLabel, "app"),
})
framework.ExpectNoError(err)
gomega.Expect(ids2[0]).NotTo(gomega.Equal(ids[0]), "Should restart container")
Expand Down
9 changes: 7 additions & 2 deletions e2e/tests/up-docker-compose/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/devsy-org/devsy/e2e/framework"
"github.com/devsy-org/devsy/pkg/compose"
pkgconfig "github.com/devsy-org/devsy/pkg/config"
docker "github.com/devsy-org/devsy/pkg/docker"
provider2 "github.com/devsy-org/devsy/pkg/provider"
"github.com/docker/docker/api/types/container"
Expand Down Expand Up @@ -197,8 +198,12 @@ func findComposeContainer(
workspaceUID, serviceName string,
) ([]string, error) {
return dockerHelper.FindContainer(ctx, []string{
fmt.Sprintf("%s=%s", compose.ProjectLabel, composeHelper.GetProjectName(workspaceUID)),
fmt.Sprintf("%s=%s", compose.ServiceLabel, serviceName),
fmt.Sprintf(
"%s=%s",
pkgconfig.ComposeProjectLabel,
composeHelper.GetProjectName(workspaceUID),
),
fmt.Sprintf("%s=%s", pkgconfig.ComposeServiceLabel, serviceName),
})
}

Expand Down
Loading
Loading