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

Arm64 Docker support #1770

Merged
merged 3 commits into from
May 24, 2023
Merged

Arm64 Docker support #1770

merged 3 commits into from
May 24, 2023

Conversation

h4l
Copy link
Contributor

@h4l h4l commented May 10, 2023

This resolves #1517.

I was trying to use mythril in a vscode devcontainer environment on an ARM Mac. It turned out to be quite a challenge to install mythril because many of your dependencies don't provide arm64 binaries, and some don't publish recent source releases to build from (blake2b).

I also found that your Docker image is only built for amd64, so I tried to build it on arm64 locally, and found it couldn't build for arm64. So set about adjusting the image so that I could use it. Now that I've got a working arm64 image, I figured I should offer the changes back. Hopefully it might make life easier for other people on ARM systems!

I've configured the build with a Docker Buildx bake file, so you can build the mythril/myth image for amd64 and arm64 simultaneously like this:

$ docker buildx bake

When you're not doing a CI build, it probably makes more sense to just build the image for your platform, which you can do like this:

$ docker buildx bake --set='*.platform=linux/arm64'
# or
$ docker buildx bake --set='*.platform=linux/amd64'

(Also, running with --print is useful to understand what bake is going to do, it'll print out the configuration that would be built without actually building.)

The image should be functionally the same as the previous version, but there are a few changes.

  • The base image is now python:3.10-slim rather than ubuntu:focal.

  • It's smaller now, ~400M arm64 / 500M amd64 vs 1.3G before. This is partly because the base image is a lot smaller, and partly because it's now a multi-stage build that builds wheels in separate stages and copies them into the final stage, so there aren't any dev dependencies/files in the image now.

  • It uses svm to download solc versions, both at image build time and in the image entrypoint. This is because the solcx Python package doesn't provide arm64 solc binaries. svm does, and it's also used by foundry.

    This doesn't seem ideal, but hopefully it's a reasonable starting point.

  • The image runs as the mythril user rather than root by default. It can still be run as root using the --user docker option. This has the potential surface file permission problems for users bind-mounting directories into a myth container that aren't readable by uid 1000.

I also updated docker_build_and_deploy.sh to build & publish using buildx bake, as shown above. It's possible that your circleci environment will need a tweak. I don't use circleci myself, but they seem to support Docker Buildx: https://support.circleci.com/hc/en-us/articles/360058095471-How-To-Use-Docker-Buildx-in-Remote-Docker-

h4l added 2 commits May 10, 2023 11:10
The mythril/myth image now builds for linux/arm64 as well as
linux/amd64. To achieve this, we now use docker buildx to build the
images and handle create a multi-platform image manifest. The build
config is defined in a buildx bake file.

By default it'll build both platforms at once, but you can build just
one by overriding the platform on the command line:

    $ docker buildx bake --set='*.platform=linux/arm64'

The solcx Python package doesn't support downloading solc for arm64, so
the image now includes the svm command-line tool, which does. (svm is
used by foundry to provide solc versions.) Integration with solcx is
not automatic, so currently the image's docker-entrypoint.sh handles
symlinking solc versions from svm into solcx's directory.

In addition to supporting arm64, the image is now quite a bit smaller.
~400M vs 1.3G before.
@CLAassistant
Copy link

CLAassistant commented May 10, 2023

CLA assistant check
All committers have signed the CLA.

When installing wheels in the Docker image, we previously used an ugly
hack to force pip to install the z3-solver wheel, despite it having
invalid platform metadata. Instead of bodging pip install in this way,
we now fix the z3-solver wheel's metadata after building it, using
`auditwheel addtag` to infer and apply compatible platform metadata,
which allows pip to install the wheel normally.
Copy link
Collaborator

@norhh norhh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR

@norhh norhh merged commit 7dcefb5 into Consensys:develop May 24, 2023
@h4l
Copy link
Contributor Author

h4l commented May 24, 2023

No problem, thanks for merging! If you have trouble with building the arm64 version, let me know, as I was experimenting with cross-compiling to avoid needing to emulate arm64 from amd64. I've got a version that can build on GitHub Actions which only has amd64 runners.

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

Successfully merging this pull request may close these issues.

Add support for arm64 images
3 participants