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
19 changes: 19 additions & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ mise run cli:test:e2e:focus "pattern"

`cli:test:e2e:act:focus` runs a focused pattern through [act](https://github.com/nektos/act).

The Docker lifecycle environment regression covers values containing `=` from both
`--workspace-env` and `--workspace-env-file`, including restart and `remoteEnv` precedence:

```bash
mise run cli:test:e2e:focus "lifecycle hooks preserve equals signs"
```

When testing local changes with Docker on macOS, run this from `e2e/` and point
`DEVSY_AGENT_BINARY` at the local Linux agent matching the Docker architecture:

```bash
DEVSY_AGENT_BINARY="$PWD/bin/devsy-linux-arm64" \
GOMAXPROCS=1 GOFLAGS=-p=1 mise exec -- go tool ginkgo --focus \
"lifecycle hooks preserve equals signs"
```

This bypasses cached release agents; otherwise the container can run a released
binary rather than the code under test.

## Kubernetes tests

Specs labeled `up-provider-kubernetes` or `build` need a kind cluster. The setup task
Expand Down
3 changes: 2 additions & 1 deletion e2e/tests/up/microsandbox_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
const (
microsandboxResourceBuiltin = provider.DeprecatedMicrosandboxSource
osLinux = "linux"
osDarwin = "darwin"
microsandboxExternalProvider = "github.com/devsy-org/devsy-provider-microsandbox@v0.1.10"
microsandboxRootUser = "root"
)
Expand All @@ -31,7 +32,7 @@ func skipIfNoMicrosandbox(ctx context.Context) {
microsandboxUnavailable("microsandbox requires KVM (/dev/kvm not accessible)")
}
_ = kvm.Close()
case runtime.GOOS == "darwin" && runtime.GOARCH == "arm64":
case runtime.GOOS == osDarwin && runtime.GOARCH == "arm64":
// Apple silicon supports microsandbox via the hypervisor framework.
default:
microsandboxUnavailable("microsandbox requires Apple silicon or Linux with KVM")
Expand Down
116 changes: 116 additions & 0 deletions e2e/tests/up/provider_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import (
"os/exec"
"path"
"path/filepath"
"runtime"
"slices"
"strings"
"time"

"github.com/devsy-org/devsy/e2e/framework"
devsyconfig "github.com/devsy-org/devsy/pkg/config"
docker "github.com/devsy-org/devsy/pkg/docker"
"github.com/devsy-org/devsy/pkg/flags/names"
provider2 "github.com/devsy-org/devsy/pkg/provider"
Expand All @@ -20,6 +23,8 @@ import (
"github.com/onsi/gomega"
)

const envEqualsIsolatedHomeLabel = "env-equals-isolated-home"

var _ = ginkgo.Describe(
"testing up command for docker customizations",
ginkgo.Label("up-provider-docker"),
Expand All @@ -31,6 +36,23 @@ var _ = ginkgo.Describe(
dtc = &dockerTestContext{}
dtc.initialDir, err = os.Getwd()
framework.ExpectNoError(err)
if slices.Contains(
ginkgo.CurrentSpecReport().Labels(),
envEqualsIsolatedHomeLabel,
) {
homeParent := os.TempDir()
if runtime.GOOS == osDarwin {
homeParent = "/tmp"
}
home, err := os.MkdirTemp(homeParent, "devsy-e2e-")
framework.ExpectNoError(err)
ginkgo.DeferCleanup(func() {
framework.ExpectNoError(os.RemoveAll(home))
})
devsyconfig.ResetPathManager()
ginkgo.DeferCleanup(devsyconfig.ResetPathManager)
framework.SetEnvForSpec(devsyconfig.EnvHome, home)
}

dtc.dockerHelper = &docker.DockerHelper{DockerCommand: "docker"}
dtc.f, err = framework.SetupDockerProvider(
Expand Down Expand Up @@ -245,6 +267,100 @@ var _ = ginkgo.Describe(
gomega.Expect(unsetLine).To(gomega.Equal("UNSET=true"))
}, ginkgo.SpecTimeout(framework.TimeoutShort()))

ginkgo.It(
"lifecycle hooks preserve equals signs in environment values",
ginkgo.Label(envEqualsIsolatedHomeLabel),
func(ctx context.Context) {
initialConfig, err := devsyconfig.LoadConfig("", "")
framework.ExpectNoError(err)
sentinelContext := fmt.Sprintf("env-equals-sentinel-%d", time.Now().UnixNano())
gomega.Expect(initialConfig.Contexts).NotTo(
gomega.HaveKey(sentinelContext),
"sentinel context must not preexist in the isolated home",
)
framework.ExpectNoError(dtc.f.DevsyContextCreate(ctx, sentinelContext))
framework.ExpectNoError(dtc.f.DevsyContextUse(ctx, sentinelContext))

priorConfig, err := devsyconfig.LoadConfig("", "")
framework.ExpectNoError(err)
priorContext := priorConfig.DefaultContext
gomega.Expect(priorContext).To(gomega.Equal(sentinelContext))

contextName := fmt.Sprintf("env-equals-%d", time.Now().UnixNano())
gomega.Expect(priorConfig.Contexts).NotTo(
gomega.HaveKey(contextName),
"test context must not preexist in the isolated home",
)
framework.ExpectNoError(dtc.f.DevsyContextCreate(ctx, contextName))
ginkgo.DeferCleanup(func(cleanupCtx context.Context) {
if err := dtc.f.DevsyContextUse(cleanupCtx, priorContext); err != nil {
framework.ExpectNoError(err)
return
}
if err := dtc.f.DevsyContextDelete(cleanupCtx, contextName); err != nil {
framework.ExpectNoError(err)
return
}
currentConfig, err := devsyconfig.LoadConfig("", "")
framework.ExpectNoError(err)
gomega.Expect(currentConfig.DefaultContext).To(gomega.Equal(priorContext))
})
framework.ExpectNoError(dtc.f.DevsyContextUse(ctx, contextName))
framework.ExpectNoError(
dtc.f.DevsyProviderAdd(ctx, "docker", "-o", "DOCKER_PATH=docker"),
)

tempDir, err := setupWorkspace(
"tests/up/testdata/docker-workspace-env-equals", dtc.initialDir, dtc.f,
)
framework.ExpectNoError(err)

framework.ExpectNoError(dtc.f.DevsyUp(ctx, tempDir,
"--workspace-env", "PLAIN=hello",
"--workspace-env", "ONE_EQ=a=b",
"--workspace-env", "TWO_EQ=a=b=c",
"--workspace-env", "COMMA_EQ=x=1,y=2",
"--workspace-env", "TRAILING_EQ=z=",
"--workspace-env-file", filepath.Join(tempDir, "workspace.env"),
))

expected := "PLAIN=hello\nONE_EQ=a=b\nTWO_EQ=a=b=c\nCOMMA_EQ=x=1,y=2\n" +
"TRAILING_EQ=z=\nFILE_ONE_EQ=k=v"
expectedHook := expected + "\nREMOTE_EQ=remote=a=b"
expectedSSH := expectedHook
expectedEnvFile := expectedHook
for _, phase := range []string{"postCreate", "postStart"} {
out, err := readLifecycleFile(tempDir, phase+".env.out")
framework.ExpectNoError(err)
gomega.Expect(out).To(gomega.Equal(expectedHook), phase)
}

out, err := dtc.execSSHCapture(ctx, tempDir, `bash -l -c '
printf "PLAIN=%s\nONE_EQ=%s\nTWO_EQ=%s\nCOMMA_EQ=%s\nTRAILING_EQ=%s\nFILE_ONE_EQ=%s\nREMOTE_EQ=%s\n" \
"$PLAIN" "$ONE_EQ" "$TWO_EQ" "$COMMA_EQ" "$TRAILING_EQ" "$FILE_ONE_EQ" "$REMOTE_EQ"'`)
framework.ExpectNoError(err)
gomega.Expect(out).To(gomega.Equal(expectedSSH), "SSH environment")

// Filter in the container so unrelated persisted values never reach test logs.
out, err = dtc.execSSHCapture(ctx, tempDir, `jq -r '.env |
"PLAIN=\(.PLAIN)\nONE_EQ=\(.ONE_EQ)\n" +
"TWO_EQ=\(.TWO_EQ)\nCOMMA_EQ=\(.COMMA_EQ)\n" +
"TRAILING_EQ=\(.TRAILING_EQ)\nFILE_ONE_EQ=\(.FILE_ONE_EQ)\n" +
"REMOTE_EQ=\(.REMOTE_EQ)"' /etc/envfile.json`)
framework.ExpectNoError(err)
gomega.Expect(out).To(gomega.Equal(expectedEnvFile), "persisted environment")

// Remove the old output to prove postStartCommand runs again after restart.
framework.ExpectNoError(os.Remove(filepath.Join(tempDir, "postStart.env.out")))
framework.ExpectNoError(dtc.f.DevsyWorkspaceStop(ctx, tempDir))
framework.ExpectNoError(dtc.f.DevsyUp(ctx, tempDir))
out, err = readLifecycleFile(tempDir, "postStart.env.out")
framework.ExpectNoError(err)
gomega.Expect(out).To(gomega.Equal(expectedHook), "postStart after restart")
},
ginkgo.SpecTimeout(framework.TimeoutModerate()),
)

ginkgo.It("mounts", func(ctx context.Context) {
tempDir, err := dtc.setupAndUp(ctx, "tests/up/testdata/docker-mounts", "--debug")
framework.ExpectNoError(err)
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/up/provider_microsandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func assertMicrosandboxHostEntries(

func microsandboxHostOwner(ctx context.Context, entry string) string {
args := []string{"-c", "%u:%g", entry}
if runtime.GOOS == "darwin" {
if runtime.GOOS == osDarwin {
args = []string{"-f", "%u:%g", entry}
}
// #nosec G204 -- fixed stat executable and test-created path
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"image": "ghcr.io/devsy-org/test-images/go:1",
"userEnvProbe": "loginInteractiveShell",
"waitFor": "postStartCommand",
"containerEnv": {
"REMOTE_EQ": "inherited=value"
},
"remoteEnv": {
"REMOTE_EQ": "remote=a=b"
},
"postCreateCommand": "bash .devcontainer/dump-env.sh postCreate",
"postStartCommand": "bash .devcontainer/dump-env.sh postStart"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# Writes only the synthetic test variables; never dump the full environment.
phase="$1"
out="$phase.env.out"
: >"$out"
for name in PLAIN ONE_EQ TWO_EQ COMMA_EQ TRAILING_EQ FILE_ONE_EQ REMOTE_EQ; do
printf '%s=%s\n' "$name" "${!name}" >>"$out"
done
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FILE_ONE_EQ=k=v
2 changes: 2 additions & 0 deletions hack/ci/suites.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ e2e:
ungated:
- label: gh-forwarding
reason: sub-label that always accompanies the ssh suite label
- label: env-equals-isolated-home
reason: sub-label that always accompanies the up-provider-docker suite label
- label: up-provider-podman-machine-bind
reason: darwin-only spec that needs a local Podman machine; run manually on macOS
- label: gpg
Expand Down
7 changes: 5 additions & 2 deletions pkg/devcontainer/config/prepareprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ func PrepareCmdUser(cmd *exec.Cmd, userName string) error {
func patchEnvVars(env []string, patches map[string]string) []string {
newEnv := map[string]string{}
for _, v := range env {
t := strings.Split(v, "=")
newEnv[t[0]] = t[1]
name, value, ok := strings.Cut(v, "=")
if !ok || name == "" {
continue
}
newEnv[name] = value
}

// apply patches
Expand Down
Loading
Loading