From e3089b05f7a5f99afc9b47443021de0c63ebf387 Mon Sep 17 00:00:00 2001 From: anandhu-eng Date: Thu, 24 Jul 2025 12:00:49 +0530 Subject: [PATCH 1/3] add script to detect/install apptainer --- script/get-apptainer/COPYRIGHT.md | 9 +++ script/get-apptainer/customize.py | 83 ++++++++++++++++++++++++++ script/get-apptainer/install-centos.sh | 8 +++ script/get-apptainer/install-ubuntu.sh | 12 ++++ script/get-apptainer/install.bat | 2 + script/get-apptainer/install.sh | 2 + script/get-apptainer/meta.yaml | 22 +++++++ script/get-apptainer/run.bat | 3 + script/get-apptainer/run.sh | 3 + 9 files changed, 144 insertions(+) create mode 100644 script/get-apptainer/COPYRIGHT.md create mode 100644 script/get-apptainer/customize.py create mode 100644 script/get-apptainer/install-centos.sh create mode 100644 script/get-apptainer/install-ubuntu.sh create mode 100644 script/get-apptainer/install.bat create mode 100644 script/get-apptainer/install.sh create mode 100644 script/get-apptainer/meta.yaml create mode 100644 script/get-apptainer/run.bat create mode 100644 script/get-apptainer/run.sh diff --git a/script/get-apptainer/COPYRIGHT.md b/script/get-apptainer/COPYRIGHT.md new file mode 100644 index 000000000..2d6a2775e --- /dev/null +++ b/script/get-apptainer/COPYRIGHT.md @@ -0,0 +1,9 @@ +# Copyright Notice + +© 2023-2025 MLCommons. All Rights Reserved. + +This file is licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License can be obtained at: + +[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) + +Unless required by applicable law or agreed to in writing, software distributed under the License is provided on an "AS IS" basis, without warranties or conditions of any kind, either express or implied. Please refer to the License for the specific language governing permissions and limitations under the License. diff --git a/script/get-apptainer/customize.py b/script/get-apptainer/customize.py new file mode 100644 index 000000000..96203dec1 --- /dev/null +++ b/script/get-apptainer/customize.py @@ -0,0 +1,83 @@ +from mlc import utils +import os + + +def preprocess(i): + + os_info = i['os_info'] + + env = i['env'] + + automation = i['automation'] + + recursion_spaces = i['recursion_spaces'] + + file_name_apptainer = 'apptainer.exe' if os_info['platform'] == 'windows' else 'apptainer' + + if 'MLC_APPTAINER_BIN_WITH_PATH' not in env: + env['FILE_NAME'] = file_name_apptainer + env['CONTAINER_TOOL_NAME'] = "apptainer" + r = i['automation'].find_artifact({'file_name': file_name_apptainer, + 'env': env, + 'os_info': os_info, + 'default_path_env_key': 'PATH', + 'detect_version': True, + 'env_path_key': 'MLC_APPTAINER_BIN_WITH_PATH', + 'run_script_input': i['run_script_input'], + 'recursion_spaces': recursion_spaces}) + if r['return'] > 0: + if r['return'] == 16: + run_file_name = "install" + r = automation.run_native_script( + {'run_script_input': i['run_script_input'], 'env': env, 'script_name': run_file_name}) + if r['return'] > 0: + return r + else: + return r + + return {'return': 0} + + +def detect_version(i): + r = i['automation'].parse_version({'match_text': r'Apptainer version\s*([\d.]+)', + 'group_number': 1, + 'env_key': 'MLC_APPTAINER_VERSION', + 'which_env': i['env']}) + if r['return'] > 0: + return r + + logger = i['automation'].logger + + version = r['version'] + + tool = "apptainer" + + logger.info( + i['recursion_spaces'] + + ' Detected version: {}'.format(version)) + return {'return': 0, 'version': version, "tool": tool} + + +def postprocess(i): + env = i['env'] + + r = detect_version(i) + + if r['return'] > 0: + return r + + version = r['version'] + tool = r['tool'] + found_file_path = env['MLC_APPTAINER_BIN_WITH_PATH'] + + found_path = os.path.dirname(found_file_path) + env['MLC_APPTAINER_INSTALLED_PATH'] = found_path + env['+PATH'] = [found_path] + + env['MLC_APPTAINER_CACHE_TAGS'] = 'version-' + version + + env['MLC_APPTAINER_VERSION'] = version + + env['MLC_CONTAINER_TOOL'] = tool + + return {'return': 0, 'version': version} diff --git a/script/get-apptainer/install-centos.sh b/script/get-apptainer/install-centos.sh new file mode 100644 index 000000000..be9879bf2 --- /dev/null +++ b/script/get-apptainer/install-centos.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e +${MLC_SUDO} yum install -y epel-release +${MLC_SUDO} yum install -y apptainer +test $? -eq 0 || exit $? + +# Print version +apptainer --version diff --git a/script/get-apptainer/install-ubuntu.sh b/script/get-apptainer/install-ubuntu.sh new file mode 100644 index 000000000..8a7036669 --- /dev/null +++ b/script/get-apptainer/install-ubuntu.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e +${MLC_SUDO} apt-get update +${MLC_SUDO} apt-get install -y software-properties-common +${MLC_SUDO} add-apt-repository -y ppa:apptainer/ppa +${MLC_SUDO} apt-get update +${MLC_SUDO} apt-get install -y apptainer +test $? -eq 0 || exit $? + +# Print version +apptainer --version + diff --git a/script/get-apptainer/install.bat b/script/get-apptainer/install.bat new file mode 100644 index 000000000..d6bdb8295 --- /dev/null +++ b/script/get-apptainer/install.bat @@ -0,0 +1,2 @@ +echo "Please install docker to continue" +exit 1 diff --git a/script/get-apptainer/install.sh b/script/get-apptainer/install.sh new file mode 100644 index 000000000..dfde606b6 --- /dev/null +++ b/script/get-apptainer/install.sh @@ -0,0 +1,2 @@ +echo "Please install apptainer to continue" +exit 1 diff --git a/script/get-apptainer/meta.yaml b/script/get-apptainer/meta.yaml new file mode 100644 index 000000000..39743ec39 --- /dev/null +++ b/script/get-apptainer/meta.yaml @@ -0,0 +1,22 @@ +alias: get-apptainer +automation_alias: script +automation_uid: 5b4e0237da074764 +cache: true +category: Detection or installation of tools and artifacts +deps: +- tags: detect,os +- tags: detect,sudo +input_description: {} +input_mapping: {} +new_env_keys: +- MLC_APPTAINER_VERSION +- MLC_CONTAINER_TOOL +new_state_keys: [] +post_deps: [] +posthook_deps: [] +prehook_deps: [] +tags: +- get-apptainer +uid: 37c5bc01c11f49fa +variations: {} +versions: {} diff --git a/script/get-apptainer/run.bat b/script/get-apptainer/run.bat new file mode 100644 index 000000000..a90c05a64 --- /dev/null +++ b/script/get-apptainer/run.bat @@ -0,0 +1,3 @@ +@echo off +apptainer --version > tmp-ver.out +if %errorlevel% neq 0 exit /b 1 diff --git a/script/get-apptainer/run.sh b/script/get-apptainer/run.sh new file mode 100644 index 000000000..38a153a65 --- /dev/null +++ b/script/get-apptainer/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash +apptainer --version > tmp-ver.out +test $? -eq 0 || exit 1 From 5deeed61d44c26f68382a1dcf9adafa434dd59cd Mon Sep 17 00:00:00 2001 From: anandhu-eng Date: Thu, 24 Jul 2025 12:15:52 +0530 Subject: [PATCH 2/3] regex change --- script/get-apptainer/customize.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/script/get-apptainer/customize.py b/script/get-apptainer/customize.py index 96203dec1..6750eede3 100644 --- a/script/get-apptainer/customize.py +++ b/script/get-apptainer/customize.py @@ -39,10 +39,12 @@ def preprocess(i): def detect_version(i): - r = i['automation'].parse_version({'match_text': r'Apptainer version\s*([\d.]+)', - 'group_number': 1, - 'env_key': 'MLC_APPTAINER_VERSION', - 'which_env': i['env']}) + r = i['automation'].parse_version({ + 'match_text': r'[Aa]pptainer version\s*([\d.]+)', + 'group_number': 1, + 'env_key': 'MLC_APPTAINER_VERSION', + 'which_env': i['env'] + }) if r['return'] > 0: return r From 3747401dfcb440c76d15735d46346df16f912e10 Mon Sep 17 00:00:00 2001 From: ANANDHU S <71482562+anandhu-eng@users.noreply.github.com> Date: Fri, 25 Jul 2025 09:38:50 +0530 Subject: [PATCH 3/3] fix typo --- script/get-apptainer/install.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/get-apptainer/install.bat b/script/get-apptainer/install.bat index d6bdb8295..dfde606b6 100644 --- a/script/get-apptainer/install.bat +++ b/script/get-apptainer/install.bat @@ -1,2 +1,2 @@ -echo "Please install docker to continue" +echo "Please install apptainer to continue" exit 1