elemental-toolkit icon indicating copy to clipboard operation
elemental-toolkit copied to clipboard

Podman support

Open GrabbenD opened this issue 2 years ago • 4 comments

Podman is a rootless and lighter alternative to Docker which is compatible with the OCI standard. The command syntax is the same as Docker. The ability to build elemental-toolkit with Podman would be greatly appreciated.

Currently make build depends on Docker which results in:

# make build
(...)
 INFO   📦  system/cos-features-0.5-17  Using image:  quay.io/costoolkit/build-teal-cache:2d5da2ad8e7abf9ab55b5a8336e1126ba2cf32973ccfc598dbfebf84de66dbd0
 INFO   📦  system/cos-features-0.5-17 🐋  Generating 'builder' image from quay.io/costoolkit/build-teal-cache:2d5da2ad8e7abf9ab55b5a8336e1126ba2cf32973ccfc598dbfebf84de66dbd0 as quay.io/costoolkit/build-teal-cache:builder-4392e325315c39c9887e7b38f5289171 with prelude steps
 WARNING   Failed to download 'quay.io/costoolkit/build-teal-cache:builder-4392e325315c39c9887e7b38f5289171'. Will keep going and build the image unless you use --fatal
 WARNING   Failed pulling image: : exec: "docker": executable file not found in $PATH

GrabbenD avatar Jul 14 '23 10:07 GrabbenD

Can you

alias docker=podman

and try again ?

kkaempf avatar Jul 14 '23 10:07 kkaempf

Any suggestions on how to change the Makefile ?

kkaempf avatar Jul 14 '23 10:07 kkaempf

Thanks for the idea @kkaempf This turned out to be more complex than I anticipated, nonetheless here's the solutions that I came up with 🙂

v0.10.7

Using alias in bash doesn't work with Makefile / make command as it spawns a new non-interactive subshell which uses /bin/sh (on my system this resolves to /usr/bin/bash):

$ echo "alias docker=podman" >> ~/.bashrc && source ~/.bashrc

$ docker version
Client:       Podman Engine
Version:      4.5.1
(...)

$ make build
(...)
 WARNING   Failed to download 'quay.io/costoolkit/build-teal-cache:builder-4392e325315c39c9887e7b38f5289171'. Will keep going and build the image unless you use --fatal
 WARNING   Failed pulling image: : exec: "docker": executable file not found in $PATH

This makes the alias unavailable as per the documentation:

When Bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

However, it's possible to workaround this with:

$ make SHELL="/bin/bash -i" build

But this might lead to unexpected behavior depending on the user's environment variables and aliases

Another alternative is setting non-interactive variables in /etc/bashrc or /etc/environment but I'm not a fan of that either which lead me further down the rabbit hole:

Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt […].

The rules concerning the definition and use of aliases are somewhat confusing. Bash always reads at least one complete line of input before executing any of the commands on that line. Aliases are expanded when a command is read, not when it is executed. Therefore, an alias definition appearing on the same line as another command does not take effect until the next line of input is read. […] To be safe, always put alias definitions on a separate line, and do not use alias in compound commands.

For almost every purpose, aliases are superseded by shell functions.

Unfortunately aliases are tricky with subshells and the best practice is to use functions:

$ docker () { podman $@; }
$ export -f docker
$ make SHELL="/bin/bash -O expand_aliases" build

Ultimately I wanted less commands and ended up doing:

$ ln -s $(which podman) /usr/bin/docker

main / upcoming release

Fortunately, DOCKER argument is already properly implemented in Makefile (which is the best practice). I was able to do it this way:

sudo -i
pacman -S crun podman git go
git clone --depth 1 --single-branch --branch main https://github.com/rancher/elemental-toolkit.git && cd elemental-toolkit
echo 'unqualified-search-registries = ["docker.io"]' >> /etc/containers/registries.conf
DOCKER=podman make build

GrabbenD avatar Jul 14 '23 17:07 GrabbenD

reopening - we should make this more prominent in the documentation

kkaempf avatar Jul 15 '23 09:07 kkaempf