cartesi / machine-emulator-tools

Set of tools to help the development
Apache License 2.0
13 stars 20 forks source link

Add way to check tools version installed from inside the machine and outside #56

Closed diegonehab closed 5 months ago

diegonehab commented 6 months ago

Context

It seems as though many users have trouble following upgrade instructions and end up with a version of tools installed that is not compatible with either the emulator or the kernel.

It would be much better if there was a way for us to check if the tools are installed in a rootfs and to check what version was installed, both from inside the machine and from the outside.

Possible solutions

The trivial solution to this problem is to create a file containing the version and install it along with the other files in tools. That way, you could simply, say, cat the contents of /etc/cartesi/tools-version or some such. Even from the outside, you could use e2cp rootfs.ext2:/etc/cartesi/tools-version -, or even e2cp template/0080000000000000-6400000.bin:/etc/cartesi/tools-version - if template is a stored machine template and 0080000000000000-6400000.bin is the memory range where it keeps the root filesystem.

mpolitzer commented 6 months ago

We can get the tools version from the apt database of a running machine with:

$ apt show machine-emulator-tools | awk '/Version/ {print $2}'
0.15.0
diegonehab commented 6 months ago

Does this work from the outside? I think for @tuler it would be best if it did. This is because you may not be able to boot a machine at all with a given rootfs.

mpolitzer commented 6 months ago

I'm sure the contents are there somewhere, but may be compressed in the apt database.

The upside of this method, or something equivalent like consulting apt databases directly, is that we can check for other packages as well, such as busybox. This gives an idea if the image was setup properly.

diegonehab commented 6 months ago

The idea is to make this easy on the outside. I think just adding a file there would be fine, right?

mpolitzer commented 6 months ago

A file with version works but is non standard, breaks the single source of truth concept and won't work for other packages such as busybox.

The incantation to fetch it from the debian database is not that bad, check it out.

T=$(mktemp)
e2cp rootfs.ext2:/var/lib/apt/lists/deb.debian.org_debian_dists_bookworm_main_binary-amd64_Packages.lz4 $T
lz4 $T - |\
  sed -n '/Package: machine-emulator-tools/,/^$/p' |\
  awk '/Version:/ {print $2}'
rm $T
edubart commented 6 months ago

I think doesn't hurt to have a simple file somewhere with the tools version, to make easy to inspect from outside. Also more fail proof for the day we start having tools available in distributions that aren't .deb based (Alpine for example).

mpolitzer commented 6 months ago

I think doesn't hurt to have a simple file somewhere with the tools version, to make easy to inspect from outside. Also more fail proof for the day we start having tools available in distributions that aren't .deb based (Alpine for example).

We'll have a lot of other changes when that happens. But ok, it is not a big deal.

diegonehab commented 6 months ago

I understand it is possible to squeeze the information out of the rootfs. :) But I can't go back to our clients with this as a solution. Since we will need to release a new version of tools with the new rollup-http-server soon, I'd like for it to include a file at a standard place with a standard name and containing the version. Pretty please?

diegonehab commented 6 months ago

To be clear, this is our fig leaf so our clients don't come up with something a lot more creative. It will allow the cartesi cli to diagnose a very common compatibility problem between the cartesi machine and the rootfs and print a nice error message rather than a kernel panic of some such.

mpolitzer commented 5 months ago

@tuler Can you give an OK if this commit solves the issue for you? https://github.com/cartesi/machine-emulator-tools/pull/57/commits/c0b4a68d578b030ed8696d66844b1769d9eb3419

To retrieve the tools version from a ext2 file, do the following (mktemp is optional):

$ T=$(mktemp)
$ e2cp rootfs.ext2:/usr/share/machine-emulator-tools/package.json $T
$ jq '.["version"]' < $T
"0.15.0"
$ rm $T