I'm running a go build
command on a golang:1.11-alpine
on two separate CI tools. As you can see the commands are exactly the same and the docker image is exactly the same.
For some reason, when I run the compiled executable on an alpine:3.9
docker image, only the bitbucket runs.
For the Circle CI build, I get the following error:
standard_init_linux.go:207: exec user process caused “exec format error”
I was reading online that it might be an architecture issue so I did a file <file>
in the terminal and it appears both were compiled the same way. Here is the response I received for both files (identical):
cloud: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, stripped
docker:
- image: golang:1.11-alpine
steps:
- checkout
- run:
name: Build Go Server
command: |
apk add --no-cache git build-base
export GOPATH="$HOME/go"
export PATH="$PATH:$GOPATH/bin"
go get -u github.com/golang/lint/[email protected]
go mod vendor
golint -set_exit_status $(go list ./... | grep -v /vendor/)
go test -short $(go list ./... | grep -v /vendor/)
go build -ldflags="-s -w"
steps:
- step: &step-test-and-build-go
name: Test and Build Go Server
image: golang:1.11-alpine
script:
- apk add --no-cache git build-base
- export GOPATH="$HOME/go"
- export PATH="$PATH:$GOPATH/bin"
- go get -u github.com/golang/lint/[email protected]
- go mod vendor
- golint -set_exit_status $(go list ./... | grep -v /vendor/)
- go test -short $(go list ./... | grep -v /vendor/)
- go build -ldflags="-s -w"
go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/project/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build122963699=/tmp/go-build -gno-record-gcc-switches"
go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/opt/atlassian/pipelines/agent/build/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build179086021=/tmp/go-build -gno-record-gcc-switches"
I have cross-posted this question to the CircleCI forum.
This issue might be related.
Setting CGO_ENABLED=0
on alpine might solve it unless it is required by your build. The line to add could be like:
export CGO_ENABLED=0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With