Repository: bentoml/BentoML

Issue:
bug: Containerize with backend podman does not correctly check for health on linux 
### Describe the bug

When running

bentoml containerize bento:tag --backend podman

A check is performed to see if podman is healthy using "podman machine info". On linux podman does not need to use virtual machines (as opposed to Windows and Mac) so this check fails.

As an example on linux the response is this:

```
Host:
  Arch: amd64
  CurrentMachine: ""
  DefaultMachine: ""
  EventsDir: /run/user/2010/podman
  MachineConfigDir: /home/bentoml/.config/containers/podman/machine/qemu
  MachineImageDir: /home/bentoml/.local/share/containers/podman/machine/qemu
  MachineState: ""
  NumberOfMachines: 0
  OS: linux
  VMType: qemu
Version:
  APIVersion: 4.2.0
  Built: 1670845316
  BuiltTime: Mon Dec 12 19:41:56 2022
  GitCommit: ""
  GoVersion: go1.18.4
  Os: linux
  OsArch: linux/amd64
  Version: 4.2.0
```

The machine state is empty so BentoML thinks podman is unhealthy and will not run the containerisation. (health in bentoml/_internal/container/podman.py)

Possible solution to look at the VMType?

### To reproduce

bentoml containerize bento:tag --backend podman

### Expected behavior

The container should build

### Environment

#### Environment variable

```bash
BENTOML_DEBUG=''
BENTOML_QUIET=''
BENTOML_BUNDLE_LOCAL_BUILD=''
BENTOML_DO_NOT_TRACK=''
BENTOML_CONFIG=''
BENTOML_CONFIG_OPTIONS=''
BENTOML_PORT=''
BENTOML_HOST=''
BENTOML_API_WORKERS=''
```

#### System information

`bentoml`: 1.0.13
`python`: 3.8.12
`platform`: Linux-4.18.0-348.12.2.el8_5.x86_64-x86_64-with-glibc2.2.5
`uid_gid`: 2010:2010
<details><summary><code>pip_packages</code></summary>

<br>

```
aiofiles==0.8.0
aiohttp==3.8.1
aiosignal==1.2.0
anyio==3.6.1
appdirs==1.4.4
asgiref==3.5.2
async-timeout==4.0.2
attrs==21.4.0
backoff==2.2.1
bentoml==1.0.13
bentoserver==0.2.1
cattrs==22.1.0
certifi==2022.5.18.1
chardet==4.0.0
charset-normalizer==2.0.12
circus==0.17.1
click==8.1.3
click-option-group==0.5.5
cloudpickle==2.1.0
commonmark==0.9.1
contextlib2==21.6.0
deepmerge==1.0.1
Deprecated==1.2.13
docker==5.0.3
exceptiongroup==1.0.0rc8
fastapi==0.78.0
filelock==3.7.1
frozenlist==1.3.0
fs==2.4.16
googleapis-common-protos==1.58.0
greenlet==1.1.2
h11==0.13.0
idna==3.3
importlib-metadata==4.12.0
Jinja2==3.1.2
Markdown==3.4.1
MarkupSafe==2.1.1
multidict==6.0.2
numpy==1.22.4
opentelemetry-api==1.14.0
opentelemetry-exporter-otlp-proto-http==1.14.0
opentelemetry-instrumentation==0.35b0
opentelemetry-instrumentation-aiohttp-client==0.35b0
opentelemetry-instrumentation-asgi==0.35b0
opentelemetry-proto==1.14.0
opentelemetry-sdk==1.14.0
opentelemetry-semantic-conventions==0.35b0
opentelemetry-util-http==0.35b0
packaging==21.3
pathspec==0.9.0
pep517==0.12.0
pip-requirements-parser==32.0.0
pip-tools==6.6.2
podman==4.3.1a2
prometheus-client==0.13.1
protobuf==3.20.3
psutil==5.9.1
pydantic==1.9.1
Pygments==2.12.0
pynvml==11.4.1
pyparsing==3.0.9
python-dateutil==2.8.2
python-dotenv==0.20.0
python-json-logger==2.0.2
python-multipart==0.0.5
pyxdg==0.28
PyYAML==6.0
pyzmq==23.1.0
requests==2.28.0
rich==12.4.4
schema==0.7.5
simple-di==0.1.5
six==1.16.0
sniffio==1.2.0
SQLAlchemy==1.4.37
starlette==0.19.1
tomli==2.0.1
tornado==6.1
typing_extensions==4.2.0
urllib3==1.26.9
uvicorn==0.17.6
watchfiles==0.16.1
websocket-client==1.3.2
wrapt==1.14.1
yarl==1.7.2
zipp==3.8.1
```

</details>


Discussion:
Hi @timc, thanks for reporting. We can skip the check for Linux. Feel free to submit a PR for this.

All you have to do is to add the check for state machine on Windows and Mac using `psutil.WINDOWs` and `psutil.MACOS` for podman health.

Resolving patch:
diff --git a/src/bentoml/_internal/container/podman.py b/src/bentoml/_internal/container/podman.py
--- a/src/bentoml/_internal/container/podman.py
+++ b/src/bentoml/_internal/container/podman.py
@@ -6,6 +6,8 @@
 import subprocess
 from typing import TYPE_CHECKING
 
+import psutil
+
 from .base import Arguments
 from .buildah import ENV
 
@@ -32,16 +34,20 @@ def health() -> bool:
             "Podman not found. Make sure it is installed and in your PATH. See https://podman.io/getting-started/installation"
         )
         return False
-    # check if podman machine is running.
-    output = (
-        subprocess.check_output(
-            [client, "machine", "info", "--format", "{{json .Host.MachineState}}"]
+
+    if psutil.MACOS or psutil.WINDOWS:
+        # check if podman machine is running.
+        output = (
+            subprocess.check_output(
+                [client, "machine", "info", "--format", "{{json .Host.MachineState}}"]
+            )
+            .decode("utf-8")
+            .strip("\n&#34;")  # strip quotation marks from JSON format.
+            .lower()
         )
-        .decode("utf-8")
-        .strip("\n&#34;")  # strip quotation marks from JSON format.
-        .lower()
-    )
-    return output == '"running"'
+        return output == '"running"'
+    else:
+        return True
 
 
 def parse_dict_opt(d: dict[str, str]) -> str:


Test patch: