Encountering "Could not find Hex" only on a different machine

16:28:41 ==> sweet_xml 16:28:41 Could not find Hex, which is needed to build dependency :ex_doc
16:28:41 Shall I install Hex? (if running non-interactively, use “mix local.hex --force”) [Yn] ** (Mix) Could not find an SCM for dependency :ex_doc from SweetXml.Mixfile

In our environment, support team has moved building with elixir to a Docker image. This contains the prerequisite elixir and Erlang versions.

We’re not allowed to download dependencies from the internet during builds - and we actually intentionally set the proxy so we can’t download those dependencies.

For this reason the dependencies are provided locally, copied into the project, and we set the “override: true” option.

This is all fine and has worked for quite a while.

I used the new Docker image with elixir 1.14 and Erlang/OTP 25.3 to compile on my “local” machine. Everything went fine.

I have no hex installed in the Docker image nor do I have hex inside my home:

# find ~/.mix
/home/me/.mix
/home/me/.mix/archives
/home/me/.mix/rebar3.old
/home/me/.mix/rebar3
/home/me/.mix/rebar.old
/home/me/.mix/rebar
/home/me/.mix/escripts

In my build script I’m setting MIX_HOME before starting the build. This MIX_HOME also contains hex under archives/hex-2.0.6/hex-2.0.6/ebin/. The path is contained inside the Docker image where the build is run.

This builds just fine.

Now when I push the whole thing to production server for a test build, I get the errors I started the post with. In spite of it executing the same script inside the same Docker image pointing with MIX_HOME to the same path.

I’m quite confounded. As far as I can see it uses hex and everything from my MIX_HOME on one machine, but on the production server I encounter this problem. Any ideas?

Thank you.

Can you share the build scripts and dockerfiles you are using?

1 Like

I don’t think I can.

Also for the Docker image, I’m not making that myself - I’m only using what is provided to me by the infrastructure team…

If you don’t show what you are doing it will be hard to give you good help.

I am missing something here. Do you have hex installed on your system or not? If the docker image does not have hex installed and you cannot download things then you obviously won’t be be able to use hex.

Does the production server have MIX_HOME pointing to a directory with hex installed?

I am missing something here. Do you have hex installed on your system or not? If the docker image does not have hex installed and you cannot download things then you obviously won’t be be able to use hex.

Let me explain it in a less ambiguous way:

  • elixir, elixirc, erl, mix, etc are available in PATH
  • hex is not installed in the user home
  • However, the hex beam files are available in the path I’ve mentioned and MIX_HOME points to it.

Does the production server have MIX_HOME pointing to a directory with hex installed?

The build script (a shell script) does set MIX_HOME, then exports it, and then runs mix commands.

This has worked fine with the previous Docker image with elixir 1.13, and it works fine locally on my machine as well (where hex is not installed in my home, either, so it can only get it from MIX_HOME).

Does the build produce a docker image in the end or do you build a release inside the docker container and then copy it out of the container?

Does the build script runs inside the docker container?

Do you have volumes attached to the docker container or use docker cp? Otherwise it shouldn’t matter what you have on your machine since the container cannot access it.

Does the production server have hex installed in MIX_HOME? Is MIX_HOME located inside the container or outside?

Does the build produce a docker image in the end or do you build a release inside the docker container and then copy it out of the container?

The building process merely produces the deployment tarball for the elixir release. Docker is involved for providing a unified environment for running builds in with the same tool versions everywhere, so the building happens inside a Docker environment.

Do you have volumes attached to the docker container or use docker cp ? Otherwise it shouldn’t matter what you have on your machine since the container cannot access it.strong text

The path in which MIX_HOME resides it’s part of the image. The image is composed by calling docker-compose.

Volumes - I can see the home directories of users are mounted into the Docker image - so when I run locally, I can see my own home. What the “user” on the continuous production server sees… not sure.

But I could add to my software some prints - the content of the MIX_HOME variable, and maybe the output of a “find” on the MIX_HOME and on the ~/.mix to see what files they contain…

Does the production server have hex installed in MIX_HOME? Is MIX_HOME located inside the container or outside?

It is within the container and I provided all the files that were copied into that part of the image.

Try to verify that the docker image comes with hex installed where MIX_HOME, or if you mount a volume to MIX_HOME make sure that the production server has hex installed in the volume source.

Hello, ericmj.

The Docker experts at my workplace had a look, and apparently all images to be composed together have to be aligned in their version - which they weren’t. They uploaded an updated YAML to that effect and now the problem doesn’t occur on production server, either.

Thank you for all your help, I was really stumped and wondered if I had overlooked something crucial about the interplay of mix/Hex and their respective environment variables…

1 Like