What are the GOOS and GOARCH values to build go executable file on GCP Container-Optimized OS

4/16/2018

I am writing a script that will download the executable binary from Google cloud storage and execute it on the Google cloud compute.

But, I don't know what would be the right values for GOOS and GOARCH environment variables to build the executable with go build command.

-- prideloki
go
google-cloud-platform
google-kubernetes-engine

2 Answers

4/16/2018

Container-Optimized OS is a Linux derivate, and to the best of my knowledge all GCE instances are x86_64 machines. This machine is a n1-standard-1 with the stable COS image:

user@instance-1 ~ $ uname -a
Linux instance-1 4.4.111+ #1 SMP Thu Apr 5 21:21:21 PDT 2018 x86_64 Intel(R) Xeon(R) CPU @ 2.50GHz GenuineIntel GNU/Linux

So to build for COS use

GOOS=linux GOARCH=amd64
-- Peter
Source: StackOverflow

4/16/2018

Here's an example of building Go binaries for various processor architectures and operating systems:

#!/usr/bin/env bash

# Build go binaries for the 3 main architectures that we can use on 
tagged releases
for GOOS in darwin linux windows; do
    for GOARCH in 386 amd64; do
        go build -v -o gm-fabric-proxy-$GOOS-$GOARCH
    done
done

Basically GOOS tells the Go compiler which OS you want to compile to, and GOARCH tells the compiler which processor architecture it needs to conform to.

On unix based systems you can run this command to find your processor architecture and operating sytem kernel info:

Alecs-MacPro:~ user$ uname -a
Darwin Alecs-MacPro.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64

The script example provided above will create binaries for the 3 main operating systems and 2 main architectures.

-- Alec Holmes
Source: StackOverflow