Skip to content

Commit 7b95178

Browse files
committed
Run crossbuild container as host user
1 parent 657f366 commit 7b95178

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

dev-tools/mage/build.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,6 @@ func GolangCrossBuild(params BuildArgs) error {
166166
"only be executed within the golang-crossbuild docker environment")
167167
}
168168

169-
defer DockerChown(filepath.Join(params.OutputDir, params.Name+binaryExtension(GOOS)))
170-
defer DockerChown(filepath.Join(params.OutputDir))
171-
172-
mountPoint, err := ElasticBeatsDir()
173-
if err != nil {
174-
return err
175-
}
176-
if err := sh.Run("git", "config", "--global", "--add", "safe.directory", mountPoint); err != nil {
177-
return err
178-
}
179-
180169
return Build(params)
181170
}
182171

dev-tools/mage/crossbuild.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ func (b GolangCrossBuilder) Build() error {
273273
return fmt.Errorf("failed to determine repo root and package sub dir: %w", err)
274274
}
275275

276+
uid := os.Getuid()
277+
gid := os.Getgid()
278+
276279
mountPoint := filepath.ToSlash(filepath.Join("/go", "src", repoInfo.CanonicalRootImportPath))
277280
// use custom dir for build if given, subdir if not:
278281
cwd := repoInfo.SubDir
@@ -314,8 +317,8 @@ func (b GolangCrossBuilder) Build() error {
314317

315318
if runtime.GOOS != "windows" {
316319
args = append(args,
317-
"--env", "EXEC_UID="+strconv.Itoa(os.Getuid()),
318-
"--env", "EXEC_GID="+strconv.Itoa(os.Getgid()),
320+
"--env", fmt.Sprintf("EXEC_UID=%d", uid),
321+
"--env", fmt.Sprintf("EXEC_GID=%d", gid),
319322
)
320323
}
321324
if versionQualified {
@@ -353,6 +356,7 @@ func (b GolangCrossBuilder) Build() error {
353356
"--env", fmt.Sprintf("DEV=%v", DevBuild),
354357
"--env", fmt.Sprintf("EXTERNAL=%v", ExternalBuild),
355358
"--env", fmt.Sprintf("FIPS=%v", FIPSBuild),
359+
"--user", fmt.Sprintf("%d:%d", uid, gid),
356360
"-v", repoInfo.RootDir+":"+mountPoint,
357361
"-w", workDir,
358362
image,

0 commit comments

Comments
 (0)