Skip to content
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

Sean simmons progress/chef 15585 omnitruck amazon2 fix #612

Merged
Merged
Show file tree
Hide file tree
Changes from 13 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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ There are two parts to running omnitruck.

First, you need to populate its cache. Redis is used for the cache, and you will want to have a redis server running beforehand:

## Docker file
```docker
docker pull redis:7.4.0-alpine3.20

then to run it:
docker run --cpus 4 --memory 8g -it --privileged -p LOCAL_IP:6379:6379 IMAGE_NAME_OR_HASH
ex: docker run --cpus 4 --memory 8g -it --privileged -p 172.20.0.178:6379:6379 --volume $(pwd):/home 7de0dedd123b8cb2b105ace4e8d00b8bba5ad7be39617dfa229acff315fe4fbf
```

```bash
# Choose the following to install redis based on your OS
brew install redis
Expand All @@ -167,6 +176,8 @@ apt-get install redis
redis-server
```

Then follow directions in [Updating Mock Data](https://github.com/chef/omnitruck?tab=readme-ov-file#updating-mock-data)

In production the cache populating is handled by a cron job. For development, you need to do this manually:

```bash
Expand Down Expand Up @@ -207,6 +218,9 @@ bundle exec unicorn
```
2. Update the latest version methods in `spec/spec_helper.rb`
3. Update any tests that may no longer be accurate. This is especially true for tests that expect a specific package or package version to exist in the current channel. Artifacts in the current channel expire after a certain time, so tests may become invalid.
4. once all the data in the spec/data folder is downloaded (fyi this takes A LONG time if the file is out of date)
5. load the data into your local running redis server by dropping to root and running `ruby redisManual.rb`
1. this is still a WIP, the format that the file is in now does load the data into the format that is expected.

## License

Expand Down
114 changes: 61 additions & 53 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,31 @@ class InvalidChannelName < StandardError; end
param :p, String, required: true
param :pv, String, required: true
param :m, String, required: true


# Get package information
package_info = get_package_info
redirect package_info["url"]

# Grab org url
original_url = package_info["url"]

# Debug output of original URL
# puts "Debug Info - Original URL: #{original_url}"

# amazon 2 rewrite nonsense
if original_url.include?("/amazon/2023/") && params[:pv] == "2"
# Rewrite the URL for Amazon Linux 2
rewritten_url = original_url
.gsub(/\/amazon\/2023\//, "/amazon/2/")
.gsub(/.amazon2023/, ".amazon2")

# uncomment for debug
# puts "Debug Info - Rewritten URL: #{rewritten_url}"

redirect rewritten_url
else
# Redirect to the original URL if no rewrite needed
redirect original_url
end
end

get /(?<channel>\/[\w]+)?\/(?<project>[\w-]+)\/metadata\/?$/ do
Expand Down Expand Up @@ -388,27 +410,21 @@ def get_package_info
current_platform = params['p']
current_platform_version = params['pv']
current_arch = params['m']

current_version = params['v']
# Create VersionResolver here to take advantage of #parse_version_string
# method which is called in the constructor. This will return nil or an Opscode::Version instance
opscode_version = Chef::VersionResolver.new(
params['v'],
current_version,
cache.manifest_for(current_project, channel),
channel,
current_project
).target_version

# Set ceiling version if nil in place of latest version. This makes comparisons easier.
opscode_version = Opscode::Version.parse('999.999.999') if opscode_version.nil?

# Windows artifacts require special handling
# 1) If no architecture is provided we default to i386
# 2) Internally we always use i386 to represent 32-bit artifacts, not i686
# Windows artifacts require special handling (as before)
current_arch = if params["p"] == "windows" &&
(current_arch.nil? || current_arch.empty? || current_arch == "i686")
"i386"
else
# Map `uname -m` returned architectures into our internal representations
case current_arch
when *%w{ arm64 aarch64 } then 'aarch64'
when *%w{ x86_64 amd64 x64 } then 'x86_64'
Expand All @@ -417,60 +433,52 @@ def get_package_info
else current_arch
end
end

# SLES/SUSE requests may need to be modified before returning metadata.
# If s390x architecture is requested we never modify the metadata.
# Output current environment details for debugging purposes
# puts "*****************"
# puts "Current Project: #{current_project}"
# puts "Current Platform: #{current_platform}"
# puts "Current Platform Version: #{current_platform_version}"
# puts "Current Architecture: #{current_arch}"
# puts "Current Version: #{current_version}"
# puts "*****************"
remap_to_el = false
# Handle SLES/SUSE as before (this section remains unchanged)
if %{sles suse opensuse-leap}.include?(current_platform) && current_arch != "s390x"
current_platform = 'sles'
# Here we map specific project versions that started building
# native SLES packages. This is used to determine which projects
# need to be remapped to EL before a certain version.
native_sles_project_version = OmnitruckDist::SLES_PROJECT_VERSIONS

# Locate native sles version for project if it exists
sles_project_version = native_sles_project_version[current_project]

remap_to_el = false

# If sles_project_version is nil (no projects listed with a native SLES version)
# then always remap to EL
if sles_project_version.nil?
remap_to_el = true
# If requested project version is a partial version then we parse new versions
# using high version limits to simulate latest version for given values
elsif opscode_version.mixlib_version.is_a?(Opscode::Version::Incomplete)
opscode_version = if opscode_version.minor.nil?
# Parse with high minor and patch versions
Opscode::Version.parse("#{opscode_version.major}.9999.9999")
else
# Parse with high patch version
Opscode::Version.parse("#{opscode_version.major}.#{opscode_version.minor}.9999")
end
# If the new parsed version is less than the native sles version then remap
remap_to_el = true if opscode_version < Opscode::Version.parse(sles_project_version)
# If requested version is a SemVer do a simple compare
elsif opscode_version < Opscode::Version.parse(sles_project_version)
remap_to_el = true
remap_to_el = true if sles_project_version.nil? || opscode_version < Opscode::Version.parse(sles_project_version)
end
# Amazon-specific logic, this is so dirty, needs cleaning.
if current_platform == "amazon" && current_platform_version == "2"
product_version_threshold = Opscode::Version.parse("15.10.12")
puts "Requested product version: #{opscode_version}"
if opscode_version >= product_version_threshold
puts "Requested version is >= 15.10.12. Keeping platform as Amazon with version 2."
current_platform = "amazon"
current_platform_version = "2"
remap_to_el = false # Ensure remap_to_el is disabled for Amazon Linux 2 and versions >= 15.10.12
else
remap_to_el = false
puts "Requested version is < 15.10.12. Remapping to EL."
remap_to_el = true
end
end

# Remap to el if triggered
# Only remap to EL if remap_to_el is true, and it isn't Amazon Linux 2 with version >= 15.10.12
if remap_to_el
current_platform_version = if current_platform == "amazon" && current_platform_version == "2"
"7"
else
current_platform_version.to_f <= 11 ? "5" : "6"
end
current_platform = "el"
current_platform_version = current_platform_version.to_f <= 11 ? "5" : "6"
end

# We need to manage automate/delivery this in this method, not #project.
# If we try to handle this in #project we have to make an assumption to
# always return automate results when the VERSIONS api is called for delivery.
end
# Handle automate/delivery based on version
if %w{automate delivery}.include?(project)
current_project = opscode_version < Opscode::Version.parse('0.7.0') ? 'delivery' : 'automate'
end

# Return the package info using the updated current values
Chef::VersionResolver.new(
params['v'],
current_version,
cache.manifest_for(current_project, channel),
channel,
current_project
Expand Down Expand Up @@ -587,4 +595,4 @@ def prepare_install_sh
def prepare_install_ps1
Mixlib::Install.install_ps1(base_url: url(settings.virtual_path).chomp('/'))
end
end
end
69 changes: 34 additions & 35 deletions lib/chef/version_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,53 +101,52 @@ def package_list
# Finds the raw metadata info for the given platform, platform_version
# and machine_architecture
def find_raw_metadata_for(target_platform, target_architecture)
# omnitruck has some core platforms like ubuntu, windows, ...
# and some secondary platforms that map onto core platforms like linuxmint, scientific
# mapped_name will return the original name if it is not mapped
core_platform = target_platform.mapped_name

# first make sure we have some builds available for the given platform
if !build_map[core_platform]
raise InvalidDownloadPath, "Cannot find any #{OmnitruckDist::CLIENT_NAME} versions for core platform #{core_platform}: #{friendly_error_msg}"
# Debug information
puts "Debug Info - Core Platform: #{core_platform}"
# puts "Debug Info - Build Map: #{build_map.inspect}"
# Check for the existence of builds
unless build_map[core_platform]
raise InvalidDownloadPath, "Cannot find any versions for core platform #{core_platform}: #{friendly_error_msg}"
end

# get all the available distro versions
# Collect available distro versions
distro_versions_available = build_map[core_platform].keys

# if core_platform is amazon then remove versions less than 2022 because they are remapped to RHEL versions
# and should not be eligible for consideration
distro_versions_available.delete_if{ |v| v.to_i < 2022 } if core_platform == "amazon"

# select only the packages from the distro versions that are <= the version we are looking for
# we do not want to select el7 packages for el6 platform
distro_versions_available.select! {|v| dsl.new_platform_version(core_platform, v, target_architecture) <= target_platform }

if distro_versions_available.length == 0
raise InvalidDownloadPath, "Cannot find any available #{OmnitruckDist::CLIENT_NAME} versions for this platform version #{target_platform.mapped_name} #{target_platform.mapped_version}: #{friendly_error_msg}"
# Remove versions that are less than 2022 if the platform is amazon
distro_versions_available.delete_if { |v| v.to_i < 2022 } if core_platform == "amazon"
vkarve-chef marked this conversation as resolved.
Show resolved Hide resolved
# Debug information
# puts "Debug Info - Available Distro Versions: #{distro_versions_available.inspect}"
# Ensure valid version mapping
filtered_versions = distro_versions_available.select do |v|
if core_platform == "amazon"
# Include Amazon Linux 2 explicitly
v == "2" || v == "2023"
else
# Map and filter other versions
mapped_version = dsl.new_platform_version(core_platform, v, target_architecture)
mapped_version <= target_platform
end
end

# sort the available distro versions from earlier to later: 10.04 then 10.10 etc.
distro_versions_available.sort! {|v1,v2| dsl.new_platform_version(core_platform, v1, target_architecture) <=> dsl.new_platform_version(core_platform, v2, target_architecture) }

# Now filter out the metadata based on architecture
raw_metadata = { }
distro_versions_available.each do |version|
# Debug information
puts "Debug Info - Filtered Distro Versions: #{filtered_versions.inspect}"
if filtered_versions.empty?
raise InvalidDownloadPath, "Cannot find any available versions for this platform version #{target_platform.mapped_name} #{target_platform.mapped_version}: #{friendly_error_msg}"
end
raw_metadata = {}
filtered_versions.each do |version|
l_target_arch = target_architecture

# Debug information
puts "Debug Info - Processing Version: #{version}"
# puts "Debug Info - Available Metadata: #{build_map[core_platform][version].inspect}"
if build_map[core_platform][version][target_architecture].nil?
next if target_platform.fallback_arch.nil?
next if build_map[core_platform][version][target_platform.fallback_arch].nil?

l_target_arch = target_platform.fallback_arch
end

# Note that we do not want to make a deep merge here. We want the
# information coming from the build_map override the ones that are
# already in raw_metadata because we have sorted
# distro_versions_available and the later ones will be the correct ones.
# Merge metadata
raw_metadata.merge!(build_map[core_platform][version][l_target_arch])
end

# Debug information
puts "Debug Info - Raw Metadata: #{raw_metadata.inspect}"
raw_metadata
end

Expand Down
36 changes: 29 additions & 7 deletions platforms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,49 @@

platform "amazon" do
remap do |opts|
# map "version 1" amazon linux and amazon linux 2 to RHEL
if /201\d\.\d/.match?(opts[:version]) || opts[:version] == "2"
if opts[:version] == "2"
"amazon" # Ensure Amazon Linux 2 is not mapped to "el"
elsif /201\d\.\d/.match?(opts[:version])
"el"
else
"amazon"
end
end

version_remap do |opts|
if /201\d\.\d/.match?(opts[:version])
# map "version 1" amazon linux to RHEL 6. These are named by the year/month ubuntu style
"6"
elsif opts[:version] == "2"
# map Amazon Linux 2 to RHEL 7
if opts[:version] == "2"
"7"
elsif /201\d\.\d/.match?(opts[:version])
"6"
else
opts[:version]
end
end
end

# platform "amazon" do
# remap do |opts|
# # map "version 1" amazon linux and amazon linux 2 to RHEL
# if /201\d\.\d/.match?(opts[:version]) || opts[:version] == "2"
# "el"
# else
# "amazon"
# end
# end

# version_remap do |opts|
# if /201\d\.\d/.match?(opts[:version])
# # map "version 1" amazon linux to RHEL 6. These are named by the year/month ubuntu style
# "6"
# elsif opts[:version] == "2"
# # map Amazon Linux 2 to RHEL 7
# "7"
# else
# opts[:version]
# end
# end
# end

# Unsupported Variants
#
platform "xenserver" do
Expand Down
Loading