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 for v2.1 please #7

Closed
nathany opened this issue Dec 6, 2017 · 12 comments
Closed

Statically linked binaries for v2.1 please #7

nathany opened this issue Dec 6, 2017 · 12 comments

Comments

@nathany
Copy link

nathany commented Dec 6, 2017

It would be help if journey releases were distributed with binaries that could be downloaded to a server or Docker container for running migrations up or down.

There are tools like https://github.com/goreleaser/goreleaser and https://equinox.io/ to help with that.

One issue is with sqlite support [even though I'm using Postgres]

When I build journey normally and copy it into an Alpine Linux based Docker container, I get this error:

./bin/journey 
./bin/journey: No such file or directory

Though the file is there:

file bin/journey 
bin/journey: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=77826a756dd9730e121e341f3d9cd983c6456a35, not stripped

But building with CGO enabled set to zero won't work due to SQLite.

CGO_ENABLED=0 go get -u github.com/db-journey/journey
# github.com/mattn/go-sqlite3
/go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:18: undefined: SQLiteConn
/go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:26: undefined: SQLiteConn
/go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:27: undefined: namedValue
/go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:29: undefined: namedValue
/go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:35: undefined: SQLiteConn
/go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:36: undefined: namedValue
/go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:44: undefined: SQLiteConn
/go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:49: undefined: SQLiteConn
/go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:54: undefined: SQLiteStmt
/go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:63: undefined: SQLiteStmt
/go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:36: too many errors
...
@gravis
Copy link
Member

gravis commented Dec 6, 2017

Have you tried https://hub.docker.com/r/dbjourney/journey/~/dockerfile/ already?

@nathany
Copy link
Author

nathany commented Dec 7, 2017

Oh, sorry, I hadn't seen it.

It looks like there are binaries for 2.0 but not 2.1. I will need the fix from #6.

https://github.com/db-journey/journey/releases

@nathany nathany changed the title Statically linked binaries please Statically linked binaries for v2.1 please Dec 7, 2017
@nathany
Copy link
Author

nathany commented Dec 7, 2017

In the Dockerfile, should

curl -OL https://github.com/db-journey/journey/releases/download/v2.0.0/journey-linux-amd64

be

curl -OL https://github.com/db-journey/journey/releases/download/v2.0.0/journey.linux-amd64.tar.gz

I get a Not Found error with the former. Looks like the Dockerfile was written for 1.4.2 before journey was in a gz file.

@nathany
Copy link
Author

nathany commented Dec 7, 2017

Dockerfile bits for journey

FROM golang:1.8.4-alpine

# ...

RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
RUN curl -L https://github.com/db-journey/journey/releases/download/v2.0.0/journey.linux-amd64.tar.gz | tar -xz
RUN mv build/journey.linux-amd64 /bin/journey

From docker exec -it mycontainer bash:

$ bin/journey -v
Error relocating bin/journey: __vfprintf_chk: symbol not found
Error relocating bin/journey: __fprintf_chk: symbol not found
$ ldd bin/journey 
	/lib64/ld-linux-x86-64.so.2 (0x7fa86eefa000)
	libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7fa86eefa000)
	libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fa86eefa000)
Error relocating bin/journey: __vfprintf_chk: symbol not found
Error relocating bin/journey: __fprintf_chk: symbol not found

$ apk add --update file
$ file bin/journey 
bin/journey: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, stripped

"Static" binary is dynamically linked

@gravis
Copy link
Member

gravis commented Dec 8, 2017

That's unfortunately because of https://github.com/mattn/go-sqlite3 which a cgo package :(

@nathany
Copy link
Author

nathany commented Dec 11, 2017

So is there anyway to statically compile it (with sqlite)?

And if not, is there a way to exclude sqlite support in the binary?

@gravis
Copy link
Member

gravis commented Dec 12, 2017

I've tried a few things, without success so far.
The easiest way for you would be to comment out the inclusion of the sqlite3 driver in https://github.com/db-journey/journey/blob/master/main.go#L13

@nathany
Copy link
Author

nathany commented Dec 12, 2017

What about installing the sqlite library (.so) in the Docker container?

I'd rather not maintain a fork of journey with sqlite removed.

@nathany
Copy link
Author

nathany commented Dec 12, 2017

Does this issue help at all? mattn/go-sqlite3#341

@gravis
Copy link
Member

gravis commented Dec 12, 2017

If you take a look at https://travis-ci.org/db-journey/journey/jobs/313519018, you'll see that the linux binary seems to be ok.
I'll try to remove the darwin and windows ones, and see how it goes with docker hub. If I build journey locally, then the docker image, it's fine.

@gravis
Copy link
Member

gravis commented Dec 12, 2017

The image is now incredibly larger, but at least it's working (at least for me):

$ docker pull dbjourney/journey
Using default tag: latest
latest: Pulling from dbjourney/journey
723254a2c089: Pull complete
5fbe1810bf3b: Pull complete
Digest: sha256:71bc2032a516302d142f7e4fe3cb12262d73dff42dc6b920fe1a22745121f3e8
Status: Downloaded newer image for dbjourney/journey:latest

$ docker run -it --rm dbjourney/journey -h
NAME:
   journey - Migrations and cronjobs for databases

USAGE:
   journey [global options] command [command options] [arguments...]

VERSION:
   2.1.1

COMMANDS:
     migrate, m   migrate database
     schedule, s  Schedule cron jobs
     help, h      Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --url value, -u value   Driver URL [$DRIVER_URL]
   --path value, -p value  Files path (default: "./files") [$FILES_PATH]
   --help, -h              show help
   --version, -v           print the version

Can you confirm, so I can close this issue please?

@nathany
Copy link
Author

nathany commented Dec 12, 2017

Well, I guess that works, but I see you switched to a Debian base image.

So the static binary doesn't work on Alpine, unfortunately. Maybe a Postgres-only binary would be better for that case, since it looks like getting the SQLite driver to run on Alpine is a pain.

@nathany nathany closed this as completed Dec 12, 2017
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

2 participants