Dzero Labs
Published in

Dzero Labs

Using Docker Images to Distribute Platform-Independent Application Packages

Toronto streetcar at dusk at Avenue Road & St. Clair Avenue. Photo credit: Dzero Labs

This past week, as I continued my quest for ArgoCD domination, I decided to look more deeply into different technologies to deploy manifests to Kubernetes. Among others, ArgoCD supports the popular kids, Kustomize and Helm. I had actually initially settled on a combo of Helm + Kustomize, which can be done with ArgoCD. (If you’re wondering how it’s done, check out my post here) I was pretty happy with that combo until…I read this post on Kapitan. Well, colour me intrigued. Kapitan seemed to be the one-stop shop that did the things I was doing with Helm + Kustomize, so I decided to give it a whirl.

Down the Rabbit Hole

Now, I normally do my dev on my beloved MacBook Pro, but in this instance, I needed to do the Kapitan proof-of-concept on a Windows 10 machine. I organized myself as I usually do, with example repos in hand and reference articles on Kapitan ready to go, and proceeded to look up instructions on how to install Kapitan.

The Kapitan Quickstart says that Kapitan is available via Docker image, pip install, or as a standalone library available only for Linux amd64. The Linux amd64 package was a non-starter for me. Although I could’ve easily gotten the Linux binary running on WSL, my target audience were full-on Microsofties who didn’t have WSL set up on their machines, and were more comfortable with PowerShell than with Bash. Plus, I figured that the pip install wouldn’t be too bad. Famous last words. Long story short, it no workie on Windows 10. At least, not without a lot of voodoo. And believe me, I even started trying some of the workarounds for a good 30 minutes before I thought to myself, “Is this even worth it? I mean, I got the Helm + Kustomize thing working pretty well. Let it be.” But no. I am as stubborn as they come, and I do not like being defeated by tech.

So I kept googling. And googling. And googling. No dice. I was still not willing to go through a stupid song and dance just to install this thing. And so, deflated and looking for answers, I returned to the Kapitan Quickstart.

The “A-HA!” Moment

Spoiler alert: the answer was staring me in the face in the Kapitan Quickstart, and I was just (stubbornly) ignoring it. The first sub-heading in the quickstart is: “Docker (recommended)”. DUH. Of COURSE! Run this in Docker.

It’s actually brilliantly simple. The docs tell you to do this:

docker run -t --rm -v $(pwd):/src:delegated deepmind/kapitan <some_command>

Which means: you’re simply using the Docker image to run the Kapitan command-line. Let’s decompose the above command:

  • --rm ensures that the container is removed with it exits
  • -v maps your current working directory ($(pwd)) to the container directory, /src, so that the container has access to files from your local filesystem
  • -t is Docker’s pseudo-TTY, which lets you run <some_command> in Docker

If you take a look at the deepmind/kapitan Dockerfile, you’ll notice that its ENTRYPOINT is the kapitan command. Which means that when we run the docker run command above, it’s the equivalent of running kapitan <some_command>.

Which got me thinking. Why don’t we just alias the docker run command? Then it pretty much looks ands acts like having the CLI installed on your machine.

This means that for Mac and Linux folks, we do something like this:

echo "alias kapitan='docker run -t --rm -v $(pwd):/src:delegated deepmind/kapitan'" >> ~/.bashrcsource ~/.bashrc

Or for Microsoft PowerShell folks, edit Microsoft.PowerShell_profile.ps1, and add the following lines:

function Run-Kapitan-CLI {
docker run -t --rm -v $(pwd):/src:delegated deepmind/kapitan
}

Set-Alias kapitan Run-Kapitan-CLI

For the full process, check out this StackOverflow post.

FYI, Microsoft folks, if you have issues with -v $(pwd):/src:delegated, you can instead replace that with --mount type=bind,source=$(pwd),target=/src.

Et voilà! We now effectively have a platform-independent kapitan CLI. No fuss, no muss!

What I love about this solution is that is:

  • Simple
  • Platform-independent
  • Portable
  • You can do it for any CLI that you want to distribute!! YAY!

Most importantly, it’s not at all a new concept. As we’ve already seen, Kapitan uses this approach, and so does Kaniko.

Many devs already have Docker installed on their systems, and having a CLI containerized pretty much avoids any of the annoying platform-specific problems that you might have when attempting to install a CLI tool. For example, running a zillion versions of Python or Java, and making sure that they all play nice with each other on your machine.

Additional Considerations

If you do choose to distribute a CLI à lá Docker image, make sure that you keep the following in mind:

  • Make sure that your image is versioned using semantic versioning. Using the latest tag is an invitation for trouble.
  • Even though you’re distributing your CLI via Docker image, it’s still an app that you’re distributing, which means that it needs to be well-documented. Good documentation goes a long way.
  • Keep your image size as small as possible. There are tons of articles in the Interwebs on different things you can do to keep your Docker images small. It’s easy to let the size of your Docker image get out of control, and you don’t want your users downloading a 2GB image for a CLI if you can easily avoid it.
  • Keep image security in mind. Your image’s default user, for example, should never be root.

Check out some other Docker best practices here.

Bonus

If you’re interested, I put together a quick example in a gist here, for dockerizing the ArgoCD CLI.

And what of Kapitan?

In case you’re wondering what happened to my Kaptian POC after I finally got the CLI going, I got partway through the tutorial, and realized that Kapitan seemed unnecessarily complicated for my liking. So I decided to stick with Helm + Kustomize, as it seemed to be a simpler approach overall.

Conclusion

The best solutions are the simplest ones. And sometimes, they’re the ones staring you right in the face, if you choose to remove your head out of your ass long enough to see them.

And now, I will reward you with the picture of a cute little duckling. Awwww…

Photo by Meg Kannan on Unsplash

Peace.

Further Reading

Want more ArgoCD goodies? Be sure to check out some of my past ArgoCD-themed blog posts below!

--

--

--

What started off as a DevOps problem turned out to be an Ops problem.

Recommended from Medium

Cheap on-demand optimized images with Laravel and AWS

About Stack Overflow (and its sister sites)

How Agile Is Helping and benefiting the Remote Teams during COVID-19

Serverless Framework —  Develop, deploy, and troubleshoot your serverless!

codebyjeff — Single Table Inheritence in Laravel: No more If’s

Goodbye! WhatsApp Chat Backup

Install Xgboost

Jay-Z & Warren Buffett’s Interview Reveals — Billionaires Think Alike

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adri Villela

Adri Villela

I push the boundaries of software delivery by learning from smart people who challenge the status quo. Former corporate automaton.

More from Medium

Empower Your Pods With Your Cloud-Native Metadata

Gateway = Ingresses & LoadBalancer?

What does Kubernetes actually do and why use it?

Easily Manage your Application Shipment With Differentiated Configuration in Multi-Cluster