Asdf – language tool version manager
asdf-vm.com
asdf-vm.com
I also hate the Docker tagline that it "eliminates 'works on my machine' issues". I believe a tool like asdf would also achieve this (correct me if I'm wrong). Docker itself can go haywire depending on the machine and you're basically in hell fighting with it just to get your dev environment working. You essentially eliminate one problem in exchange for a variety of equally frustrating challenges.
This is true for very simple applications, where you’re just running `npm ci` or `pip install`, but breaks down as soon as you have sophisticated dependencies with system / library requirements or dependencies (e.g. databases, caches, message brokers, queues) that are beyond the scope of asdf.
Also, since you’re probably deploying containers to production, it’s useful to have a similar environment for local development so that you know what will actually happen in production.
Citation needed I feel - I’d wager the number of containerized deployments pales in comparison to the number of binaries scp’d into a production host.
I said “probably” because the vast majority of deployments I’ve done over the past decade have been containerized, but I have no trouble believing that my experience isn’t indicative of the average.
Docker is NOT about local dev, it's about deployment.
We forgot this...
I mean... if Vagrant can be about local development, I don't see why Docker can't be about local development too.
Do you want to quickly debug some software that relies on an older version of Postgres 9 but you don't want to clutter your host machine? Just run the following command to fetch and start an instance. With --rm flag it's going to be removed as soon as you terminate it:
docker run --rm -p 5432:5432 postgres:9
But that was never the primary purpose of Docker. Like I can use Mac Minis as door stops, etc.
Docker runs best on top of Linux. As in actually run a Linux host , everything else in my experience is a hack. As long as you have internet access, spinning up an ec2 instance to test stuff shouldn't be too hard.
This such a complete and utter lie and I'm surprised people in 2022 still believe it.
You do know what's happening when you run Docker on your Macbook, right? Right?
I used Docker to run the application using the exact same image that was deployed to production, and was able to replicate the issue.
Why? Because the PDF renderer depended on loads of finicky dependencies (e.g. linked libraries), and it turns out that the default fonts in our base image didn’t support the Unicode code points in the example payload. I couldn’t replicate this outside of Docker because I have a completely different set of linked libraries and don’t stack.
Happy to answer any questions you have.
the other post mentioned setup, so i thought he meant they imposed presetup containers for developers to use?
A Linux vm spawns a process with new namespaces - which is often exactly what happens in production as well.
There are two possibilities - a) you are right, you know something your company doesn't, and by proposing your new plan in a constructive manner you might make life better for everyone b) you are wrong, you don't fully comprehend the surface area of the software you are working on, and your suggestion is short sighted and doesn't account for all of the requirements.
Either way it is helpful to put it out there - so long as you do it from the right place, with the right intention. Either you'll humble yourself, or you will eliminate an unnecessary dependency and make life easier for your team.
But countless developers in countless companies have each their own set of frustrations where they sense that something could be improved but don't know what to do with the frustration.
Frustrations are a useful symptom but learned helplessness is a terrible thing that can lead to anything from being annoyed to leaving your job to depression.
I would argue that the response was in fact a very valuable lesson.
In the "big 'ol" companies I worked at, something like that takes months! If even possible...
It is totally valid to point out failures in something without knowing how to put them right, or being in a position to do so.
Complaining for complaining is not helpful, but don't dismiss problems because no one can think of a better solution at the same time.
It is NOT great for having a live-reloading dev webservice running. People seem to swing for an all in one solution, but consideration is needed about what services you want in docker or not. Docker is great to have preconfigured database environments that are easy to tear down and start from scratch and works across multiple platforms. Docker is bad for local dev server.
Oh my god this.
I was running a fastapi server on my m1 Mac in an arm Linux docker container. Everything else works great in this, but the live-reloading server was running at 200% cpu and ate 50% of my battery life!
- docker is good when the deployed software runs on docker too, because dev and prod are the same and on Linux the performance hit is negligible if any. If you're on Mac or Windows it seems that it can be felt.
- docker is a good way to distribute the development environment, anecdotally much better than Vagrant or bare VMs.
- However having to always prefix commands with docker exec container is a little pain. Working in docker exec container bash is worse.
- Sharing only volumes between the host file system and docker means that sometimes I have to copy files to the shared volume instead of addressing them where they are.
- asdf doesn't have all those problems but I must be careful to pick different ports for different postgresql servers in different projects. Docker would shield those ports inside the network of the project.
All considered, I use docker when a customer uses docker, VMs when a customer uses VMs, asdf for all the other cases including my own software which I never deployed to docker so far. If I did I'd probably work in docker because I don't want surprises at deployment time.
I’m not saying this is the right way but this is very common. I also agree with the rest of your points.
docker-compose build
docker-compose run --rm api bundle
docker-compose up
api is the name of the service in docker-compose.ymlOne developer has a M1 Mac and he's using something called mutagen instead of docker. His docker-compose.yml is a little different and he's paying a performance penalty. His M1 is only 50% faster than my Intel from 2014 at running the test suite (50 seconds vs 75.) The difference is not noticeable when running only a few tests per time when working on a single feature.
docker compose
not docker-compose
The latter was the name of the compose v1 binary, so using it may cause your command to be handled with a v1-to-v2 compatibility mode. Depends on how your installation is setup. Compose v2 is implemented as a Docker CLI plugin. The new 'docker compose' command is currently experimental.On a workstation level, people who really know their way around stuff tend to dislike docker in my experience, and for people who don't its still too difficult. One problem I think it has is that docker - still talking about workstations here - solves mostly problems on the team level, not on an individual level. But individuals tend to regard those problems as 'other peoples problems'.
Another problem is that you can work with docker just fine with barely knowing how it works, until there's a problem. In my experience, developers tend to immediately blame docker for the problem, even though its a misconfiguration of npm for example, which they would also have in a native installation.
Still, docker solves a lot of problems that aren't solved by asdf, apt or rpm, which is why it continues to be relevant and used also for workstations.
EDIT: docker on windows before wsl2 was hell too, a lot of discontent about docker that people have comes from those installs. On wsl2 it's mostly fine, if you don't attempt to mount from an ntfs file system.
Docker basically just takes a snapshot, which hides the problem rather than fixing it: when we want to change something, like updating a dependency, we're back to the same dependency hell.
Even worse, those snapshots are often not reproducible (e.g. running things like `apt-get install -y foo`, which depends on the latest contents of third-party servers). Again, Docker tries to hide the problem by putting snapshots into a cache.
To avoid these problems, we need the discipline to do sensible things (e.g. using specific .deb packages, rather than apt-getting whatever's latest; or using something more brute-force like Nix). Yet once we do that, there's usually no point doing it with Docker at all; since those commands work perfectly well outside of a container (if we want a container to deploy, we can tar up the resulting directory)
I hope you don't COPY your entire system into the container at least.
I can't recall ever encountering such a thing myself. On the other hand, I've seen LOTS of this sort of thing:
RUN apt-get update && \
apt-get -y install apache2
The above is taken from official AWS documentation[1] but it's pretty rampant.As I mentioned above, when the instructions are reproducible, there's no point using Docker to run them; a shell script would suffice.
[1] https://docs.aws.amazon.com/AmazonECS/latest/developerguide/...
That's not reproducible in the sense of "reproducible software", but it is usually good enough to build other things on top of.
If you want reproducible in the sense of unchaging/same digest, you should make a custom base image with the things you never want to change and pull it from somewhere.
For example, asdf can install tools on a developer's system. asdf can route invocations to the appropriate version of an installed tool.
Docker can be used to install tools in isolation by way of an image build. That image can be shipped off, so that developers can pull the image, and do not have to run an installation procedure. Docker can pull and run the appropriate version on demand upon invocation.
It's also not a binary choice. You can use asdf in a Docker container, and you could use Docker in an asdf plugin.
Having the ecosystem of asdf plugins which are basically just shell scripts has been a huge boon. It's been a breeze to work with, and most of the plugins are well written.
Now, I've been contemplating switching to NixOS, but most version managers don't work at all with it due to dynamic linking. I absolutely love the idea of NixOS, but this has really bummed me out. I feel like the nix language is still a little clunky for general use, so as long as there is not a straightforward solution like having a tool-versions file I'm really hesitant to make the full switch.
However, it's surprising to hear that they've been focusing on UX. The fact that you have to manually install a plugin, then install a version, and then finally set it, without the tool suggesting any of those steps to you when you forgot one, really makes the tool annoying to use when switching versions a lot.
As a proof of concept I wrote a Fish native version of the function that figures out what local version of a tool to use I do actually use it to show the currently selected version in my shell prompt. The asdf version was unusable in a shell prompt.
It goes through the parent directory structure up until the top level root directory and finds the first .tool-versions file and parses out the version of a specific tool.
The asdf native shim takes ~100 ms in Bash (no idea if it can be optimized, but I assume so). My Fish version takes ~1 ms.
As an example I use fnm (https://github.com/Schniz/fnm) for managing JavaScript versions. It runs so fast (compared to nvm) I'm inclined to think something went wrong and it silently failed, but it never does!
Does qwer support per-directory, local versions of plugins? I'm finding that that's difficult to do without shims...
I think though it is more complex because it is a programming language that provides this functionality instead of purpose build tool like asdf.
For my needs I created a framework for development: https://github.com/takeda/nix-cde to avoid cruft of including the same things over and over in my projects.
I migrated to asdf from nvm because of nvm's very slow startup time. I haven't noticed excessive startup time on asdf yet. I wonder what's the issue with your asdf installation.
Nix is a package manager (like apt or whatever), and like package managers, it works with a set of vetted, decently verified package versions (NixOS releases). Mostly this is fine. It’s easy to use nix stable for most stuff and nix-unstable for anything where you need newer stuff. You can then configure “overlays” to the set of packages where you specify how to build particular versions where you need it.
It took me a long time to make the mental shift from nix being something like pip or npm or asdf or pyenv or whatever to thinking of it like a true linux distribution’s package manager, but it helped everything to click once I did
Does asdf come with a plugin for asdf & quicklisp? would've preferred for the new guy on the block pay respect to the old guy on the block and used a different name..
asdf for common lisp been around for years and used by the clergy of programming basically and still widely used today
asdf global python systemMostly by reusing existing version managers, which have been developed and optimised over the years. Asdf itself is a relatively thin wrapper really.
The only exception I can think of is any dependencies on libraries that may or may not be installed by the system package manager. Even then, those dependencies are often optional.
alias aoeu='asdf'
Seems like a reasonable shortcut compared to trying to do keyboard layout detection.The low barrier to entry is also a bit of a curse too. The quality of asdf tool scripts varies wildly. Anything not maintained by their core org is a crapshoot in my experience. Many of those smaller tools don't support ARM or have lots of undocumented dependencies or quirks.
Asdf can automatically install tool chain versions based on a plain text file stored in your repository, so it’s pretty plug and play too.
[0] https://www.docker.com/blog/speed-boost-achievement-unlocked...
Switching back and forth between branches with .tool-versions seamlessly switches to the correct version of the language and it “just works”. Trying to accomplish the same purely via docker is slow and painful.
https://tfswitch.warrensbox.com/
Even then some versions of terraform providers are not compatible with M1 macs. Docker would help with that probably, but so can: https://github.com/kreuzwerker/m1-terraform-provider-helper
Perhaps these sort of issues support the benefits of per-module docker images?
Okay, a worthy target.
> No messing around
I will list layers that I guess you are using:
docker client binary
a command to run the thing <---
user-specific docker configuration
docker daemon as root
system-specific dockerd configuration
Dockerfile
embedded in it, a small shell script to download Terraform binary <---
files scattered on /var/lib/docker/* which never require cleanup
dns implementation
virtual bridge and other kernel-ish entities
tcp proxy
a running Terraform binary <---
I marked the layers that, in my opinion, would be enough to achieve the same goal. The explanation is that terraform is a self-contained binary that is not trying to scan system-wide or homedir-wide for files that can and will break it into dozen pieces. It is confined to the repo.
Sadly, reuses the name of a completely unrelated common lisp tool.
There was a discussion about asdf before[1] with a blog post[2] about someone's shift to using asdf which may help, it's pretty straight to the point.
[1] https://news.ycombinator.com/item?id=30917354
[2] https://jinyuz.dev/2020/07/switching-from-pyenv-rbenv-goenv-...
> Once asdf core is set up with your Shell configuration, plugins are installed to manage particular tools. When a tool is installed by a plugin, the executables that are installed have shims created for each of them. When you try and run one of these executables, the shim is run instead, allowing asdf to identify which version of the tool is set in .tool-versions and execute that version.
There is a hyperlink on word shims to the Wikipedia article https://en.wikipedia.org/wiki/Shim_(computing) that explains the generic concept of shims. Not helpful.Edit: here it is: https://github.com/asdf-vm/asdf/blob/v0.10.2/asdf.sh#L30-L31
This is often the case when the software you are writing is a web application that has one intended production deployment target, rather than a library or even a shrink-wrapped product that might need to work in diverse installations.
If you just have one of these projects, you can just install the dependency in user-space and update your user's startup files to point to it and be happy. But if you have two or more, or the version changes often (hopefully it does, so you can scoop up security and other updates), then a version manager helps with the toil of swapping back and forth.
Like many of its predecessors, asdf not only gives you a set of commands to swap these versions on demand, but it also creates "shims" to automate this swapping behavior when you enter and exit directories with an appropriate configuration file.
The "killer feature" of asdf (versus rbenv, pyenv, phpenv etc.) is that it is an extendable toolkit that gives you the same tools for dozens, maybe hundreds of different plugins contributed by the community. It is a polyglot web programmer's friend.
My team maintains multiple projects that are over 10 years old with a mix of Ruby on Rails and JavaScript. The code base is large, so there is pretty much a guarantee that going to the next version of Ruby or Ruby on Rails or Node will introduce problems. We lock down all the versions for everything so that we don't have to worry a deploying to a new environment (new server, developer, etc) will have different versions and require use to change priority to fix things. Instead, we periodically review our projects for upgrades, find upgrade issues and fix them, lock new versions, and deploy. Some of the code base is in legacy status. It does what it needs to do, and we have no need to change it unless some security issue is found.
Web interface: https://tldr.ostera.io/asdf
Other clients (ways to access it): https://github.com/tldr-pages/tldr/wiki/tldr-pages-clients
Works great in itself, however, PostgreSQL version upgrade is quite hustle. It's plug-in area, though could have some protocol with the core to make it seamless. I didn't upgrade my postgres for a while (on 12.4 right now).
Not sure if it still requires you to do:
`POSTGRES_EXTRA_CONFIGURE_OPTIONS=--with-openssl LDFLAGS="-L/usr/local/opt/openssl/lib" CPPFLAGS="-I/usr/local/opt/openssl/include" asdf install postgres x.x`
And run `pg_upgrade` yourself moving data from previous version to the new one's directory.
Seriously through, it's pretty easy to create an asdf plugin, and it works great. But it would be great if there were a static executable to handle it all.
A couple projects out there come close, but need people to contribute code to finish the most useful functionality. One example is https://github.com/marcosnils/bin - the developer is fully in favor of improvements and added features, but needs someone with the free time to add them.
Sadly this is not available in windows so i had to use WSL to run everything. Development in windows is so wonky once you switched from unix based system
Use a flake.nix
So yeah, there's https://github.com/bobvanderlinden/nixpkgs-ruby and others - but you have to find them yourself. (until someone makes a flake to integrate them all, I guess?)
I don't think mentioning Nix is meant to be sarcastic - this is a function the package manager has built-in by default, so it is worth mentioning.
For example, I cross-compile rust code to arm64, build websites, and deploy the whole infrastructure to AWS including the said rust code as AWS lambdas from a single nix derivation. The cross-compiling toolchains, etc take time to build, but then they are cached and only stuff that gets rebuild are the actual stuff I'm developing / changing. This is the backbone of nix really. You may not think this is not that amazing though, but nix is from ground-up built so that it's very difficult to write anything impure, anything that can't be cached or does not cache properly.
For my work, I've written shell.nix for every project I'm developing. This means my own personal environment stays clean, but for projects I always have the environment I need up in seconds. And if I start running out of space, I can just run nix-collect-garbage and forget about it. This is especially useful for me, as I do contract work and don't use the work PC just for one company.
I haven't actually yet used NixOS, but if I ever have to spin up new servers, I'm considering it.. I have ryzen machine that I use for gaming and sometimes building larger stuff... and I'm feeling like I want to migrate that to NixOS.. maybe someday .. :)
Also if you are an mac user, you really should do yourself a favor and switch away from homebrew
That being said, the task of debugging a deprecated tool version in asdf just one time makes the investment in the nix awkwardness worth it.
the pitch for nix isn't that it's a nicer tool than, e.g. `asdf`, but rather, that it will probably work in five years. frightful flashbacks of of trying to get nokogiri to build.
Machine learning people usually use anaconda which is all sorts of mess... But honestly yeah, I think it's worthwhile to invest learning nix for simply guaranteeing your environment still works for years to come and isn't affected by side-effects (some thing outside of your environment description actually is causing the whole thing to work, or some thing outside the environment is making the thing not work).
Convert all data / markup to s-expressions
Make all code lambda calculus in some paren form
No more "xml being manipulated by a scheme designed to look like imperative language" (javacript manipulating the DOM)
Thank you have a nice day.
Though asdf itself is language-agnostic, is it in practice used more for web-development or something?
My boss loves ASDF and I liked the idea but I tried to use it three times and failed
asdf which node
/Users/jmfayard/.asdf/installs/nodejs/19.0.0/bin/node
which node
/Users/jmfayard/.asdf/shims/node
node --version
v19.0.0
asdf local nodejs 16.18.0
node --version
v16.18.0
I probably had read the documentation in the wrong order.
Thanks for your message!I think the main thing is just having consistent documentation, especially for global settings.
But other than that it definitely "works" on MacOS; can't comment on fish, I use zsh.
EDIT: Besides being only for JS.
clone the terraform source repo
~ git remote -v
origin https://github.com/hashicorp/terraform.git (fetch)
origin https://github.com/hashicorp/terraform.git (push)
check out the tag you want ~ git tag | tail -1
v1.1.5
~ git checkout v1.1.5
Previous HEAD position was 516295951 Release v1.1.4
HEAD is now at fe2ddc22a Release v1.1.5
compile/install the binary in a local bin dirctory, ~ go build
go: downloading github.com/aws/aws-sdk-go v1.42.35
~ install terraform ~/bin/terraform-v1.1.5
~ ls ~/bin/terraform\*
/home/matt/bin/terraform /home/matt/bin/terraform-v0.13.7 /home/matt/bin/terraform-v1.1.4
/home/matt/bin/terraform-v0.13.4 /home/matt/bin/terraform-v0.14.9 /home/matt/bin/terraform-v1.1.5
then manage a series of brittle aliases to disptach the proper version? ~ which terraform
terraform () {
binary=terraform
if [[ $1 == "v"\* ]] && [[ $1 != "validate" ]]
then
version=$1
shift
binary="$binary-$version"
[ -f ~/bin/$binary ] || bail 1 "missing binary $binary" || return 1
else
binary=/usr/bin/$binary
fi
dispatch --name terraform --scope --slice compilers.slice -c 35 -mh 2048M -mm 2048M -s 1M --binary $binary
"$@"
}
(dispatch just runs things with memory and cpu limits) ~ which dispatch
dispatch () {
if [[ $USER == "root" ]]
then
command "$binary" "$@"
return $?
fi
declare args=(--user --same-dir -p IOAccounting=yes -p MemoryAccounting=yes -p TasksAccounting=yes)
while (($#))
do
case "$1" in
(-c) args+="-p"
args+="CPUWeight=$2"
shift 2 ;;
(-mm) args+="-p"
args+="MemoryMax=$2"
shift 2 ;;
(-mh) args+="-p"
args+="MemoryHigh=$2"
shift 2 ;;
(-s) args+="-p"
args+="MemorySwapMax=$2"
shift 2 ;;
(--scope) args+=--scope
shift ;;
(--slice) args+="--slice=$2"
shift 2 ;;
(--name) name=$1
shift 2 ;;
(-P) args+=-P
shift ;;
(--binary) [ -z "$name" ] || name=$2
binary="$2"
shift ;;
(*) break ;;
esac
done
systemd-run $args "$@" 2> >(>&2 grep -vE 'Running.*as unit:')
}
and of course, then you'd need a shitty little script to call your alias when other tools decide they want to call terraform ~ cat ~/bin/terraform
#!/usr/bin/env zsh
source ~/.zshrc >/dev/null 2>/dev/null || exit 1
terraform $@
Because that would be silly and dumb, and I totally don't do that for everything.Don't even get me started on virtualenvs.
Ok there's criticism as well: why do you need an alias and a script that calls that alias? Get rid of the alias, just paste it into a script then?