Hi, I was using frolvlad/alpine-glibc
and it worked OK with my testing script, but it isn't working properly with new frolvlad/alpine-glibc:alpine-3.3_glibc-2.22
.
The test script is written in Go and tests C bindings, zlib compress and CGO (by calling getuid() with user.Current() from Go). I am not cross-compiling.
Bellow I show you how to reproduce the error:
main.go (test script)
package main
import (
"bytes"
"compress/zlib"
"fmt"
"io"
"os"
"os/user"
)
/*
char* foo(void) { return "Hello world - from the good old C"; }
*/
import "C"
func main() {
fmt.Println(C.GoString(C.foo()))
var b bytes.Buffer
w := zlib.NewWriter(&b)
w.Write([]byte("Hello world - compressed\n"))
w.Close()
r, err := zlib.NewReader(&b)
check(err)
io.Copy(os.Stdout, r)
r.Close()
user, err := user.Current()
check(err)
fmt.Printf("Olar, I am %v (%v:%v) - from Go app\n", user.Username, user.Uid, user.Gid)
}
func check(err error) {
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
Builder container (to compile Go binaries)
$ docker run -it --rm -v $(pwd):/go/src/main golang:1.5.3
root@go-container:/go# cd src/main
root@go-container:/go/src/main# ls
main.go
Build dynamic
root@go-container:/go/src/main# go build
root@go-container:/go/src/main# mv main main.simple
Build static
root@go-container:/go/src/main# go build --ldflags='-extldflags "-static"'
root@go-container:/go/src/main# mv main main.static
Prep for upx
root@go-container:/go/src/main# apt-get update
root@go-container:/go/src/main# apt-get install -y upx-ucl
root@go-container:/go/src/main# go get github.com/pwaller/goupx
Binary upx
root@go-container:/go/src/main# cp main.simple main.simple.upx
root@go-container:/go/src/main# goupx --strip-binary main.simple.upx
root@go-container:/go/src/main# cp main.static main.static.upx
root@go-container:/go/src/main# goupx --strip-binary main.static.upx
root@go-container:/go/src/main# ls -l
-rw-r--r-- 1 root root 603 Feb 14 23:52 main.go
-rwxr-xr-x 1 root root 2885624 Feb 14 23:52 main.simple*
-rwxr-xr-x 1 root root 611192 Feb 14 23:59 main.simple.upx*
-rwxr-xr-x 1 root root 3974304 Feb 14 23:53 main.static*
-rwxr-xr-x 1 root root 935388 Feb 14 23:59 main.static.upx*
Test frolvlad/alpine-glibc (works OK)
$ for x in main.s*; do echo "- $x"; docker run -it --rm -v $(pwd):/go/src/main frolvlad/alpine-glibc /go/src/main/$x; echo; done
main.simple
Hello world - from the good old C
Hello world - compressed
Olar, I am root (0:0) - from Go app
main.simple.upx
Hello world - from the good old C
Hello world - compressed
Olar, I am root (0:0) - from Go app
main.static
Hello world - from the good old C
Hello world - compressed
Olar, I am root (0:0) - from Go app
main.static.upx
Hello world - from the good old C
Hello world - compressed
Olar, I am root (0:0) - from Go app
Test frolvlad/alpine-glibc:alpine-3.3_glibc-2.22 (is failing for some binaries)
$ for x in main.s*; do echo "- $x"; docker run -it --rm -v $(pwd):/go/src/main frolvlad/alpine-glibc:alpine-3.3_glibc-2.22 /go/src/main/$x; echo; done
main.simple
Hello world - from the good old C
Hello world - compressed
Olar, I am root (0:0) - from Go app
main.simple.upx
Hello world - from the good old C
Hello world - compressed
Olar, I am root (0:0) - from Go app
main.static
Hello world - from the good old C
Hello world - compressed
user: lookup userid 0: no such file or directory
main.static.upx
Hello world - from the good old C
Hello world - compressed
user: lookup userid 0: no such file or directory
I would like to still building my code with --ldflags='-extldflags "-static"'
to make tottaly static binaries. Why this approach generates erros only in the frolvlad/alpine-glibc:alpine-3.3_glibc-2.22
image?