snazy commented on code in PR #3553:
URL: https://github.com/apache/polaris/pull/3553#discussion_r2868621479


##########
site/it/site_checks/docker.py:
##########
@@ -0,0 +1,112 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+import json
+import subprocess
+import time
+
+from .tee import Tee
+
+DASH_LINE = 
"------------------------------------------------------------------------------------------------"
+
+
+def cleanup_docker(tee: Tee) -> float:
+    """
+    Clean up (remove) Docker containers, networks, and volumes.
+
+    :param tee: Log output.
+    :return: Elapsed time (in seconds) spent running this cleanup.
+    """
+    start = time.monotonic()
+    try:
+        tee.printf("::group::Cleanup Docker containers, networks, volumes")
+        tee.printf("Purging Docker containers...")
+        try:
+            result = subprocess.run(
+                ["docker", "ps", "-a", "-q"],
+                capture_output=True,
+                text=True,
+                check=False,
+            )
+            container_ids = [line for line in result.stdout.splitlines() if 
line.strip()]
+            if container_ids:
+                tee.run(["docker", "container", "rm", "-f", *container_ids])
+        except FileNotFoundError:
+            pass
+        tee.printf("Purging Docker networks...")
+        try:
+            tee.run(["docker", "network", "prune", "-f"])
+        except FileNotFoundError:
+            pass
+        tee.printf("Purging Docker volumes...")
+        try:
+            tee.run(["docker", "volume", "prune", "-f"])
+        except FileNotFoundError:
+            pass
+        tee.printf("::endgroup::")
+    finally:
+        return time.monotonic() - start
+
+
+def docker_compose_info(tee: Tee, md_base_name: str, md_dir_name: str) -> 
float:
+    """
+    Emit docker compose status/logs for any known compose projects.
+
+    :param tee: Log output.
+    :param md_base_name: Markdown file base name (for logging/group naming).
+    :param md_dir_name: Markdown file directory name (for logging/group 
naming).
+    :return: Elapsed time (in seconds) spent collecting docker compose 
information.
+    """
+    start = time.monotonic()
+    tee.printf(f"::group::Docker Compose information for {md_base_name} in 
{md_dir_name}")
+    tee.printf(DASH_LINE)
+    try:
+        result = subprocess.run(
+            ["docker", "compose", "ls", "--all", "--format", "json"],
+            capture_output=True,
+            text=True,
+            check=False,
+        )
+    except FileNotFoundError:
+        tee.printf(DASH_LINE)
+        tee.printf("::endgroup::")
+        return time.monotonic() - start
+
+    try:
+        compose_entries = json.loads(result.stdout) if result.stdout.strip() 
else []
+    except json.JSONDecodeError:
+        compose_entries = []
+
+    for entry in compose_entries:
+        docker_compose_file = entry.get("ConfigFiles")

Review Comment:
   Added a comment to `_index.md`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to