From aed5cd32cb05867b882865a62e141ad5823b602e Mon Sep 17 00:00:00 2001 From: Daniel McIlvaney Date: Thu, 14 Nov 2024 11:28:58 -0800 Subject: [PATCH 1/6] Automate prereq install --- .github/workflows/check-prerequisites.yml | 44 ++++++ .../docs/building/prerequisites-mariner.md | 2 +- toolkit/docs/building/prerequisites-src.json | 133 ++++++++++++++++++ toolkit/docs/building/prerequisites-ubuntu.md | 3 +- toolkit/scripts/prerequisites.sh | 121 ++++++++++++++++ toolkit/scripts/toolkit.mk | 6 + 6 files changed, 307 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/check-prerequisites.yml create mode 100644 toolkit/docs/building/prerequisites-src.json create mode 100755 toolkit/scripts/prerequisites.sh diff --git a/.github/workflows/check-prerequisites.yml b/.github/workflows/check-prerequisites.yml new file mode 100644 index 00000000000..687c03476bb --- /dev/null +++ b/.github/workflows/check-prerequisites.yml @@ -0,0 +1,44 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +# This action checks that the licenses.json file is up-to-date +# and that the LICENSES-MAP.md file is up-to-date +name: Prerequisites Check + +on: + push: + branches: [main, dev, 1.0*, 2.0*, 3.0*, fasttrack/*] + pull_request: + branches: [main, dev, 1.0*, 2.0*, 3.0*, fasttrack/*] + +jobs: + check: + name: Prerequisites Check + runs-on: ubuntu-latest + + steps: + # Checkout the branch of our repo that triggered this action + - name: Workflow trigger checkout + uses: actions/checkout@v4 + + - name: Run prerequisites checking script for Ubuntu + run: | + if [ ! -f ./toolkit/docs/building/prerequisites-src.json ]; then + echo "prerequisites-src.json not found" + exit 0 + fi + ./toolkit/scripts/prerequisites.sh \ + -m ./toolkit/docs/building/prerequisites-ubuntu.md \ + -s ./toolkit/docs/building/prerequisites-src.json \ + -d "ubuntu" + + - name: Run prerequisites checking script for AzureLinux + run: | + if [ ! -f ./toolkit/docs/building/prerequisites-src.json ]; then + echo "prerequisites-src.json not found" + exit 0 + fi + ./toolkit/scripts/prerequisites.sh \ + -m ./toolkit/docs/building/prerequisites-mariner.md \ + -s ./toolkit/docs/building/prerequisites-src.json \ + -d "azurelinux" diff --git a/toolkit/docs/building/prerequisites-mariner.md b/toolkit/docs/building/prerequisites-mariner.md index a8acb5dd06b..2563b450a22 100644 --- a/toolkit/docs/building/prerequisites-mariner.md +++ b/toolkit/docs/building/prerequisites-mariner.md @@ -16,9 +16,9 @@ sudo tdnf -y install \ diffutils \ dosfstools \ gawk \ - glibc-devel \ genisoimage \ git \ + glibc-devel \ golang \ jq \ kernel-headers \ diff --git a/toolkit/docs/building/prerequisites-src.json b/toolkit/docs/building/prerequisites-src.json new file mode 100644 index 00000000000..ea4102828ed --- /dev/null +++ b/toolkit/docs/building/prerequisites-src.json @@ -0,0 +1,133 @@ +[ + { + "name": "acl", + "azurelinux": "acl", + "ubuntu": "acl" + }, + { + "name": "binutils", + "azurelinux": "binutils" + }, + { + "name": "cdrkit", + "azurelinux": "cdrkit" + }, + { + "name": "curl", + "azurelinux": "curl", + "ubuntu": "curl" + }, + { + "name": "diffutils", + "azurelinux": "diffutils", + "ubuntu": "diffutils" + }, + { + "name": "dosfstools", + "azurelinux": "dosfstools" + }, + { + "name": "gawk", + "azurelinux": "gawk", + "ubuntu": "gawk" + }, + { + "name": "glibc-devel", + "azurelinux": "glibc-devel" + }, + { + "name": "genisoimage", + "azurelinux": "genisoimage", + "ubuntu": "genisoimage" + }, + { + "name": "git", + "azurelinux": "git", + "ubuntu": "git" + }, + { + "name": "golang", + "azurelinux": "golang", + "ubuntu": "golang-1.21-go" + }, + { + "name": "jq", + "azurelinux": "jq", + "ubuntu": "jq" + }, + { + "name": "kernel-headers", + "azurelinux": "kernel-headers" + }, + { + "name": "make", + "azurelinux": "make", + "ubuntu": "make" + }, + { + "name": "moby-cli", + "azurelinux": "moby-cli" + }, + { + "name": "moby-engine", + "azurelinux": "moby-engine" + }, + { + "name": "openssl", + "azurelinux": "openssl", + "ubuntu": "openssl" + }, + { + "name": "parted", + "azurelinux": "parted", + "ubuntu": "parted" + }, + { + "name": "pigz", + "azurelinux": "pigz", + "ubuntu": "pigz" + }, + { + "name": "qemu-img", + "azurelinux": "qemu-img", + "ubuntu": "qemu-utils" + }, + { + "name": "rpm", + "azurelinux": "rpm", + "ubuntu": "rpm" + }, + { + "name": "rpm-build", + "azurelinux": "rpm-build" + }, + { + "name": "sudo", + "azurelinux": "sudo" + }, + { + "name": "systemd", + "azurelinux": "systemd", + "ubuntu": "systemd" + }, + { + "name": "tar", + "azurelinux": "tar", + "ubuntu": "tar" + }, + { + "name": "wget", + "azurelinux": "wget", + "ubuntu": "wget" + }, + { + "name": "xfsprogs", + "azurelinux": "xfsprogs", + "ubuntu": "xfsprogs" + }, + { + "name": "zstd", + "azurelinux": "zstd", + "ubuntu": "zstd" + } +] diff --git a/toolkit/docs/building/prerequisites-ubuntu.md b/toolkit/docs/building/prerequisites-ubuntu.md index c96944df2ad..5395988af67 100644 --- a/toolkit/docs/building/prerequisites-ubuntu.md +++ b/toolkit/docs/building/prerequisites-ubuntu.md @@ -20,11 +20,12 @@ sudo apt -y install \ golang-1.21-go \ jq \ make \ + openssl \ parted \ pigz \ - openssl \ qemu-utils \ rpm \ + systemd \ tar \ wget \ xfsprogs \ diff --git a/toolkit/scripts/prerequisites.sh b/toolkit/scripts/prerequisites.sh new file mode 100755 index 00000000000..1b2cd52a623 --- /dev/null +++ b/toolkit/scripts/prerequisites.sh @@ -0,0 +1,121 @@ +#!/bin/bash -e +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +prereq_md_path="" +prereq_json_path="" + +function help { + echo "Pre-requisite installer. Installs azurelinux pre-requisites for the toolkit." + echo "Usage:" + echo '[MANDATORY] -m PATH -> path to the pre-requisite md file' + echo '[MANDATORY] -s PATH -> path to the src json file' + echo '[MANDATORY] -d DISTRO -> One of "azurelinux" or "ubuntu"' + echo '[OPTIONAL] -p -> print the canonical pre-requisite list and exit' + echo '[OPTIONAL] -h -> print this help dialogue and exit' +} + +do_print=false +while getopts "hpm:s:d:" OPTIONS; do + case ${OPTIONS} in + m ) prereq_md_path=$OPTARG ;; + s ) prereq_json_path=$OPTARG ;; + d ) distro=$OPTARG ;; + p ) do_print="true" ;; + h ) help; exit 0 ;; + ? ) echo -e "ERROR: INVALID OPTION.\n\n" >&2; help; exit 1 ;; + esac +done + +if [ -z "$prereq_json_path" ]; then + echo "ERROR: Missing src json file path." >&2 + help + exit 1 +fi + +if [ ! -f "$prereq_json_path" ]; then + echo "ERROR: Src json file not found at $prereq_json_path." >&2 + exit 1 +fi + +if [ -z "$distro" ]; then + echo "ERROR: Missing distro." >&2 + help + exit 1 +fi + +if [ "$distro" != "azurelinux" ] && [ "$distro" != "ubuntu" ]; then + echo "ERROR: Invalid distro. Must be one of 'azurelinux' or 'ubuntu'." >&2 + help + exit 1 +fi + +# For print mode, just print the pre-requisites and exit early. +# A distro specific entry may not exist for every package, so get the entries that do exist, and +# select the distro specific value. Convert the result to a space separated string. +src_prereqs=$(jq -r --arg distro "$distro" '[.[] | select(has($distro)) | .[$distro]] | sort | join(" ")' "$prereq_json_path") +if "$do_print"; then + echo "$src_prereqs" + exit 0 +fi + +if [ -z "$prereq_md_path" ]; then + echo "ERROR: Missing pre-requisite file path." >&2 + help + exit 1 +fi + +if [ ! -f "$prereq_md_path" ]; then + echo "ERROR: Pre-requisite file not found at $prereq_md_path." >&2 + exit 1 +fi + +# Load the pre-requisite source json for the distro of interest +# Json is of the form: +# [ +# { +# "name": "pkg", +# "azurelinux": "pkg-b", +# "ubuntu": "pkg-a" +# }, +# ... +#] + + +current_prereqs="$(sed -e ':a' -e 'N' -e '$!ba' -e 's/\\\n/ /g' "$prereq_md_path")" +if [[ "$distro" == "azurelinux" ]]; then + # Get the current entry in the .md file: + # 1) Remove all line continuations (backslash followed by newline) and replace with a space + # 2) Remove all leading and trailing whitespace + # 3) Find the line that starts with "sudo tdnf -y install ..." + # 4) Grab the package list from the line + + current_prereqs=$(echo "$current_prereqs" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + current_prereqs=$(echo "$current_prereqs" | grep -oP 'sudo tdnf -y install \K.*') + current_prereqs=$(echo "$current_prereqs" | xargs) +elif [[ "$distro" == "ubuntu" ]]; then + # Get the current entry in the .md file: + # 1) Remove all line continuations (backslash followed by newline) and replace with a space + # 2) Remove all leading and trailing whitespace + # 3) Find the line that starts with "sudo apt -y install ..." + # 4) Grab the package list from the line + + current_prereqs=$(echo "$current_prereqs" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + current_prereqs=$(echo "$current_prereqs" | grep -oP 'sudo apt -y install \K.*') + current_prereqs=$(echo "$current_prereqs" | xargs) +fi + +# Compare the current and source pre-requisites. Enforce a 1:1 match including order. +if [ "$current_prereqs" != "$src_prereqs" ]; then + echo "ERROR: Pre-requisites do not match. Please update the pre-requisite file." + echo "" + echo "Comparing: $prereq_json_path" + echo "with: $prereq_md_path" + echo "" + echo ".json file: $src_prereqs" + echo ".md file: $current_prereqs" + exit 1 +else + echo "Pre-requisites match." + exit 0 +fi diff --git a/toolkit/scripts/toolkit.mk b/toolkit/scripts/toolkit.mk index 07647755502..32e33ef03df 100644 --- a/toolkit/scripts/toolkit.mk +++ b/toolkit/scripts/toolkit.mk @@ -127,3 +127,9 @@ $(valid_arch_spec_names): $(go-specarchchecker) $(chroot_worker) $(local_specs) --log-level=$(LOG_LEVEL) \ --log-file="$(valid_arch_spec_names_logs_path)" \ --log-color="$(LOG_COLOR)" + +##help:target:install-azurelinux-prereqs=Install Azure Linux Prerequisites +install-azurelinux-prereqs: + @echo "Installing Azure Linux Prerequisites" + prereqs="$$( $(SCRIPTS_DIR)/prerequisites.sh -s $(toolkit_root)/docs/building/prerequisites-src.json -d azurelinux -p )" && \ + tdnf -y install $$prereqs From 7383d15fd860c9afd5b44c55b952df7d14ccddb2 Mon Sep 17 00:00:00 2001 From: Daniel McIlvaney Date: Thu, 14 Nov 2024 14:16:13 -0800 Subject: [PATCH 2/6] drop systemd for independent PRs --- toolkit/docs/building/prerequisites-src.json | 5 ----- toolkit/docs/building/prerequisites-ubuntu.md | 1 - 2 files changed, 6 deletions(-) diff --git a/toolkit/docs/building/prerequisites-src.json b/toolkit/docs/building/prerequisites-src.json index ea4102828ed..2772677171a 100644 --- a/toolkit/docs/building/prerequisites-src.json +++ b/toolkit/docs/building/prerequisites-src.json @@ -105,11 +105,6 @@ "name": "sudo", "azurelinux": "sudo" }, - { - "name": "systemd", - "azurelinux": "systemd", - "ubuntu": "systemd" - }, { "name": "tar", "azurelinux": "tar", diff --git a/toolkit/docs/building/prerequisites-ubuntu.md b/toolkit/docs/building/prerequisites-ubuntu.md index 5395988af67..6c1796330db 100644 --- a/toolkit/docs/building/prerequisites-ubuntu.md +++ b/toolkit/docs/building/prerequisites-ubuntu.md @@ -25,7 +25,6 @@ sudo apt -y install \ pigz \ qemu-utils \ rpm \ - systemd \ tar \ wget \ xfsprogs \ From 4f880a0977590102ceada254602abc44e514991a Mon Sep 17 00:00:00 2001 From: Daniel McIlvaney Date: Thu, 14 Nov 2024 14:52:54 -0800 Subject: [PATCH 3/6] Add comments to json, clean up script --- toolkit/docs/building/prerequisites-src.json | 261 ++++++++++--------- toolkit/scripts/prerequisites.sh | 74 +++--- 2 files changed, 169 insertions(+), 166 deletions(-) diff --git a/toolkit/docs/building/prerequisites-src.json b/toolkit/docs/building/prerequisites-src.json index 2772677171a..001ed0b30f1 100644 --- a/toolkit/docs/building/prerequisites-src.json +++ b/toolkit/docs/building/prerequisites-src.json @@ -1,128 +1,133 @@ -[ - { - "name": "acl", - "azurelinux": "acl", - "ubuntu": "acl" - }, - { - "name": "binutils", - "azurelinux": "binutils" - }, - { - "name": "cdrkit", - "azurelinux": "cdrkit" - }, - { - "name": "curl", - "azurelinux": "curl", - "ubuntu": "curl" - }, - { - "name": "diffutils", - "azurelinux": "diffutils", - "ubuntu": "diffutils" - }, - { - "name": "dosfstools", - "azurelinux": "dosfstools" - }, - { - "name": "gawk", - "azurelinux": "gawk", - "ubuntu": "gawk" - }, - { - "name": "glibc-devel", - "azurelinux": "glibc-devel" - }, - { - "name": "genisoimage", - "azurelinux": "genisoimage", - "ubuntu": "genisoimage" - }, - { - "name": "git", - "azurelinux": "git", - "ubuntu": "git" - }, - { - "name": "golang", - "azurelinux": "golang", - "ubuntu": "golang-1.21-go" - }, - { - "name": "jq", - "azurelinux": "jq", - "ubuntu": "jq" - }, - { - "name": "kernel-headers", - "azurelinux": "kernel-headers" - }, - { - "name": "make", - "azurelinux": "make", - "ubuntu": "make" - }, - { - "name": "moby-cli", - "azurelinux": "moby-cli" - }, - { - "name": "moby-engine", - "azurelinux": "moby-engine" - }, - { - "name": "openssl", - "azurelinux": "openssl", - "ubuntu": "openssl" - }, - { - "name": "parted", - "azurelinux": "parted", - "ubuntu": "parted" - }, - { - "name": "pigz", - "azurelinux": "pigz", - "ubuntu": "pigz" - }, - { - "name": "qemu-img", - "azurelinux": "qemu-img", - "ubuntu": "qemu-utils" - }, - { - "name": "rpm", - "azurelinux": "rpm", - "ubuntu": "rpm" - }, - { - "name": "rpm-build", - "azurelinux": "rpm-build" - }, - { - "name": "sudo", - "azurelinux": "sudo" - }, - { - "name": "tar", - "azurelinux": "tar", - "ubuntu": "tar" - }, - { - "name": "wget", - "azurelinux": "wget", - "ubuntu": "wget" - }, - { - "name": "xfsprogs", - "azurelinux": "xfsprogs", - "ubuntu": "xfsprogs" - }, - { - "name": "zstd", - "azurelinux": "zstd", - "ubuntu": "zstd" - } -] +{ + "_comment": "This JSON file lists the prerequisites for building the source code in the CBL-Mariner toolkit.", + "_comment2": "check-prerequisites.yml and 'make install-azurelinux-prereqs' use this file as the canonical truth", + "_comment3": "The 'name' field is the name of the package to install, followed by the actual package name for each supported OS", + "packages": [ + { + "name": "acl", + "azurelinux": "acl", + "ubuntu": "acl" + }, + { + "name": "binutils", + "azurelinux": "binutils" + }, + { + "name": "cdrkit", + "azurelinux": "cdrkit" + }, + { + "name": "curl", + "azurelinux": "curl", + "ubuntu": "curl" + }, + { + "name": "diffutils", + "azurelinux": "diffutils", + "ubuntu": "diffutils" + }, + { + "name": "dosfstools", + "azurelinux": "dosfstools" + }, + { + "name": "gawk", + "azurelinux": "gawk", + "ubuntu": "gawk" + }, + { + "name": "glibc-devel", + "azurelinux": "glibc-devel" + }, + { + "name": "genisoimage", + "azurelinux": "genisoimage", + "ubuntu": "genisoimage" + }, + { + "name": "git", + "azurelinux": "git", + "ubuntu": "git" + }, + { + "name": "golang", + "azurelinux": "golang", + "ubuntu": "golang-1.21-go" + }, + { + "name": "jq", + "azurelinux": "jq", + "ubuntu": "jq" + }, + { + "name": "kernel-headers", + "azurelinux": "kernel-headers" + }, + { + "name": "make", + "azurelinux": "make", + "ubuntu": "make" + }, + { + "name": "moby-cli", + "azurelinux": "moby-cli" + }, + { + "name": "moby-engine", + "azurelinux": "moby-engine" + }, + { + "name": "openssl", + "azurelinux": "openssl", + "ubuntu": "openssl" + }, + { + "name": "parted", + "azurelinux": "parted", + "ubuntu": "parted" + }, + { + "name": "pigz", + "azurelinux": "pigz", + "ubuntu": "pigz" + }, + { + "name": "qemu-img", + "azurelinux": "qemu-img", + "ubuntu": "qemu-utils" + }, + { + "name": "rpm", + "azurelinux": "rpm", + "ubuntu": "rpm" + }, + { + "name": "rpm-build", + "azurelinux": "rpm-build" + }, + { + "name": "sudo", + "azurelinux": "sudo" + }, + { + "name": "tar", + "azurelinux": "tar", + "ubuntu": "tar" + }, + { + "name": "wget", + "azurelinux": "wget", + "ubuntu": "wget" + }, + { + "name": "xfsprogs", + "azurelinux": "xfsprogs", + "ubuntu": "xfsprogs" + }, + { + "name": "zstd", + "azurelinux": "zstd", + "ubuntu": "zstd" + } + ] +} diff --git a/toolkit/scripts/prerequisites.sh b/toolkit/scripts/prerequisites.sh index 1b2cd52a623..4c12460847a 100755 --- a/toolkit/scripts/prerequisites.sh +++ b/toolkit/scripts/prerequisites.sh @@ -1,11 +1,14 @@ -#!/bin/bash -e +#!/bin/bash + # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +set -e + prereq_md_path="" prereq_json_path="" -function help { +function print_help { echo "Pre-requisite installer. Installs azurelinux pre-requisites for the toolkit." echo "Usage:" echo '[MANDATORY] -m PATH -> path to the pre-requisite md file' @@ -22,14 +25,14 @@ while getopts "hpm:s:d:" OPTIONS; do s ) prereq_json_path=$OPTARG ;; d ) distro=$OPTARG ;; p ) do_print="true" ;; - h ) help; exit 0 ;; - ? ) echo -e "ERROR: INVALID OPTION.\n\n" >&2; help; exit 1 ;; + h ) print_help; exit 0 ;; + ? ) echo -e "ERROR: INVALID OPTION.\n\n" >&2; print_help; exit 1 ;; esac done if [ -z "$prereq_json_path" ]; then echo "ERROR: Missing src json file path." >&2 - help + print_help exit 1 fi @@ -40,20 +43,33 @@ fi if [ -z "$distro" ]; then echo "ERROR: Missing distro." >&2 - help + print_help exit 1 fi if [ "$distro" != "azurelinux" ] && [ "$distro" != "ubuntu" ]; then echo "ERROR: Invalid distro. Must be one of 'azurelinux' or 'ubuntu'." >&2 - help + print_help exit 1 fi -# For print mode, just print the pre-requisites and exit early. +# Load the pre-requisite source json for the distro of interest +# Json is of the form: +# { +# "packages": [ +# { +# "name": "pkg", +# "azurelinux": "pkg-b", +# "ubuntu": "pkg-a" +# }, +# ... +# ] +#} # A distro specific entry may not exist for every package, so get the entries that do exist, and # select the distro specific value. Convert the result to a space separated string. -src_prereqs=$(jq -r --arg distro "$distro" '[.[] | select(has($distro)) | .[$distro]] | sort | join(" ")' "$prereq_json_path") +src_prereqs=$(jq -r --arg distro "$distro" '[.packages[] | select(has($distro)) | .[$distro]] | sort | join(" ")' "$prereq_json_path") + +# For print mode, just print the pre-requisites and exit early. if "$do_print"; then echo "$src_prereqs" exit 0 @@ -61,7 +77,7 @@ fi if [ -z "$prereq_md_path" ]; then echo "ERROR: Missing pre-requisite file path." >&2 - help + print_help exit 1 fi @@ -70,42 +86,24 @@ if [ ! -f "$prereq_md_path" ]; then exit 1 fi -# Load the pre-requisite source json for the distro of interest -# Json is of the form: -# [ -# { -# "name": "pkg", -# "azurelinux": "pkg-b", -# "ubuntu": "pkg-a" -# }, -# ... -#] +# Get the current entry in the .md file: +# 1) Remove all line continuations (backslash followed by newline) and replace with a space +current_prereqs="$(sed -e ':a' -e 'N' -e '$!ba' -e 's/\\\n/ /g' "$prereq_md_path")" +# 2) Remove all leading and trailing whitespace +current_prereqs=$(echo "$current_prereqs" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') -current_prereqs="$(sed -e ':a' -e 'N' -e '$!ba' -e 's/\\\n/ /g' "$prereq_md_path")" +# 3) Find the line that starts with "sudo -y install ..." if [[ "$distro" == "azurelinux" ]]; then - # Get the current entry in the .md file: - # 1) Remove all line continuations (backslash followed by newline) and replace with a space - # 2) Remove all leading and trailing whitespace - # 3) Find the line that starts with "sudo tdnf -y install ..." - # 4) Grab the package list from the line - - current_prereqs=$(echo "$current_prereqs" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') current_prereqs=$(echo "$current_prereqs" | grep -oP 'sudo tdnf -y install \K.*') - current_prereqs=$(echo "$current_prereqs" | xargs) elif [[ "$distro" == "ubuntu" ]]; then - # Get the current entry in the .md file: - # 1) Remove all line continuations (backslash followed by newline) and replace with a space - # 2) Remove all leading and trailing whitespace - # 3) Find the line that starts with "sudo apt -y install ..." - # 4) Grab the package list from the line - - current_prereqs=$(echo "$current_prereqs" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') current_prereqs=$(echo "$current_prereqs" | grep -oP 'sudo apt -y install \K.*') - current_prereqs=$(echo "$current_prereqs" | xargs) fi -# Compare the current and source pre-requisites. Enforce a 1:1 match including order. +# 4) Grab the package list from the line +current_prereqs=$(echo "$current_prereqs" | xargs) + +# Compare the current and source pre-requisites. Enforce a 1:1 match including order for consistency. if [ "$current_prereqs" != "$src_prereqs" ]; then echo "ERROR: Pre-requisites do not match. Please update the pre-requisite file." echo "" From cc1716df9a846b909b8ec99da83083b105a62f26 Mon Sep 17 00:00:00 2001 From: Daniel McIlvaney Date: Thu, 14 Nov 2024 17:30:55 -0800 Subject: [PATCH 4/6] Clarify utility, support "mariner", auto-detect from /etc/os-release --- toolkit/scripts/prerequisites.sh | 11 +++++++---- toolkit/scripts/toolkit.mk | 9 +++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/toolkit/scripts/prerequisites.sh b/toolkit/scripts/prerequisites.sh index 4c12460847a..b6dcc47e4f4 100755 --- a/toolkit/scripts/prerequisites.sh +++ b/toolkit/scripts/prerequisites.sh @@ -9,11 +9,11 @@ prereq_md_path="" prereq_json_path="" function print_help { - echo "Pre-requisite installer. Installs azurelinux pre-requisites for the toolkit." + echo "Build prereq utility. Lists or validates pre-requisites for a given distro." echo "Usage:" - echo '[MANDATORY] -m PATH -> path to the pre-requisite md file' echo '[MANDATORY] -s PATH -> path to the src json file' - echo '[MANDATORY] -d DISTRO -> One of "azurelinux" or "ubuntu"' + echo '[MANDATORY] -d DISTRO -> One of "mariner", "azurelinux" or "ubuntu"' + echo '[OPTIONAL] -m PATH -> path to the pre-requisite md file, must be provided if not in print mode' echo '[OPTIONAL] -p -> print the canonical pre-requisite list and exit' echo '[OPTIONAL] -h -> print this help dialogue and exit' } @@ -47,11 +47,14 @@ if [ -z "$distro" ]; then exit 1 fi -if [ "$distro" != "azurelinux" ] && [ "$distro" != "ubuntu" ]; then +if [ "$distro" != "mariner" ] && [ "$distro" != "azurelinux" ] && [ "$distro" != "ubuntu" ]; then echo "ERROR: Invalid distro. Must be one of 'azurelinux' or 'ubuntu'." >&2 print_help exit 1 fi +if [ "$distro" == "mariner" ]; then + distro="azurelinux" +fi # Load the pre-requisite source json for the distro of interest # Json is of the form: diff --git a/toolkit/scripts/toolkit.mk b/toolkit/scripts/toolkit.mk index 32e33ef03df..6a8f4c6f89e 100644 --- a/toolkit/scripts/toolkit.mk +++ b/toolkit/scripts/toolkit.mk @@ -128,8 +128,13 @@ $(valid_arch_spec_names): $(go-specarchchecker) $(chroot_worker) $(local_specs) --log-file="$(valid_arch_spec_names_logs_path)" \ --log-color="$(LOG_COLOR)" -##help:target:install-azurelinux-prereqs=Install Azure Linux Prerequisites +##help:target:install-azurelinux-prereqs=Install build prerequisites, only supported on Mariner/AzureLinux. install-azurelinux-prereqs: - @echo "Installing Azure Linux Prerequisites" + @echo "Installing build prerequisites for AzureLinux..." + current_os=$$(grep '^ID=' /etc/os-release | cut -d'=' -f2-) && \ + if [ "$$current_os" != "mariner" ] && [ "$$current_os" != "azurelinux" ]; then \ + echo "This target is only supported on Mariner/AzureLinux." && \ + exit 1; \ + fi && \ prereqs="$$( $(SCRIPTS_DIR)/prerequisites.sh -s $(toolkit_root)/docs/building/prerequisites-src.json -d azurelinux -p )" && \ tdnf -y install $$prereqs From 5c18a29a497fde09c11d595e5e78c9d6f8d83fdb Mon Sep 17 00:00:00 2001 From: Daniel McIlvaney Date: Fri, 15 Nov 2024 10:42:35 -0800 Subject: [PATCH 5/6] drop old branches --- .github/workflows/check-prerequisites.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-prerequisites.yml b/.github/workflows/check-prerequisites.yml index 687c03476bb..104764a3570 100644 --- a/.github/workflows/check-prerequisites.yml +++ b/.github/workflows/check-prerequisites.yml @@ -7,9 +7,9 @@ name: Prerequisites Check on: push: - branches: [main, dev, 1.0*, 2.0*, 3.0*, fasttrack/*] + branches: [main, 2.0*, 3.0*, fasttrack/*] pull_request: - branches: [main, dev, 1.0*, 2.0*, 3.0*, fasttrack/*] + branches: [main, 2.0*, 3.0*, fasttrack/*] jobs: check: From 4127cf0b34aafa96f11d0484857510d28ef884ee Mon Sep 17 00:00:00 2001 From: Daniel McIlvaney Date: Fri, 15 Nov 2024 10:42:43 -0800 Subject: [PATCH 6/6] fix whitepsace --- toolkit/scripts/prerequisites.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolkit/scripts/prerequisites.sh b/toolkit/scripts/prerequisites.sh index b6dcc47e4f4..4a410bcd2d7 100755 --- a/toolkit/scripts/prerequisites.sh +++ b/toolkit/scripts/prerequisites.sh @@ -13,7 +13,7 @@ function print_help { echo "Usage:" echo '[MANDATORY] -s PATH -> path to the src json file' echo '[MANDATORY] -d DISTRO -> One of "mariner", "azurelinux" or "ubuntu"' - echo '[OPTIONAL] -m PATH -> path to the pre-requisite md file, must be provided if not in print mode' + echo '[OPTIONAL] -m PATH -> path to the pre-requisite md file, must be provided if not in print mode' echo '[OPTIONAL] -p -> print the canonical pre-requisite list and exit' echo '[OPTIONAL] -h -> print this help dialogue and exit' }