Hi. I've been using asdf for about 4 months now on CircleCI. Today it started giving me this error. Is there anything that changed in asdf that could have caused this, and any suggestions to work around it?
$ asdf plugin-add erlang https://github.com/HashNuke/asdf-erlang.git
Plugin named erlang already added
asdf plugin-add erlang https://github.com/HashNuke/asdf-erlang.git returned exit code 1
Action failed: asdf plugin-add erlang https://github.com/HashNuke/asdf-erlang.git
The code that I'm running looks like this (hasn't changed):
if ! asdf | grep version; then git clone https://github.com/HashNuke/asdf.git ~/.asdf; fi
asdf plugin-add erlang https://github.com/HashNuke/asdf-erlang.git
asdf plugin-add elixir https://github.com/HashNuke/asdf-elixir.git
erlang_version=$(awk '/erlang/ { print $2 }' .tool-versions) && asdf install erlang ${erlang_version}
elixir_version=$(awk '/elixir/ { print $2 }' .tool-versions) && asdf install elixir ${elixir_version}
...
The directories that I'm caching also hasn't changed:
~/.asdf
~/.asdf/installs/elixir/1.2.6/.mix
deps
_build
I did a clean rebuild (cleared the cache) last week. Not sure if that's related.
That is strange. I have not experienced that issue. That error message you got from asdf is only printed when that directory (~/.asdf/plugins/erlang) already exists. Is there a way you can check if that directory exists? If it already exists then that is the problem. Even if the directory is empty asdf will still consider it a fully installed plugin.
Also, in you script I see you extracting versions from the .tool-versions file and then installing them. You shouldn't need to do that. Try doing something like this (untested code):
$(cd dir_with_tool_versions_file && asdf install);
Where dir_with_tool_versions_file is the directory containing the .tool-versions file you want to use. asdf will read the .tool-versions file and install everything that isn't already installed (in your case most likely Erlang and Elixir would be installed).
Thanks for the reply. I'm currently caching ~/.asdf and all the directories under it, so that probably explains why it's failing (if the cache exists). It's possible that I was using an older version of asdf for some time, which was working. I guess the solution is to not cache that entire folder from build to build, and just some specific folders under asdf?
Thanks for the .tool-versions tip.The file should already be in the current directory, so that should simplify things.
erlang 18.3
elixir 1.2.6
You could try not caching those directories, but that will slow your build down. Another disadvantage of caching is that you might be using an old version of the Erlang and Elixir plugins, though this may not be an issue, and could be a benefit if things change significantly. Assuming your fine with adding a second or two to your build time, I would probably not cache the plugin dirs and reinstall them for each build.
Okay. But it still makes sense to cache ~/.asdf/installs? Any other directories you'd recommend caching?
I'm honestly not sure. I haven't ever used asdf for CI builds before. My guess is that's probably wise (if you upgrade Erlang/Elixir versions the installs would be in different directories so the caching shouldn't interfere).
@asdf-vm/maintainers Any thoughts here? I haven't ever used asdf with caching like this. Do you guys see any pitfalls?
That's okay. I'll probably just remove all caching of the asdf stuff for now and see how it goes. Thanks for your help.
@nathany Thanks for the feedback!
Sorry, that's my bad.
I didn't think the behavior was relied on, and thought it would make more sense to exit with 1 was the plugin was not actually added.
You should definitely use your CI cache, at least for ~/.asdf/installs.
For now, could you just try something like this please?
asdf plugin-list | grep -q erlang || asdf plugin-add erlang https://github.com/HashNuke/asdf-erlang.git
@asdf-vm/maintainers Do you think it is better to exit with 0 or not when the plugin already existed? As it did not actually add the plugin, a non-zero code makes more sense to me. What do you think?
Non-zero for skipped installs makes sense to me.
@tuvistavie Thanks, I'll give it a try. Not caching the installs added 10 minutes to my test run.
It's working well. Thanks everyone.
@tuvistavie Non-zero exit for a plugin already installed is very appropriate.
Also @kdisneur's has a blog post about using asdf on CircleCI - https://kevin.disneur.me/archives/2015-06-14-elixir-on-circleci.html
I just sent a message to @kdisneur on Twitter to ask him if he could update his blog with the above check!
https://twitter.com/tuvistavie/status/745473152101191681
https://twitter.com/tuvistavie/status/745473287908536321
Thanks @tuvistavie, I forgot to update the blog post when this change was released.
Mistake fixed, should be all good now 馃憤
@kdisneur Thank you very much! :smile:
Thanks @kdisneur. For comparison, this is my current circle.yml. It's pretty similar:
machine:
environment:
PATH: "$HOME/.asdf/bin:$HOME/.asdf/shims:$PATH"
dependencies:
cache_directories:
- ~/.asdf
- deps
- _build
override:
- if ! asdf | grep version; then git clone https://github.com/HashNuke/asdf.git ~/.asdf; fi
- asdf plugin-list | grep -q erlang || asdf plugin-add erlang https://github.com/HashNuke/asdf-erlang.git
- asdf plugin-list | grep -q elixir || asdf plugin-add elixir https://github.com/HashNuke/asdf-elixir.git
- asdf install
- mix local.hex --force
- mix local.rebar --force
- mix deps.get
- mix deps.compile
test:
override:
- MIX_ENV=test mix do compile --warnings-as-errors, test --include remote
Most helpful comment
Thanks @kdisneur. For comparison, this is my current
circle.yml. It's pretty similar: