Skip to content

Commit

Permalink
add support for optionally specifying compatible system architectures…
Browse files Browse the repository at this point in the history
… in a userenv

- Some base container images that userenvs are based on support
  multiple architectures and some do not.  This new ability allows the
  userenv definition to optionally declare what is supported so that
  future errors can be avoided by failing very early.

- Initially the only supported architectures are x86_64 and aarch64
  (arm64) as they are the only environments that have been tested.
  • Loading branch information
k-rister committed Feb 16, 2023
1 parent 7eac4f7 commit 4d78721
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
24 changes: 23 additions & 1 deletion schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"enum": [
"2020.03.02",
"2020.04.30",
"2022.07.25"
"2022.07.25",
"2023.02.16"
]
}
},
Expand Down Expand Up @@ -119,6 +120,27 @@
"properties": {
"type": "object",
"properties": {
"platform": {
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": {
"type": "object",
"properties": {
"architecture": {
"type": "string",
"enum": [
"x86_64",
"aarch64"
]
}
},
"required": [
"architecture"
],
"additionalProperties": false
}
},
"packages": {
"type": "object",
"properties": {
Expand Down
39 changes: 39 additions & 0 deletions workshop.pl
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ sub get_exit_code {
'no_label' => 92,
'package_remove' => 93,
'group_remove' => 94,
'architecture_query_failed' => 95,
'unsupported_platform_architecture' => 96
);

if (exists($reasons{$exit_reason})) {
Expand Down Expand Up @@ -579,6 +581,43 @@ sub delete_proto {
}
}

if (exists $userenv_json->{'userenv'}{'properties'}{'platform'}) {
# the userenv has platform information that indicates what type of
# system architecture(s) it supports so validate that what we are
# about to build is supported
my $my_architecture;
logger('info', "performing userenv platform validation...\n", 1);
($command, $command_output, $rc) = run_command("uname -m");
if ($rc == 0) {
command_logger('verbose', $command, $rc, $command_output);
$command_output = filter_output($command_output);
chomp($command_output);
$my_architecture = $command_output;
logger('info', "found current system architecture is " . $my_architecture . "\n", 2);
} else {
logger('info', "failed\n", 2);
command_logger('error', $command, $rc, $command_output);
logger('error', "Failed to obtain the current system architecture!\n");
exit(get_exit_code('architecture_query_failed'));
}

my $supported = 0;
# loop through the supported platforms and see if our architecture matches one of them
foreach my $platform (@{$userenv_json->{'userenv'}{'properties'}{'platform'}}) {
if ($platform->{'architecture'} eq $my_architecture) {
$supported = 1;
}
}

if ($supported) {
logger('info', "succeeded...the userenv is supported for my architecture.\n", 2);
} else {
logger('info', "failed...the userenv is not supported for my architecture.\n", 2);
logger('error', "The userenv is not supported for my architecure.\n");
exit(get_exit_code('unsupported_platform_architecture'));
}
}

if (!defined $args{'proj'}) {
if (defined $args{'label'}) {
# Support default behavior before --proj was introduced
Expand Down

0 comments on commit 4d78721

Please sign in to comment.