-
Notifications
You must be signed in to change notification settings - Fork 198
[packaging] proxy binary to be for the root dir of windows archive #7601
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
Merged
pkoutsovasilis
merged 14 commits into
elastic:main
from
pkoutsovasilis:packaging/windows_archive_root_binary
Mar 31, 2025
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
159b7b6
feat: implement a proxy binary to be placed in the root of windows ar…
pkoutsovasilis 521e771
fix: remove redundant returns in the code
pkoutsovasilis 6f5df45
fix: reword error message when we cannot stat inner elastic-agent binary
pkoutsovasilis fe889d4
fix: use slices.Contains to check if we are building for windows/amd64
pkoutsovasilis bc4c38c
fix: add comment to capture that CommitSHA is set at build time
pkoutsovasilis 40c08a7
fix: rename hack folder to wrapper
pkoutsovasilis 0a47027
fix: reside typo
pkoutsovasilis 316fc11
fix: reword error message when we cannot stat inner elastic-agent binary
pkoutsovasilis c9a698b
ci: automate go version updates for wrapper/windows/archive-proxy/go.mod
pkoutsovasilis e7c6ed6
fix: switch logging to fmt and also log to windows event logger
pkoutsovasilis b088b05
Revert "ci: automate go version updates for wrapper/windows/archive-p…
pkoutsovasilis df09d40
fix: initialise windows event log only if we are admin
pkoutsovasilis 39d651a
fix: remove os.Stat call and rely on command.Start() to raise an erro…
pkoutsovasilis efe5fd5
fix: remove custom logger
pkoutsovasilis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| module github.com/elastic/elastic-agent/hack/windows/archive-proxy | ||
|
|
||
| go 1.24.1 | ||
|
|
||
| require github.com/elastic/elastic-agent v0.0.0 | ||
|
|
||
| require golang.org/x/sys v0.31.0 // indirect | ||
|
|
||
| replace github.com/elastic/elastic-agent => ../../../ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| // or more contributor license agreements. Licensed under the Elastic License 2.0; | ||
| // you may not use this file except in compliance with the Elastic License 2.0. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "log" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
|
|
||
| "github.com/elastic/elastic-agent/pkg/core/process" | ||
| ) | ||
|
|
||
| // CommitSHA is set by the linker at build time | ||
| var CommitSHA string | ||
pkoutsovasilis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| func main() { | ||
| if CommitSHA == "" { | ||
| // this should never happen | ||
| log.Fatal("No commit SHA provided") | ||
| } | ||
|
|
||
| exePath, err := os.Executable() | ||
| if err != nil { | ||
| log.Fatalf("Error getting executable path: %v\n", err) | ||
| } | ||
|
|
||
| exeAbsPath, err := filepath.Abs(exePath) | ||
| if err != nil { | ||
| log.Fatalf("Error getting executable absolute path: %v\n", err) | ||
| } | ||
|
|
||
| // Fabricate the elastic-agent.exe path that reside inside the data/elastic-agent-{commit-short-sha} directory | ||
pkoutsovasilis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| exeTopPath := filepath.Dir(exeAbsPath) | ||
| nestedAgentBinaryPath := filepath.Join(exeTopPath, "data", fmt.Sprintf("elastic-agent-%s", CommitSHA), "elastic-agent.exe") | ||
| if _, err := os.Stat(nestedAgentBinaryPath); err != nil { | ||
| log.Fatalf("Unable to stat inner agent binary at %q: %v\n", nestedAgentBinaryPath, err) | ||
pkoutsovasilis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // Create the arguments | ||
| var args []string | ||
| if len(os.Args) > 1 { | ||
| args = os.Args[1:] | ||
| } | ||
|
|
||
| g, err := process.CreateJobObject() | ||
| if err != nil { | ||
| log.Fatalf("Unable to create job object: %v\n", err) | ||
| } | ||
| defer func() { | ||
| _ = g.Close() | ||
| }() | ||
|
|
||
| // Create the command | ||
| command := exec.Command(nestedAgentBinaryPath, args...) | ||
|
|
||
| // Forward stdout, stderr, stdin | ||
| command.Stdout = os.Stdout | ||
| command.Stderr = os.Stderr | ||
| command.Stdin = os.Stdin | ||
|
|
||
| // Pass the environment | ||
| command.Env = os.Environ() | ||
|
|
||
| // Run the command | ||
| err = command.Start() | ||
| if err != nil { | ||
| log.Fatalf("Error running command: %v\n", err) | ||
| } | ||
|
|
||
| // Add the process to the job object | ||
| if err := g.Assign(command.Process); err != nil { | ||
| log.Fatalf("Error adding job object: %v\n", err) | ||
| } | ||
|
|
||
| err = command.Wait() | ||
| var exitError *exec.ExitError | ||
| switch { | ||
| case errors.As(err, &exitError): | ||
| exitCode := exitError.ExitCode() | ||
| if exitCode == 0 { | ||
| // Exit with non-zero exit code since we did get an error | ||
| os.Exit(1) | ||
| } | ||
| // Exit with the same exit code | ||
| os.Exit(exitCode) | ||
| case err != nil: | ||
| // Exit with a non-zero exit code | ||
| log.Fatalf("Command failed: %v\n", err) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.