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

fix(test): fix agent url on non-linux runners #971

Merged
merged 5 commits into from
Mar 28, 2024
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
54 changes: 25 additions & 29 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,21 @@ jobs:
max-parallel: 16
matrix:
label:
[
"build",
"ide",
"integration",
"machine",
"machineprovider",
"provider",
"proxyprovider",
"ssh",
"up",
"up-docker",
"up-podman",
"up-docker-compose",
"up-docker-build",
"up-docker-compose-build",
"context",
]
- "build"
- "ide"
- "integration"
- "machine"
- "machineprovider"
- "provider"
- "proxyprovider"
- "ssh"
- "up"
- "up-docker"
- "up-podman"
- "up-docker-compose"
- "up-docker-build"
- "up-docker-compose-build"
- "context"

steps:
- name: Checkout repo
Expand Down Expand Up @@ -97,15 +95,13 @@ jobs:
max-parallel: 1
matrix:
label:
[
"build",
"ide",
"ssh",
"up-docker",
"up-docker-build",
"up-docker-compose",
"up-docker-wsl",
]
- "build"
- "ide"
- "ssh"
- "up-docker"
- "up-docker-build"
- "up-docker-compose"
- "up-docker-wsl"

steps:
- name: Git set line ending
Expand All @@ -122,14 +118,14 @@ jobs:

- name: Build binary and copy to the E2E directory
run: |
go build -ldflags "-s -w" -o devpod-windows-amd64.exe
mkdir e2e\bin
cp devpod-windows-amd64.exe e2e\bin\
go build -ldflags "-s -w" -o e2e\bin\devpod-windows-amd64.exe
$Env:GOOS = "linux"; $Env:GOARCH = "amd64"; go build -ldflags "-s -w" -o e2e\bin\devpod-linux-amd64

- name: E2E test
working-directory: .\e2e
run: |
go run github.com/onsi/ginkgo/v2/ginkgo -r -p --timeout=3600s --label-filter=${{ matrix.label }}
go run github.com/onsi/ginkgo/v2/ginkgo -r --timeout=3600s --label-filter=${{ matrix.label }}

- name: Container cleanup
if: ${{ always() }}
Expand Down
18 changes: 12 additions & 6 deletions .github/workflows/e2e-win-full-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ jobs:
fail-fast: true
max-parallel: 1
matrix:
# windows blocklist: "up-podman", "integration", "machineprovider", "proxyprovider", "up"
label: ["build", "ide", "machine", "provider", "ssh", "up-docker", "up-docker-compose", "up-docker-build", "up-docker-compose-build", "up-docker-wsl"]
label:
- "build"
- "ide"
- "ssh"
- "up-docker"
- "up-docker-build"
- "up-docker-compose"
- "up-docker-wsl"

steps:
- name: Git set line ending
Expand All @@ -37,14 +43,14 @@ jobs:

- name: Build binary and copy to the E2E directory
run: |
go build -ldflags "-s -w" -o devpod-windows-amd64.exe
mkdir e2e\bin
cp devpod-windows-amd64.exe e2e\bin\
mkdir e2e\bin
go build -ldflags "-s -w" -o e2e\bin\devpod-windows-amd64.exe
$Env:GOOS = "linux"; $Env:GOARCH = "amd64"; go build -ldflags "-s -w" -o e2e\bin\devpod-linux-amd64

- name: E2E test
working-directory: .\e2e
run: |
go run github.com/onsi/ginkgo/v2/ginkgo -r -p --timeout=3600s --label-filter=${{ matrix.label }}
go run github.com/onsi/ginkgo/v2/ginkgo -r --timeout=3600s --label-filter=${{ matrix.label }}

- name: Container cleanup
if: ${{ always() }}
Expand Down
16 changes: 16 additions & 0 deletions e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package e2e

import (
"os"
"runtime"
"testing"
"time"

"github.com/onsi/ginkgo/v2"

"github.com/onsi/gomega"

"github.com/loft-sh/devpod/e2e/framework"

// Register tests
_ "github.com/loft-sh/devpod/e2e/tests/build"
_ "github.com/loft-sh/devpod/e2e/tests/context"
Expand All @@ -26,6 +31,17 @@ import (
// generated in this directory, and cluster logs will also be saved.
// This function is called on each Ginkgo node in parallel mode.
func TestRunE2ETests(t *testing.T) {
if runtime.GOOS != "linux" {
go framework.ServeAgent()

// wait for http server to be up and running
for {
time.Sleep(time.Second)
if os.Getenv("DEVPOD_AGENT_URL") != "" {
break
}
}
}
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "DevPod e2e suite")
}
85 changes: 85 additions & 0 deletions e2e/framework/server_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package framework

import (
"fmt"
"log"
"net"
"net/http"
"os"
"path/filepath"
)

// serveAgent will be a simple http file server that will expose our
// freshly compiled devpod binaries to be downloaded as agents.
// useful for non-linux runners
func ServeAgent() {
// Specify the directory containing the files you want to serve
dir := "bin"

wd, err := os.Getwd()
if err == nil {
dir = filepath.Join(wd, "bin")
}

// Create a file server handler for the specified directory
fileServer := http.FileServer(http.Dir(dir))

// Register the file server handler to serve files under the /files route
http.Handle("/files/", http.StripPrefix("/files", fileServer))

ip := getIP()

listener, err := net.Listen("tcp", fmt.Sprintf("%v:0", ip))
if err != nil {
log.Fatal(err)
}

addr := listener.Addr().String()
err = os.Setenv("DEVPOD_AGENT_URL", "http://"+addr+"/files/")
if err != nil {
log.Fatal(err)
}

// Start the HTTP server on port 8080
log.Printf("Server started on %s", addr)

err = http.Serve(listener, nil)
if err != nil {
log.Fatal(err)
}
}

func getIP() string {
// Get a list of network interfaces
ifaces, err := net.Interfaces()
if err != nil {
return "0.0.0.0"
}

// Iterate over each network interface
for _, iface := range ifaces {
addrs, err := iface.Addrs()
if err != nil {
return "0.0.0.0"
}

for _, addr := range addrs {
switch v := addr.(type) {
case *net.IPAddr:
if v.IP.To4() != nil {
if v.IP.DefaultMask().String() == "ffffff00" || v.IP.DefaultMask().String() == "ff000000" {
return v.IP.String()
}
}
case *net.IPNet:
if v.IP.To4() != nil {
if v.IP.DefaultMask().String() == "ffffff00" || v.IP.DefaultMask().String() == "ff000000" {
return v.IP.String()
}
}
}
}
}

return "0.0.0.0"
}
4 changes: 4 additions & 0 deletions pkg/agent/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func InjectAgentAndExecute(
versionCheck := fmt.Sprintf(`[ "$(%s version 2>/dev/null || echo 'false')" != "%s" ]`, remoteAgentPath, version.GetVersion())
if version.GetVersion() == version.DevVersion {
preferDownload = false

if runtime.GOOS != "linux" {
preferDownload = true
}
}

// install devpod into the target
Expand Down
Loading