From 4d787217187cccd4097a465004338a80a103662d Mon Sep 17 00:00:00 2001 From: Karl Rister Date: Thu, 16 Feb 2023 10:21:52 -0600 Subject: [PATCH 1/2] add support for optionally specifying compatible system architectures 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. --- schema.json | 24 +++++++++++++++++++++++- workshop.pl | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/schema.json b/schema.json index 9de945a..1ed4eba 100644 --- a/schema.json +++ b/schema.json @@ -72,7 +72,8 @@ "enum": [ "2020.03.02", "2020.04.30", - "2022.07.25" + "2022.07.25", + "2023.02.16" ] } }, @@ -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": { diff --git a/workshop.pl b/workshop.pl index 2996cec..b602924 100755 --- a/workshop.pl +++ b/workshop.pl @@ -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})) { @@ -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 From c007b026c85866882b2cc4ec00e2260938306abd Mon Sep 17 00:00:00 2001 From: Karl Rister Date: Thu, 16 Feb 2023 10:25:25 -0600 Subject: [PATCH 2/2] add container image target architecture validation to workshop-ci --- userenvs/fedora36-ci.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/userenvs/fedora36-ci.json b/userenvs/fedora36-ci.json index f40c749..3b16fee 100644 --- a/userenvs/fedora36-ci.json +++ b/userenvs/fedora36-ci.json @@ -1,7 +1,7 @@ { "workshop": { "schema": { - "version": "2020.03.02" + "version": "2023.02.16" } }, "userenv": { @@ -12,6 +12,14 @@ "tag": "36" }, "properties": { + "platform": [ + { + "architecture": "x86_64" + }, + { + "architecture": "aarch64" + } + ], "packages": { "type": "rpm", "manager": "dnf"