-
Notifications
You must be signed in to change notification settings - Fork 143
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
move the package version file outside of app directory for MacOS #3335
Conversation
} | ||
} | ||
|
||
return filepath.Join(dirPath, PackageVersionFileName), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at
elastic-agent/internal/pkg/agent/application/paths/common.go
Lines 211 to 221 in 454e625
func retrieveExecutableDir() string { | |
execPath, err := os.Executable() | |
if err != nil { | |
panic(err) | |
} | |
evalPath, err := filepath.EvalSymlinks(execPath) | |
if err != nil { | |
panic(err) | |
} | |
return filepath.Dir(evalPath) | |
} |
elastic-agent/internal/pkg/agent/application/paths/common.go
Lines 229 to 241 in 454e625
// ExecDir returns the "executable" directory which is: | |
// 1. The same if the execDir is not inside of the data path | |
// 2. Two levels up if the execDir inside of the data path on non-macOS platforms | |
// 3. Five levels up if the execDir inside of the dataPath on macOS platform | |
func ExecDir(execDir string) string { | |
if isInsideData(execDir) { | |
execDir = filepath.Dir(filepath.Dir(execDir)) | |
if runtime.GOOS == darwin { | |
execDir = filepath.Dir(filepath.Dir(filepath.Dir(execDir))) | |
} | |
} | |
return execDir | |
} |
elastic-agent/internal/pkg/agent/application/paths/common.go
Lines 206 to 208 in 454e625
func initialTop() string { | |
return ExecDir(retrieveExecutableDir()) | |
} |
If I'm reading the logic of the GetAgentPackageVersionFilePath
function, it looks pretty much the same as the logic in the functions mentioned above. So maybe you could reuse them somehow, either by exporting retrieveExecutableDir()
from the paths
package or by moving GetAgentPackageVersionFilePath()
into the paths
package? This would also let you get rid of the getCurrentExecutablePath
function as I believe it's only being called from the GetAgentPackageVersionFilePath
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this patch I am not making any assumption as to what the directory structure is... I just cut off the part of the path that goes in elastic-agent.app
the code we have in paths requires that there are exactly 0, 2 or 5 levels (for Mac) between the executable and the execDir.
The initial idea of this was to have the package version file side by side with the executable wherever it is... we are just moving it for mac because of package signing issues and I would prefer to keep changes to a minimum for this hotfix. We can open a follow-up issue if you feel that we should remove the duplication (we still have to verify that everything still works also for packages that we just extract somewhere on disk as it must not depend on installing agent)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds fair. Would you mind opening that follow up issue and linking it here so we don't lose track of this work? We really should ideally have only one code path through which paths are determined. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created #3337
Pinging @elastic/elastic-agent (Team:Elastic-Agent) |
🌐 Coverage report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested this PR locally on my Mac.
Before this PR
After installing Agent:
$ sudo find /Library/Elastic/Agent -iname package.version
/Library/Elastic/Agent/data/elastic-agent-454e62/elastic-agent.app/Contents/MacOS/package.version
$ sudo cat /Library/Elastic/Agent/data/elastic-agent-454e62/elastic-agent.app/Contents/MacOS/package.version
8.11.0
$ sudo elastic-agent version
Binary: 8.11.0-SNAPSHOT (build: 454e6253a0e3457828b769e7c2c7c0e9365d870b at 2023-08-30 17:38:19 +0000 UTC)
Daemon: 8.11.0-SNAPSHOT (build: 454e6253a0e3457828b769e7c2c7c0e9365d870b at 2023-08-30 17:38:19 +0000 UTC)
After this PR
After installing Agent:
$ sudo find /Library/Elastic/Agent -iname package.version
/Library/Elastic/Agent/data/elastic-agent-73b4c7/package.version
$ sudo cat /Library/Elastic/Agent/data/elastic-agent-73b4c7/package.version
8.11.0
$ sudo elastic-agent version
Binary: 8.11.0-SNAPSHOT (build: 73b4c7cfaef362452cac4bd03e19518ed61212d5 at 2023-08-30 17:35:04 +0000 UTC)
Daemon: 8.11.0-SNAPSHOT (build: 73b4c7cfaef362452cac4bd03e19518ed61212d5 at 2023-08-30 17:35:04 +0000 UTC)
Thx @ycombinator, I'm merging this to unlock the next BC. |
(cherry picked from commit 7dcc732)
…) (#3336) (cherry picked from commit 7dcc732) Co-authored-by: Paolo Chilà <[email protected]>
What does this PR do?
Move elastic package version file outside of
elastic-agent.app
directory to fix the package signing for MacWhy is it important?
Checklist
[ ] I have commented my code, particularly in hard-to-understand areas[ ] I have made corresponding changes to the documentation[ ] I have made corresponding change to the default configuration files[ ] I have added tests that prove my fix is effective or that my feature works[ ] I have added an entry in./changelog/fragments
using the changelog tool[ ] I have added an integration test or an E2E testAuthor's Checklist
How to test this PR locally
Related issues
Use cases
Screenshots
Logs
Questions to ask yourself