Skip to content

Commit

Permalink
fix: use architectures from opencontainers initiative
Browse files Browse the repository at this point in the history
  • Loading branch information
fstagni committed Jun 5, 2024
1 parent 6475951 commit 6b517e7
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/DIRAC/Core/Utilities/Os.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,34 +154,39 @@ def which(executable):
return shutil.which(executable)


def findImage(continer_root="container/apptainer/alma9/"):
def findImage(container_root="container/apptainer/alma9/"):
"""Finds the image for the current platform
This looks into location "${CVMFS_locations}/${container_root}/${platform}/"
and expects to find one of the following platforms:
- x86_64
- aarch64
- ppc64le
This looks into location "${CVMFS_locations}/${container_root}/${platform}/"
and expects to find one of the following platforms:
- x86_64
- aarch64
- ppc64le
"""
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations

plat = DIRAC.gConfig.getValue("LocalSite/Platform", platform.machine())
DIRAC.gLogger.info(f"Platform: {plat}")

# NB: platform compatibility is more complex than the following simple identification.
# sources:

# NB: platform compatibility is more complex than the following simple identification.
#
# Given that, on Linux, platform.machine() returns the same values as uname -m,
# and this is already "confusing", e.g. see
# https://stackoverflow.com/questions/45125516/possible-values-for-uname-m
# https://en.wikipedia.org/wiki/Uname

if plat.lower() == "amd64":
plat = "x86_64"
if plat.lower().startswith("arm"):
plat = "aarch64"
# Since here we are using the architecture specification defined by opencontainers initiative:
# https://github.com/opencontainers/image-spec/blob/main/image-index.md#platform-variants
# we need to make some simple "conversions" to get the right values:

if plat.lower() == "x86_64":
plat = "amd64"
if plat.lower().startswith("arm") or plat.lower() == "aarch64":
plat = "arm64"
if plat.lower().startswith("ppc64"):
plat = "ppc64le"

if plat not in ["x86_64", "aarch64", "ppc64le"]:
if plat not in ["amd64", "arm64", "ppc64le"]:
DIRAC.gLogger.error(f"Platform {plat} not supported")
return None

Expand All @@ -192,7 +197,7 @@ def findImage(continer_root="container/apptainer/alma9/"):
rootImage = None

for candidate in CVMFS_locations:
rootImage = os.path.join(candidate, continer_root, plat)
rootImage = os.path.join(candidate, container_root, plat)
DIRAC.gLogger.verbose(f"Checking {rootImage} existence")
if safe_listdir(rootImage):
break
Expand Down

0 comments on commit 6b517e7

Please sign in to comment.