Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statically linked binaries in release packages #45

Closed
marvell opened this issue Jun 4, 2018 · 11 comments
Closed

Statically linked binaries in release packages #45

marvell opened this issue Jun 4, 2018 · 11 comments

Comments

@marvell
Copy link

marvell commented Jun 4, 2018

Hi there,

could you please recompile latest binaries with statically linking. Current version cannot use in alpine OS.

FROM alpine:latest

ENV MIGRATE_VERSION=3.2.0
RUN set -xe && \
	curl -Ls https://github.com/golang-migrate/migrate/releases/download/v${MIGRATE_VERSION}/migrate.linux-amd64.tar.gz | \
	tar -xz -C /usr/local/bin && \
	mv /usr/local/bin/migrate.linux-amd64 /usr/local/bin/migrate
@marvell marvell changed the title Static binaries in release packages Statically linked binaries in release packages Jun 4, 2018
@dhui
Copy link
Member

dhui commented Jun 4, 2018

Thanks for the Dockerfile to test!

Note to self: Try passing the following to go build: -ldflags '-extldflags "-static"'

@dhui
Copy link
Member

dhui commented Jun 4, 2018

Will close this issue after the next release

@marvell
Copy link
Author

marvell commented Jun 6, 2018

Thanks!

@dhui
Copy link
Member

dhui commented Jun 19, 2018

Fixed in v3.3.0

@dhui dhui closed this as completed Jun 19, 2018
@dolftax
Copy link

dolftax commented Jul 14, 2018

➜  file ~/code/bin/migrate         
/home/dolftax/code/bin/migrate: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, with debug_info, not stripped
➜  ~/code/bin/migrate -version
3.3.0

@dolftax
Copy link

dolftax commented Jul 14, 2018

@dhui Not fixed in v3.3.0 // Re-open this?

@dhui
Copy link
Member

dhui commented Jul 14, 2018

Weird, the MacOS binary is statically linked but the Linux one isn't... I don't have access to a Windows machine, so I can't verify that binary. My guess is that CGO_ENABLE needs to be set to 0.

MacOS

$ curl -sLO https://github.com/golang-migrate/migrate/releases/download/v3.3.0/migrate.darwin-amd64.tar.gz
$ tar -xzvf migrate.darwin-amd64.tar.gz
x ./migrate.darwin-amd64
$ file migrate.darwin-amd64
migrate.darwin-amd64: Mach-O 64-bit executable x86_64
$ otool -L migrate.darwin-amd64
migrate.darwin-amd64:
$

Linux

$ curl -sLO https://github.com/golang-migrate/migrate/releases/download/v3.3.0/migrate.linux-amd64.tar.gz
$ tar -xzvf migrate.linux-amd64.tar.gz
./migrate.linux-amd64
$ file migrate.linux-amd64
migrate.linux-amd64: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, with debug_info, not stripped
$ ldd migrate.linux-amd64
	linux-vdso.so.1 (0x00007ffe54f73000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fd002d65000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd002974000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fd002f84000)
$

@dhui dhui reopened this Jul 14, 2018
dhui added a commit that referenced this issue Jul 14, 2018
    - Previously, only cross-compiled binaries were built statically
    - Addresses: #45
@dhui
Copy link
Member

dhui commented Jul 14, 2018

I've confirmed that CGO_ENABLED=0 ensures that all built binaries are statically linked. This will go out in the next release.

@dolftax
Copy link

dolftax commented Jul 15, 2018

@dhui Thanks for the heads up. Could you patch it with v3.3.1 ? It is breaking in alpine environments.

If not, will build it myself and push to s3 for now and wait for v3.4.0

@dhui
Copy link
Member

dhui commented Jul 16, 2018

@jaipradeesh v3.3.1 uses static builds

MacOS

$ curl -sLO https://github.com/golang-migrate/migrate/releases/download/v3.3.1/migrate.darwin-amd64.tar.gz
$ tar -xzvf migrate.darwin-amd64.tar.gz
x ./migrate.darwin-amd64
$ file migrate.darwin-amd64
migrate.darwin-amd64: Mach-O 64-bit executable x86_64
$ otool -L migrate.darwin-amd64
migrate.darwin-amd64:
$

Linux

$ curl -sLO https://github.com/golang-migrate/migrate/releases/download/v3.3.1/migrate.linux-amd64.tar.gz
$ tar -xzvf migrate.linux-amd64.tar.gz
./migrate.linux-amd64
$ file migrate.linux-amd64
migrate.linux-amd64: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped
$ ldd migrate.linux-amd64
	not a dynamic executable
$

@dhui dhui closed this as completed Jul 16, 2018
@dolftax
Copy link

dolftax commented Jul 16, 2018

Thanks very much Dale.

FPiety0521 pushed a commit to FPiety0521/Golang-SQL that referenced this issue May 24, 2023
FPiety0521 pushed a commit to FPiety0521/Golang-SQL that referenced this issue May 24, 2023
    - Previously, only cross-compiled binaries were built statically
    - Addresses: golang-migrate/migrate#45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants