migrate icon indicating copy to clipboard operation
migrate copied to clipboard

Released binaries don't work with musl

Open 115100 opened this issue 7 years ago • 2 comments

For alpine-based Docker containers, binaries won't work without statically compiling, due to musl being the default libc:

# /usr/local/bin/migrate3
sh: /usr/local/bin/migrate3: not found
# ldd /usr/local/bin/migrate3 
        /lib64/ld-linux-x86-64.so.2 (0x55925953c000)
        libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x55925953c000)
        libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x55925953c000)
Error relocating /usr/local/bin/migrate3: __vfprintf_chk: symbol not found
Error relocating /usr/local/bin/migrate3: __fprintf_chk: symbol not found

This can be fixed by compiling without cgo enabled within Makefile, i.e.:

	cd ./cli && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o build/migrate.linux-amd64 -ldflags='-X main.Version=$(VERSION)' -tags '$(DATABASE) $(SOURCE)' .

115100 avatar Jun 05 '17 10:06 115100

I just enabled CGO because of this actually: https://github.com/mattes/migrate/pull/238#issuecomment-306112711

mattes avatar Jun 05 '17 20:06 mattes

Maybe putting -static in -ldflags ought to do it? runc does it, for example.

alecmev avatar Nov 07 '17 18:11 alecmev