From 75bdd30985dcf936c3172c511baad2962fe62659 Mon Sep 17 00:00:00 2001 From: Erik Skultety Date: Thu, 14 Dec 2023 15:18:53 +0100 Subject: [PATCH] pkg_managers: gomod: Add preliminary support for Go 1.21 One of Go 1.21's main features is specifying the suggested version of toolchain to be used for compiling modules as a means of forwards compatibility. However, this patch only adds preliminary support for Go 1.21 in that it essentially explicitly denies usage of toolchains (which is fine, because those versions are only suggestive, Go always prefers building with the bundled toolchain anyway) by the means of explicitly setting the GOTOOLCHAIN env variable to 'local' which instructs Go to always use it bundled toolchain (provided it's new enough to conform to the minimum required version of Go indicated by the 'go' line). This patch makes sure we set GOTOOLCHAIN=local during fetching of the dependencies as well as for user container builds. STONEBLD-2047 Signed-off-by: Erik Skultety --- cachito/web/static/api_v1.yaml | 6 ++++++ cachito/workers/config.py | 6 +++++- cachito/workers/pkg_managers/gomod.py | 1 + tests/test_workers/test_tasks/test_gomod.py | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cachito/web/static/api_v1.yaml b/cachito/web/static/api_v1.yaml index ad01fb749..e4a7d7d6b 100644 --- a/cachito/web/static/api_v1.yaml +++ b/cachito/web/static/api_v1.yaml @@ -541,6 +541,9 @@ paths: GOSUMDB: value: off kind: literal + GOTOOLCHAIN: + value: local + kind: literal "404": description: The request wasn't found content: @@ -1222,6 +1225,9 @@ components: GOSUMDB: value: off kind: literal + GOTOOLCHAIN: + value: local + kind: literal state: $ref: "#/components/schemas/RequestState" state_reason: diff --git a/cachito/workers/config.py b/cachito/workers/config.py index 3f6a5ab6a..bdefba93d 100644 --- a/cachito/workers/config.py +++ b/cachito/workers/config.py @@ -29,7 +29,10 @@ class Config(object): cachito_archives_minimum_age_days = 365 cachito_auth_type: Optional[str] = None cachito_default_environment_variables = { - "gomod": {"GOSUMDB": {"value": "off", "kind": "literal"}}, + "gomod": { + "GOSUMDB": {"value": "off", "kind": "literal"}, + "GOTOOLCHAIN": {"value": "local", "kind": "literal"}, + }, "npm": { "CHROMEDRIVER_SKIP_DOWNLOAD": {"value": "true", "kind": "literal"}, "CYPRESS_INSTALL_BINARY": {"value": "0", "kind": "literal"}, @@ -161,6 +164,7 @@ class TestingConfig(DevelopmentConfig): "gomod": { "GO111MODULE": {"value": "on", "kind": "literal"}, "GOSUMDB": {"value": "off", "kind": "literal"}, + "GOTOOLCHAIN": {"value": "local", "kind": "literal"}, }, "npm": { "CHROMEDRIVER_SKIP_DOWNLOAD": {"value": "true", "kind": "literal"}, diff --git a/cachito/workers/pkg_managers/gomod.py b/cachito/workers/pkg_managers/gomod.py index 91eb3934d..5cad8ee6b 100644 --- a/cachito/workers/pkg_managers/gomod.py +++ b/cachito/workers/pkg_managers/gomod.py @@ -312,6 +312,7 @@ def resolve_gomod(app_source_path, request, dep_replacements=None, git_dir_path= "GOPROXY": f"{athens_url}|{athens_url}", "PATH": os.environ.get("PATH", ""), "GOMODCACHE": "{}/pkg/mod".format(temp_dir), + "GOTOOLCHAIN": "local", } if "cgo-disable" in request.get("flags", []): env["CGO_ENABLED"] = "0" diff --git a/tests/test_workers/test_tasks/test_gomod.py b/tests/test_workers/test_tasks/test_gomod.py index 26378cc9e..5fae60a45 100644 --- a/tests/test_workers/test_tasks/test_gomod.py +++ b/tests/test_workers/test_tasks/test_gomod.py @@ -114,6 +114,7 @@ def directory_present(*args, **kwargs): env_vars = { "GO111MODULE": {"value": "on", "kind": "literal"}, "GOSUMDB": {"value": "off", "kind": "literal"}, + "GOTOOLCHAIN": {"value": "local", "kind": "literal"}, } sample_env_vars.update(env_vars)