Skip to content

Commit

Permalink
feat: added 9.4 versions and updated build.sh
Browse files Browse the repository at this point in the history
- Refactors depedencies check build.sh.
- Updates Oracle Linux 9 to 9.4 release.
- Updates Almalinux 9 to 9.4 release.
- Updates Rocky Linux 9 to 9.4 release.

Signed-off-by: Jared Burns <jared.burns@broadcom.com>
  • Loading branch information
burnsjared0415 authored and tenthirtyam committed May 20, 2024
1 parent a8f40d8 commit 0b3863e
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 83 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@

- Updates Red Hat Enterprise Linux 9 to 9.4 release.
[#925](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/925)
- Updates Oracle Linux 9 to 9.4 release.
[#927](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/927)
- Updates Almalinux 9 to 9.4 release.
[#927](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/927)
- Updates Rocky Linux 9 to 9.4 release.
[#927](https://github.com/vmware-samples/packer-examples-for-vsphere/pull/927)
- Removes CentOS Stream 8 from the project.

On 31 May 2024, CentOS Stream 8 reached the end of life.
Expand Down
12 changes: 12 additions & 0 deletions ansible/roles/base/tasks/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@
state: latest
when: ansible_distribution == 'AlmaLinux' and ansible_distribution_version | int >= 8 and enable_cloudinit == 'true'

- name: "Installing cloud-init."
command:
cmd: dnf install -y cloud-init
become: yes
when: enable_cloudinit == 'true' and ansible_distribution == 'Rocky'

- name: "Installing cloud-init."
command:
cmd: dnf install -y cloud-init
become: yes
when: enable_cloudinit == 'true' and ansible_distribution == 'OracleLinux'

- block:
- name: "Updating the operating system."
dnf:
Expand Down
225 changes: 156 additions & 69 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,121 @@ script_path=$(
cd "$(dirname "$(follow_link "$0")")"
pwd
)

run_check_dependencies=false
run_check_jq=false
run_check_packer=false
run_check_anisble=false
run_show_help=false

# This function prompts the user to press Enter to continue.
press_enter_continue() {
printf "Press \033[32mEnter\033[0m to continue.\n"
read -r
exec "$0"
}

# This function prompts the user to press Enter to exit.
press_enter_exit() {
printf "Press \033[31mEnter\033[0m to exit.\n"
read -r
exit 0
}

# Set config_path if it's not already set
if [ -z "$config_path" ]; then
config_path=$(
cd "${script_path}/config"
pwd
)
fi
# Set the default values for the variables.

# This function displays the information about the script and project.
info() {
project_name=$(get_project_info "name")
project_description=$(get_project_info "description")
project_version=$(get_project_info "version")
project_license=$(get_project_info "license[0].name")
project_github_url=$(get_project_info "urls.github")
project_docs_url=$(get_project_info "urls.documentation")
clear
printf "\033[32m$project_name\033[0m: \033[34m$project_version\033[0m\n\n"
printf "Copyright 2023-$(date +%Y) Broadcom. All Rights Reserved.\n\n"
printf "License: $project_license\n\n"
printf "$project_description\n\n"
printf "GitHub Repository: $project_github_url\n"
printf "Documentation: $project_docs_url\n\n"
show_help "continue"
press_enter
}

# This function displays the help message.
show_help() {
local exit_after=${1:-"exit"}
script_name=$(basename $0)
printf "Usage: $script_name [options]\n\n"
printf "Options:\n"
printf " --deps, -d, -D Check the dependencies.\n"
printf " --json, -j, -J Specify the JSON file path.\n"
printf " --show, -s, -S Display the build command used to build the image.\n"
printf " --help, -h, -H Display this help message.\n\n"
if [[ -z "$input" ]]; then
[ "$exit_after" = "exit" ] && exit 0
else
printf "Press \033[32mEnter\033[0m to continue."
fi
}

json_path="project.json"
os_names=$(jq -r '.os[] | .name' $json_path)
os_array=($os_names)
# Check for jq
check_jq() {
if ! command -v jq &>/dev/null; then
echo -e "\033[0;31m[✘]\033[0m jq is not installed."
exit 1
fi
}

check_ansible() {
cmd="ansible"
local deps_version=$(jq -r --arg cmd $cmd '.dependencies[] | select(.name == $cmd ) | .version_requirement' $json_path)
if ! command -v ansible &>/dev/null; then
echo -e "\033[0;31m[✘]\033[0m Ansible is not installed."
exit 1
else
installed_ansible_version=$(ansible --version | head -n 1 | awk '{print $3}' | tr -d '[]')
required_version=$(echo $deps_version | tr -d '>=' | xargs)
if [ "$(printf '%s\n' "$required_version" "$installed_ansible_version" | sort -V | head -n1)" != "$required_version" ]; then
echo -e "\033[0;31m[✘]\033[0m Packer version is incorrect. Expected $required_version, but got $installed_ansible_version."
exit 1
fi
fi
}


check_packer() {
cmd="packer"
local deps_version=$(jq -r --arg cmd $cmd '.dependencies[] | select(.name == $cmd ) | .version_requirement' $json_path)
if ! command -v $cmd &>/dev/null; then
echo -e "\033[0;31m[✘]\033[0m Packer is not installed."
exit 1
else
installed_packer_version=$(packer version | head -n 1 | awk '{print $2}' | tr -d 'v')
required_version=$(echo $deps_version | tr -d '>=' | xargs)
if [ "$(printf '%s\n' "$required_version" "$installed_packer_version" | sort -V | head -n1)" != "$required_version" ]; then
echo -e "\033[0;31m[✘]\033[0m Packer version is incorrect. Expected $required_version, but got $installed_packer_version."
exit 1
fi
fi
}

# Check if check_jq needs to be run
check_jq

# Check if check_ansible needs to be run
check_ansible

# Check if check_packer needs to be run
check_packer

check_command() {
cmd=$1
Expand Down Expand Up @@ -84,6 +188,55 @@ check_dependencies() {
fi
}

show_command=0
# Script options.
while (("$#")); do
case "$1" in
--json | -j | -J)
json_path="$2"
run_check_jq=true
shift 2
;;
--deps | -d | -D)
check_dependencies
shift
;;
--show | -s | -S)
show_command=1
shift
;;
--debug | -d | -D)
debug=1
debug_option="-debug"
shift
;;
--help | -h | -H)
run_show_help=true
show_help
shift
;;
*)
config_path=$(realpath "$1")
shift
;;
esac
done

# After the loop, check if show_help needs to be run
if $run_show_help; then
show_help
fi

if $run_check_dependencies; then
check_dependencies
fi

# Set the default values for the variables.
os_names=$(jq -r '.os[] | .name' $json_path)
os_array=($os_names)



# Get the project information from the JSON file.
get_project_info() {
local field=$1
Expand Down Expand Up @@ -145,41 +298,6 @@ press_enter() {
exec $0
}

# This function displays the information about the script and project.
info() {
project_name=$(get_project_info "name")
project_description=$(get_project_info "description")
project_version=$(get_project_info "version")
project_license=$(get_project_info "license[0].name")
project_github_url=$(get_project_info "urls.github")
project_docs_url=$(get_project_info "urls.documentation")
clear
printf "\033[32m$project_name\033[0m: \033[34m$project_version\033[0m\n\n"
printf "Copyright 2023-$(date +%Y) Broadcom. All Rights Reserved.\n\n"
printf "License: $project_license\n\n"
printf "$project_description\n\n"
printf "GitHub Repository: $project_github_url\n"
printf "Documentation: $project_docs_url\n\n"
show_help "continue"
press_enter
}

# This function displays the help message.
show_help() {
local exit_after=${1:-"exit"}
script_name=$(basename $0)
printf "Usage: $script_name [options]\n\n"
printf "Options:\n"
printf " --deps, -d, -D Check the dependencies.\n"
printf " --json, -j, -J Specify the JSON file path.\n"
printf " --show, -s, -S Display the build command used to build the image.\n"
printf " --help, -h, -H Display this help message.\n\n"
if [[ -z "$input" ]]; then
[ "$exit_after" = "exit" ] && exit 0
else
printf "Press \033[32mEnter\033[0m to continue."
fi
}

# This function prompts the user to go back or quit.
prompt_user() {
Expand Down Expand Up @@ -713,37 +831,6 @@ select_build() {
;;
esac
}
show_command=0
# Script options.
while (("$#")); do
case "$1" in
--json | -j | -J)
json_path="$2"
shift 2
;;
--deps | -d | -D)
check_dependencies
shift
;;
--show | -s | -S)
show_command=1
shift
;;
--debug | -d | -D)
debug=1
debug_option="-debug"
shift
;;
--help | -h | -H)
show_help
shift
;;
*)
config_path=$(realpath "$1")
shift
;;
esac
done

# Check if logging is enabled.
if [[ "$logging_enabled" == "true" ]]; then
Expand Down
4 changes: 2 additions & 2 deletions builds/linux/almalinux/9/linux-almalinux.pkrvars.hcl.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ vm_network_card = "vmxnet3"

// Removable Media Settings
iso_datastore_path = "iso/linux/almalinux"
iso_content_library_item = "AlmaLinux-9.3-x86_64-dvd"
iso_file = "AlmaLinux-9.3-x86_64-dvd.iso"
iso_content_library_item = "AlmaLinux-9.4-x86_64-dvd"
iso_file = "AlmaLinux-9.4-x86_64-dvd.iso"

// Boot Settings
vm_boot_order = "disk,cdrom"
Expand Down
6 changes: 3 additions & 3 deletions builds/linux/oracle/9/linux-oracle.pkrvars.hcl.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ vm_guest_os_keyboard = "us"
vm_guest_os_timezone = "UTC"
vm_guest_os_family = "linux"
vm_guest_os_name = "oracle"
vm_guest_os_version = "9.3"
vm_guest_os_version = "9.4"

// Virtual Machine Guest Operating System Setting
vm_guest_os_type = "other5xLinux64Guest"
Expand All @@ -35,8 +35,8 @@ vm_network_card = "vmxnet3"

// Removable Media Settings
iso_datastore_path = "iso/linux/oracle"
iso_content_library_item = "OracleLinux-R9-U3-x86_64-dvd"
iso_file = "OracleLinux-R9-U3-x86_64-dvd.iso"
iso_content_library_item = "OracleLinux-R9-U4-x86_64-dvd"
iso_file = "OracleLinux-R9-U4-x86_64-dvd.iso"

// Boot Settings
vm_boot_order = "disk,cdrom"
Expand Down
4 changes: 2 additions & 2 deletions builds/linux/rocky/9/linux-rocky.pkrvars.hcl.example
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ vm_network_card = "vmxnet3"

// Removable Media Settings
iso_datastore_path = "iso/linux/rocky"
iso_content_library_item = "Rocky-9.3-x86_64-dvd"
iso_file = "Rocky-9.3-x86_64-dvd.iso"
iso_content_library_item = "Rocky-9.4-x86_64-dvd"
iso_file = "Rocky-9.4-x86_64-dvd.iso"

// Boot Settings
vm_boot_order = "disk,cdrom"
Expand Down
14 changes: 7 additions & 7 deletions project.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@
"architectures": [
{
"architecture": "amd64",
"download_link": "https://download.rockylinux.org/pub/rocky/9/isos/x86_64/Rocky-9.3-x86_64-dvd.iso",
"download_link": "https://dl.rockylinux.org/vault/rocky/9.4/isos/x86_64/Rocky-9.4-x86_64-dvd.iso",
"checksum_algorithm": "sha256",
"checksum": "https://download.rockylinux.org/pub/rocky/9/isos/x86_64/CHECKSUM"
"checksum": "https://dl.rockylinux.org/vault/rocky/9.4/isos/x86_64/CHECKSUM"
}
],
"build_files": [
Expand Down Expand Up @@ -342,9 +342,9 @@
"architectures": [
{
"architecture": "amd64",
"download_link": "https://repo.almalinux.org/almalinux/9.3/isos/x86_64/AlmaLinux-9.3-x86_64-dvd.iso",
"download_link": "https://repo.almalinux.org/almalinux/9.4/isos/x86_64/AlmaLinux-9.4-x86_64-dvd.iso",
"checksum_algorithm": "sha256",
"checksum": "https://repo.almalinux.org/almalinux/9.3/isos/x86_64/CHECKSUM"
"checksum": "https://repo.almalinux.org/almalinux/9.4/isos/x86_64/CHECKSUM"
}
],
"build_files": [
Expand Down Expand Up @@ -403,9 +403,9 @@
"architectures": [
{
"architecture": "amd64",
"download_link": "https://yum.oracle.com/ISOS/OracleLinux/OL9/u3/x86_64/OracleLinux-R9-U3-x86_64-dvd.iso",
"download_link": "https://yum.oracle.com/ISOS/OracleLinux/OL9/u4/x86_64/OracleLinux-R9-U4-x86_64-dvd.iso",
"checksum_algorithm": "sha256",
"checksum": "https://linux.oracle.com/security/gpg/checksum/OracleLinux-R9-U3-Server-x86_64.checksum"
"checksum": "https://linux.oracle.com/security/gpg/checksum/OracleLinux-R9-U4-Server-x86_64.checksum"
}
],
"build_files": [
Expand Down Expand Up @@ -962,7 +962,7 @@
"name": "git",
"url": "https://git-scm.com/"
},
"version_requirement": ">= 2.45.0"
"version_requirement": ">= 2.43.0"
}
]
}

0 comments on commit 0b3863e

Please sign in to comment.