Skip to content

Add script to detect/install apptainer #536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions script/get-apptainer/COPYRIGHT.md
Original file line number Diff line number Diff line change
@@ -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.
85 changes: 85 additions & 0 deletions script/get-apptainer/customize.py
Original file line number Diff line number Diff line change
@@ -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}
8 changes: 8 additions & 0 deletions script/get-apptainer/install-centos.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions script/get-apptainer/install-ubuntu.sh
Original file line number Diff line number Diff line change
@@ -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

2 changes: 2 additions & 0 deletions script/get-apptainer/install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo "Please install apptainer to continue"
exit 1
2 changes: 2 additions & 0 deletions script/get-apptainer/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo "Please install apptainer to continue"
exit 1
22 changes: 22 additions & 0 deletions script/get-apptainer/meta.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
3 changes: 3 additions & 0 deletions script/get-apptainer/run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
apptainer --version > tmp-ver.out
if %errorlevel% neq 0 exit /b 1
3 changes: 3 additions & 0 deletions script/get-apptainer/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
apptainer --version > tmp-ver.out
test $? -eq 0 || exit 1
Loading