From 77be62afccb2754957092041e3327622342a7655 Mon Sep 17 00:00:00 2001 From: Charlie Collett Date: Fri, 30 Aug 2024 14:01:08 -0700 Subject: [PATCH] Move output generation to file --- Dockerfile | 11 +---------- print_env.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 print_env.py diff --git a/Dockerfile b/Dockerfile index 57f649e..5a4d0a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,16 +16,7 @@ WORKDIR /app FROM base AS poetry # Print environment information -RUN echo "--------ENVIRONMENT OUTPUT--------" && \ - . /etc/os-release && \ - echo "ID: $ID" && \ - echo "VERSION_ID: $VERSION_ID" && \ - echo "VERSION_CODENAME: $VERSION_CODENAME" && \ - echo "FULL VERSION: $(cat /etc/debian_version)" && \ - echo "LANGUAGE VERSION: $(python --version 2>&1)" && \ - echo "--------ENVIRONMENT OUTPUT--------" - - +RUN python print_env.py RUN pip install poetry diff --git a/print_env.py b/print_env.py new file mode 100644 index 0000000..5e22fef --- /dev/null +++ b/print_env.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +import os +import subprocess + +def get_os_info(): + os_info = {} + with open("/etc/os-release") as f: + for line in f: + if "=" in line: + key, value = line.strip().split("=", 1) + os_info[key] = value.strip('"') + return os_info + +def get_debian_version(): + try: + with open("/etc/debian_version") as f: + return f.read().strip() + except FileNotFoundError: + return "Unknown" + +def get_python_version(): + result = subprocess.run(["python", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + return result.stdout.decode().strip() or result.stderr.decode().strip() + +def main(): + os_info = get_os_info() + debian_version = get_debian_version() + python_version = get_python_version() + + print("--------ENVIRONMENT OUTPUT--------") + print(f"ENV_OUTPUT_ID: {os_info.get('ID', 'Unknown')}") + print(f"ENV_OUTPUT_VERSION_ID: {os_info.get('VERSION_ID', 'Unknown')}") + print(f"ENV_OUTPUT_VERSION_CODENAME: {os_info.get('VERSION_CODENAME', 'Unknown')}") + print(f"ENV_OUTPUT_FULL_VERSION: {debian_version}") + print(f"ENV_OUTPUT_LANGUAGE_VERSION: {python_version}") + print("--------ENVIRONMENT OUTPUT--------") + +if __name__ == "__main__": + main()