Skip to content

Commit

Permalink
Adjust path for GH actions
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelroquetto committed Feb 22, 2025
1 parent e5b8032 commit 6910357
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions bpf/build_ebpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
"strings"
)

const OCI_BIN = "docker"
Expand All @@ -33,6 +34,24 @@ func getPipes(cmd *exec.Cmd) (io.ReadCloser, io.ReadCloser, error) {
return stdout, stderr, nil
}

// when a GH action job is executed inside a container, the host workspace in
// the host gets mounted in the '/__w' target directory. However, because the
// beyla-ebpf-generator image runs as a sibling container (it shares the same
// docker socket), we need to pass the host path to the '/src' volume rather
// than the detected container path
func adjustPathForGitHubActions(path string) string {
const prefixInContainer = "/__w/"
const prefixInHost = "/home/runner/work/"

_, isGithubWorkflow := os.LookupEnv("GITHUB_WORKSPACE")

if isGithubWorkflow && strings.HasPrefix(path, prefixInContainer) {
return strings.Replace(path, prefixInContainer, prefixInHost, 1)
}

return path
}

func moduleRoot() (string, error) {
wd, err := os.Getwd()

Expand Down Expand Up @@ -66,6 +85,8 @@ func main() {
os.Exit(1)
}

wd = adjustPathForGitHubActions(wd)

cmd := exec.Command(OCI_BIN, "run", "--rm", "-v", wd+":/src", GEN_IMG)

stdoutPipe, stderrPipe, err := getPipes(cmd)
Expand Down

0 comments on commit 6910357

Please sign in to comment.