Follow

I blogged! πŸ“

"Shipping Rust CLIs with docker"

A guide on how you can build Rust binaries, package them in docker, and then distribute and run them as if they were "normal" CLI tools.

kevingimbel.de/blog/2020/08/sh

Β· Web Β· 2 Β· 2 Β· 2

The concepts discussed in the article are not limited to Rust.

You can do the same with or any other compiles-to-binary language.

@kevin I would say for non compile-to-binary it makes even more sense. For example Java or python where you don't want to mess up your current environment getting the right JVM version for that one little tool you want to run and not wanting to pollute your global Python installation with tons of packages.

In general I thing go or rust are very good fits for CLI tools but there are too many that are written in a imo not-so-fitting language that makes deployment painful.

@dnaka91 I agree with you 100%!

I loved Go in the past for CLI tools and nowadays I mostly use Rust, but the common problem for me is distribution. Not everybody in my team knows how to setup a binary and Homebrew has no good support for private repositories.

When I install Rust tools I usually use cargo, too.

@kevin very nice article I actually build my rust web servers the exact same way.

For CLI tools I always just install the directly with cargo as I do most of my hobby projects in rust anyways.

Just two suggestions that could be interesting to add:

- how to link in local config files. Same as you do already with volumes but maybe a nice addition.

- create a user with uid 1000 so not all created files have root ownership.

Anyways, again, nice article πŸ‘

@dnaka91 Thanks!

Great input, I'll see that I publish an updated version with the config file. I'll also check out the user creation, I usually don't care too much about users in docker tho. πŸ˜…

@kevin The user creation helps so you don't have to run chown on all files created by the docker container every time as it runs as root.

In Ubuntu:
RUN useradd me
USER me

In Alpine:
RUN addgroup -S -g 1000 me && adduser -S -G me -u 1000 me
USER me

Quite lengthy in Alpine as it creates users with UID 100 by default.

This doesn't guarantee to work every time but most machines have 1 account only and that has UID 1000 most of the time.

Not super important but I thought it's maybe interesting πŸ€”

Sign in to participate in the conversation
Mastodon

bullgit.party is a instance for everyone who is part of bullgit. πŸŽ‰