krotik / eliasdb

EliasDB a graph-based database.
Mozilla Public License 2.0
993 stars 49 forks source link

Thoughts about OSX support & "common" dependencies #37

Open oderwat opened 3 years ago

oderwat commented 3 years ago

I wonder what the status is on OSX support?

As an OSX user, I found that the eliasdb console won't work because of the missing implementation of parts of getch in the termutil package of the common module. So I quickly cloned that repository, used a replace statement in the go.mod file, and implemented a very minimal and unfinished Darwin version to play around a bit (not really worth a PR so far).

Next, in my journey, I found that the datamining-example copies over the eliasdb executable into the docker image. I also changed the build script to use a cross compiled version (this could be a small PR).

All in all, I could run all examples on my Mac (strafing in asteroids is cool), and I am thinking about the possibilities for using EliasDB for some projects.

But I read somewhere that ElisaDB was created from scratch using "no dependencies" but the gorilla/websocket. This is true if one does not count for the pretty large dependency on all of those packages below https://devt.de/krotik/common.

While those packages are really cool, they form a substantial part of EliasDB, and this is "just a private gogs server" where all of this is located. This will render the whole EliasDB useless for anybody using it if that repository vanishes. Wouldn't it be better to include the used parts as internal packages or add the whole "common" repo to GitHub?

mladkau commented 3 years ago

Hey there, thank you for raising this (and the PR) :pray: - To your points:

oderwat commented 3 years ago

Hey :) We may create some more OSX stuff in the future. To be honest: I love what EliasDB has to offer. It would be very cool to have this working for larger projects too.

oderwat commented 3 years ago

Additional information:

I researched how to actually cross-compile for the alpine Linux musl lib and ended up with this:

#!/bin/sh
cd "$(dirname "$0")"
export ROOT_PATH=`pwd`

# Build the collector component

CC=$(which musl-gcc) go build --ldflags '-w -linkmode external -extldflags "-static"' ../../../../cli/eliasdb.go
docker build --no-cache --build-arg cluster_id=1 --tag data-mining/eliasdb1 .
docker build --build-arg cluster_id=2 --tag data-mining/eliasdb2 .
docker build --build-arg cluster_id=3 --tag data-mining/eliasdb3 .

# Run an interactive shell on the build image with:
# docker run -it data-mining/eliasdb sh

To make this work on Debian, one needs to install musl-tools (apt-get install musl-tools) which installs musl-gcc.

Nearly the same can be done on Mac by using:

brew install FiloSottile/musl-cross/musl-cross

and creating a softlink

ln -s $(brew --PREFIX)/opt/musl-cross/bin/x86_64-linux-musl-gcc $(brew --PREFIX)/bin/musl-gcc (should work on Intel and Apple Silicon homebrew installations)

Or just using the x86_64-linux-musl-gcc instead of musl-gcc in the build.sh. One could extend the build.sh to check for those.

With this knowledge, I actually wonder what happens when not using musl-gcc on OSX, as the result of the "normal" cross-compile will work on alpine, while the Debian-based build executable was not. It seems that Go compiles on OSX statically against something "else" than glibc.

I also wonder why your Docker works on Linux. Which Linux distribution did you use for testing?

P.S.: The Linux binary with the musl lib should be statically linked and work on every Linux, glibc or musl or whatever.

Resources used:

krotik commented 3 years ago

I am using Linux Mint (20.1) - I think it works on Linux for me because the default Makefile sets: export CGO_ENABLED=0 🤔

oderwat commented 3 years ago

Oh yes. I see. I followed:

You can build EliasDB's executable with:
go build cli/eliasdb.go

I didn't even saw the Makefile till now. And I can confirm that it works in Debian when EliasDB was build through the Makefile. Well. Learned something... as usual :)

And (back on the Mac) of course, you can't use the Makefile on the Mac. I think I could extend the PR at the weekend and add stuff so it builds/examples on Mac and Linux. What do you think?

oderwat commented 3 years ago

Well.. https://devt.de/ is down right now while I am talking to a colleague about using eliasdb for something in production.

krotik commented 3 years ago

I though about your point about using github.com and I changed my mind. Since I already mirror eliasdb and ecal on github I could also go all the way and also mirror common. I've linked up all the code on github and there should be now no more code dependencies to devt.de on github (some of the documentation links stay however, e.g. build results).

krotik commented 3 years ago

I am not sure I follow with "can't use the Makefile on the Mac". Re: building the examples - I would still like to aim for not having to build examples so the binary distributions can include examples which do not require a go build environment. I wonder if the data-mining example could use the image on DockerHub https://hub.docker.com/r/krotik/eliasdb which is a scratch image ...

oderwat commented 3 years ago

I think we may have just different ideas about how stuff "should" work. I expected running make to build a working executable for my system. As is, it builds a Linux executable. But then this works for building the examples ;-)

About the examples themselves: I think it depends if they are "examples of how to build something" or "showcases". For me, an example should let me create everything from scratch. Even the front end. Using the DockerHub image may help to demo them. For letting people use them as the basis for experiments, it may be better to make the build process and documentation "foolproof" when using different systems.

I think I would change the Makefile so that it detects the system and also creates the right executable for the demos. Probably even build/run everything from there and ditch the individual scripts (or call them from the Makefile).

But this is a lot of work and hard to do if you don't have all the target systems for testing. As I said, we may do some work in that direction, but we are still evaluating if we want to use EliasDB in production.