Skip to content

Commit

Permalink
move msgo root logic to python
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkb7 committed Dec 3, 2024
1 parent 515a900 commit 87633e0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 1 addition & 5 deletions omnibus/config/software/datadog-agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@
# Use msgo toolchain when fips mode is enabled
if fips_mode?
if windows_target?
go_version = ENV['GO_VERSION'] || File.read("#{project_dir}/.go-version").strip
if go_version.empty?
raise "GO_VERSION is not set and .go-version file is not present"
end
msgoroot = "C:\\msgo\\#{go_version}\\go"
msgoroot = ENV['MSGO_ROOT']
# ensure msgoroot\bin\go.exe file exists
if !File.exist?("#{msgoroot}\\bin\\go.exe")
raise "msgo go.exe not found at #{msgoroot}\\bin\\go.exe"
Expand Down
8 changes: 8 additions & 0 deletions tasks/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,3 +715,11 @@ def mod_diffs(_, targets):
print(f" - Version {version} in:")
for path in paths:
print(f" * {path}")


def repo_go_version():
"""
Returns the go version specified in the .go-version file
"""
with open('.go-version') as f:
return f.read().strip()
15 changes: 14 additions & 1 deletion tasks/omnibus.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from invoke.exceptions import Exit, UnexpectedExit

from tasks.flavor import AgentFlavor
from tasks.go import deps
from tasks.go import deps, repo_go_version
from tasks.libs.common.omnibus import (
install_dir_for_project,
omnibus_compute_cache_key,
Expand Down Expand Up @@ -136,6 +136,19 @@ def get_omnibus_env(

if fips_mode:
env['FIPS_MODE'] = 'true'
if sys.platform == 'win32' and not os.environ.get('MSGO_ROOT'):
# Point omnibus at the msgo root
# TODO: idk how to do this in omnibus datadog-agent.rb
# because `File.read` is executed when the script is loaded,
# not when the `command`s are run and the source tree is not
# available at that time.
# Comments from the Linux FIPS PR discussed wanting to centralize
# the msgo root logic, so this can be updated then.
go_version = repo_go_version()
env['MSGO_ROOT'] = f'C:\\msgo\\{go_version}\\go'
gobinpath = f"{env['MSGO_ROOT']}\\bin\\go.exe"
if not os.path.exists(gobinpath):
raise Exit(f"msgo go.exe not found at {gobinpath}")

# We need to override the workers variable in omnibus build when running on Kubernetes runners,
# otherwise, ohai detect the number of CPU on the host and run the make jobs with all the CPU.
Expand Down

0 comments on commit 87633e0

Please sign in to comment.