Skip to content

Commit

Permalink
Added option to pass custom environment variables to the build enviro…
Browse files Browse the repository at this point in the history
…nment (#142)
  • Loading branch information
micbis authored Dec 13, 2021
1 parent 463708c commit 0df875d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions xgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var (
crossArgs = flag.String("depsargs", "", "CGO dependency configure arguments")
targets = flag.String("targets", "*/*", "Comma separated targets to build for")
dockerImage = flag.String("image", "", "Use custom docker image instead of official distribution")
dockerEnv = flag.String("env", "", "Comma separated custom environments added to docker run -e")
forwardSsh = flag.Bool("ssh", false, "Enable ssh agent forwarding")
)

Expand All @@ -68,6 +69,7 @@ type ConfigFlags struct {
Dependencies string // CGO dependencies (configure/make based archives)
Arguments string // CGO dependency configure arguments
Targets []string // Targets to build for
DockerEnv []string // Custom environments added to docker run -e
ForwardSsh bool // Enable ssh agent forwarding
}

Expand Down Expand Up @@ -177,6 +179,7 @@ func main() {
Dependencies: *crossDeps,
Arguments: *crossArgs,
Targets: strings.Split(*targets, ","),
DockerEnv: strings.Split(*dockerEnv, ","),
ForwardSsh: *forwardSsh,
}
flags := &BuildFlags{
Expand Down Expand Up @@ -351,6 +354,12 @@ func compile(image string, config *ConfigFlags, flags *BuildFlags, folder string
"-e", fmt.Sprintf("GOPROXY=%s", os.Getenv("GOPROXY")),
"-e", fmt.Sprintf("GOPRIVATE=%s", os.Getenv("GOPRIVATE")),
}
// Set custom environment variables
for _, s := range config.DockerEnv {
if s != "" {
args = append(args, []string{"-e", s}...)
}
}
if config.ForwardSsh && os.Getenv("SSH_AUTH_SOCK") != "" {
// Keep stdin open and allocate pseudo tty
args = append(args, "-i", "-t")
Expand Down

0 comments on commit 0df875d

Please sign in to comment.