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
48 changes: 47 additions & 1 deletion e2e/tests/proxycommands/proxycommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bytes"
"context"
"fmt"
"github.com/onsi/ginkgo/v2"
"os"
"os/exec"
"time"

"github.com/onsi/ginkgo/v2"

"github.com/loft-sh/devspace/cmd"
"github.com/loft-sh/devspace/cmd/flags"
"github.com/loft-sh/devspace/e2e/framework"
Expand Down Expand Up @@ -95,4 +96,49 @@ var _ = DevSpaceDescribe("proxyCommands", func() {
err = <-done
framework.ExpectNoError(err)
})

ginkgo.It("devspace dev should proxy commands to host machine without /usr/local/bin", func() {
tempDir, err := framework.CopyToTempDir("tests/proxycommands/testdata/proxycommands-no-usr-local")
framework.ExpectNoError(err)
defer framework.CleanupTempDir(initialDir, tempDir)

ns, err := kubeClient.CreateNamespace("no-usr-local")
framework.ExpectNoError(err)
defer framework.ExpectDeleteNamespace(kubeClient, ns)

// create a new dev command and start it
done := make(chan error)
cancelCtx, cancel := context.WithCancel(context.Background())
defer cancel()

go func() {
defer ginkgo.GinkgoRecover()

devCmd := &cmd.RunPipelineCmd{
GlobalFlags: &flags.GlobalFlags{
NoWarn: true,
Namespace: ns,
},
Pipeline: "dev",
Ctx: cancelCtx,
}

done <- devCmd.RunDefault(f)
}()

// Check that the command is proxied to the host.
var stdout, stderr bytes.Buffer
cmd := exec.Command("helm", "version")
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err = cmd.Run()
framework.ExpectNoError(err)

framework.ExpectRemoteFileContents("busybox", ns, "helm-version.out", stdout.String())

cancel()

err = <-done
framework.ExpectNoError(err)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: v2beta1

name: no-usr-local

vars:
IMAGE: busybox

deployments:
test:
helm:
chart:
name: component-chart
repo: https://charts.devspace.sh
values:
containers:
- image: ${IMAGE}
command: ["sleep"]
args: ["infinity"]

dev:
test:
imageSelector: ${IMAGE}
proxyCommands:
- command: helm

pipelines:
dev:
run: |
run_default_pipeline dev
exec_container --image-selector ${IMAGE} -- sh -c 'helm version > helm-version.out'
21 changes: 18 additions & 3 deletions helper/cmd/proxycommands/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package proxycommands
import (
"encoding/base64"
"fmt"
"github.com/mitchellh/go-homedir"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/mitchellh/go-homedir"

"github.com/loft-sh/devspace/helper/util/stderrlog"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -63,10 +64,24 @@ func (cmd *ConfigureCmd) Run(_ *cobra.Command, _ []string) error {

// first configure the commands
for _, c := range cmd.Commands {
filePath := "/usr/local/bin/" + c
fileDir := "/usr/local/bin/"
filePath := fileDir + c

_, err := os.Stat(fileDir)
if err != nil {
if !os.IsNotExist(err) {
return fmt.Errorf("error checking for command path '%s': %v", fileDir, err)
}

err := os.MkdirAll(fileDir, 0755)
if err != nil {
return fmt.Errorf("error creating command path '%s': %v", fileDir, err)
}
}

executeCommand := fmt.Sprintf(`#!/bin/sh
/tmp/devspacehelper proxy-commands run %s "$@"`, c)
err := os.WriteFile(filePath, []byte(executeCommand), 0777)
err = os.WriteFile(filePath, []byte(executeCommand), 0777)
if err != nil {
return fmt.Errorf("error writing command '%s': %v", filePath, err)
}
Expand Down