From 776ca35175d9f0b874d89149c048990a5136c6b1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= <kvch@users.noreply.github.com>
Date: Mon, 13 Jul 2020 14:42:03 +0200
Subject: [PATCH] Do not update go.mod during packaging and testing (#19823)
 (#19833)

(cherry picked from commit f91c96f672ba88edc668fe3d44249e46a3e9d2ec)
---
 dev-tools/mage/crossbuild.go | 1 +
 dev-tools/mage/fields.go     | 2 ++
 dev-tools/mage/integtest.go  | 1 +
 3 files changed, 4 insertions(+)

diff --git a/dev-tools/mage/crossbuild.go b/dev-tools/mage/crossbuild.go
index a553ee0e1970..8bce2103fd91 100644
--- a/dev-tools/mage/crossbuild.go
+++ b/dev-tools/mage/crossbuild.go
@@ -263,6 +263,7 @@ func (b GolangCrossBuilder) Build() error {
 
 	args = append(args,
 		"--rm",
+		"--env", "GOFLAGS=-mod=readonly",
 		"--env", "MAGEFILE_VERBOSE="+verbose,
 		"--env", "MAGEFILE_TIMEOUT="+EnvOr("MAGEFILE_TIMEOUT", ""),
 		"--env", fmt.Sprintf("SNAPSHOT=%v", Snapshot),
diff --git a/dev-tools/mage/fields.go b/dev-tools/mage/fields.go
index 94c3f899e9e5..a4837315729d 100644
--- a/dev-tools/mage/fields.go
+++ b/dev-tools/mage/fields.go
@@ -102,6 +102,7 @@ func generateFieldsYAML(baseDir, output string, moduleDirs ...string) error {
 	}
 
 	cmd := []string{"run",
+		"-mod=readonly",
 		filepath.Join(beatsDir, globalFieldsCmdPath),
 		"-es_beats_path", beatsDir,
 		"-beat_path", baseDir,
@@ -127,6 +128,7 @@ func GenerateFieldsGo(fieldsYML, out string) error {
 	}
 
 	cmd := []string{"run",
+		"-mod=readonly",
 		filepath.Join(beatsDir, assetCmdPath),
 		"-pkg", "include",
 		"-in", fieldsYML,
diff --git a/dev-tools/mage/integtest.go b/dev-tools/mage/integtest.go
index e932a55c45d2..94101c5056ba 100644
--- a/dev-tools/mage/integtest.go
+++ b/dev-tools/mage/integtest.go
@@ -236,6 +236,7 @@ func initRunner(tester IntegrationTester, dir string, passInEnv map[string]strin
 	// Create the custom env for the runner.
 	env := map[string]string{
 		insideIntegrationTestEnvVar: "true",
+		"GOFLAGS":                   "-mod=vendor",
 	}
 	for name, value := range passInEnv {
 		env[name] = value