Skip to content

Commit

Permalink
Move output generation to file
Browse files Browse the repository at this point in the history
  • Loading branch information
cscollett committed Aug 30, 2024
1 parent 842ddf5 commit 77be62a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
11 changes: 1 addition & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
40 changes: 40 additions & 0 deletions print_env.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 77be62a

Please sign in to comment.