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..6750eede3 --- /dev/null +++ b/script/get-apptainer/customize.py @@ -0,0 +1,85 @@ +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'[Aa]pptainer 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..dfde606b6 --- /dev/null +++ b/script/get-apptainer/install.bat @@ -0,0 +1,2 @@ +echo "Please install apptainer 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