-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds Container Runtime Binary Autodetection #1738
Conversation
@@ -56,7 +56,7 @@ var ( | |||
CloudAPIToken: newCfg("cloud.api.token", ""), | |||
Context: newCfg("context", ""), | |||
Contexts: newCfg("contexts", ""), | |||
DockerCommand: newCfg("container.binary", "docker"), | |||
DockerCommand: newCfg("container.binary", ""), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docker
is no longer the "default" here. We "default" to an empty string here and only access the configuration from our new wrapper function where we search the $PATH
for an appropriate binary. If one is not found, we now throw a more helpful error.
e541a81
to
8676726
Compare
Tagging @lzdanski since this can help simplify the podman docs a bit. |
8676726
to
88987c7
Compare
88987c7
to
d6a2c1d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good! Just a question on scanning PATH for the container runtime.
@@ -46,7 +46,7 @@ const ( | |||
RuntimeImageLabel = "io.astronomer.docker.runtime.version" | |||
AirflowImageLabel = "io.astronomer.docker.airflow.version" | |||
componentName = "airflow" | |||
podman = "podman" | |||
podmanCmd = "podman" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just renamed this to be consistent with dockerCmd
. dockerCmd
is not simply docker
because it conflicts with our imports of the docker go libs. This just makes them more similar.
a8aa1a5
to
20bfb81
Compare
20bfb81
to
c3121e4
Compare
// Although programs can be called without the .exe extension, | ||
// we need to append it here when searching the file system. | ||
if isWindows() { | ||
binaryName += ".exe" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we tested the changes in this branch on a Windows machine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah, was just doing that this morning. Just posted some screenshots on the PR description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels risky that we rely on Docker Desktop and Podman continuing to call their executable "docker.exe" and "podman.exe" but I guess the CLI already does when building the image?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea that's true. If something breaks in the wild, I think we'll always have our config file to manually override the binary name, until we have a chance to cut an updated release with a new binary name in the search array here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, if we would run into this code path if running in WSL2 on Windows, I doubt it, but just in case you have already tried out that option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We run into this code path when running astro
on Windows, with podman
managing the WSL2 VM. The podman
binary is podman.exe
in Windows. If we were running purely within WSL2 on something like an Ubuntu machine where astro
and podman
were both installed in Linux, then this path shouldn't be hit. But, I wasn't actually able to get that scenario to work at all, and I don't believe we have that documented as an option yet. Do we have customers operating purely within WSL2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may have customers operating purely within WSl2 on the Software side - it's hard to know. I also would expect IsWindows to be false under WSL2.
}{ | ||
{ | ||
name: "Find docker", | ||
pathEnv: "/usr/local/bin:/usr/bin:/bin", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes we won't run these tests on Windows, but that's probably safe enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests should run on windows because the MockFileChecker
just looks for a match in the mockFiles
map. I originally had the os.Stat
call directly in the function here, but that wouldn't work even across unixy machines since it was actually checking the filesystem which could differ drastically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we're on the topic though, we should probably think about some automated way to run the tests on Windows (a future PR). @sam-awezec was digging into the traffic coming through our onboarding flow and we're seeing a pretty even 50/50 split between mac and windows. Seems like the winget release process could use some love too.
if err != nil { | ||
return err | ||
} | ||
if runtime.GOOS == "darwin" && containerRuntime == dockerCmd { | ||
err := startDocker() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we feel about the CLI taking it upon itself to try to start Docker if it's not running? And only for macOS? But not for Podman?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as we work deeper into this doc, we'll add this support for podman. For podman, we need to manage the underlying podman machine
as well, basically automating the steps we document manually today here - https://www.astronomer.io/docs/astro/cli/use-podman#configure-the-astro-cli-to-use-podman.
The goal would be that a fresh user doesn't need to understand anything about containers to get started. It won't stay "hidden" forever, but at least it won't be something that stands in the way of getting something running in airflow ASAP.
…Users/schnie/go/bin:/Users/schnie/.bun/bin:/Users/schnie/.docker/bin:/Users/schnie/.nvm/versions/node/v16.15.1/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/schnie/bin:/usr/local/bin:/Users/schnie/go/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/usr/local/MacGPG2/bin:/usr/local/go/bin:/Users/schnie/.orbstack/bin:/Users/schnie/.local/bin:/Users/schnie/.local/bin
@rob-1126 I think you originally add the podman binary support. Any concerns here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, apart from a minor curious question
// Although programs can be called without the .exe extension, | ||
// we need to append it here when searching the file system. | ||
if isWindows() { | ||
binaryName += ".exe" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, if we would run into this code path if running in WSL2 on Windows, I doubt it, but just in case you have already tried out that option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for this.
@yanmastin-astro Move step 2 to a "tip" box and note that it's required for versions less than 1.31. In release notes, add a section called |
Description
This PR adds the ability for the CLI to autodetect the container runtime binary to use for the commands that utilize containers. If the already existing configuration (
containers.binary
) is set in theconfig.yaml
file, we use that, otherwise we search file paths in$PATH
fordocker
, thenpodman
. Others can be added if needed.Previously all commands that used the container runtime would grab the configuration directly (
config.CFG.DockerCommand.GetString()
). We've replaced all instances of this with calls to a new function that wraps up this configuration and layers on the auto-detection piece.This is a small piece of a larger project to simplify getting started with Astro CLI. We're also exploring the idea of bundling podman with our package and using it as our default, rather than Docker Desktop. This is part of that effort, but also just useful on its own.
New functionality is in the new files here. The other files are mostly just adapting to the new method signature.
This effectively makes the highlighted command show below unnecessary when using podman.
🎟 Issue(s)
Related to https://github.com/astronomer/astro/issues/24344
🧪 Functional Testing
Tested on Mac and Windows with Docker Desktop, Orbstack (docker binary), and Podman.
Mac OS
astro dev start
with no container runtime installedastro dev start
after runningbrew install podman
Automatically detects
podman
binary and uses it.astro dev start
after additionally runningbrew install orbstack
(docker
binary)Both binaries are installed and
docker
is selected, as it's first in our list.astro dev start
after installing both binaries, but manually overriding topodman
with the config fileWindows OS
Uninstalled podman and attempted to
astro dev start
.We see the helpful error message.
Installed podman and attempt to
astro dev start
again.Once podman is installed, we can successfully run
astro dev start
and view the webserver in the browser.📋 Checklist
make test
before taking out of draftmake lint
before taking out of draftTested against Astro-API (if necessary).Tested against Houston-API and Astronomer (if necessary).