mattes / migrate

Database migrations. CLI and Golang library.
Other
2.29k stars 326 forks source link

Released binaries don't work with musl #241

Open 115100 opened 7 years ago

115100 commented 7 years ago

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)' .
mattes commented 7 years ago

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

alecmev commented 6 years ago

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