Skip to content

Commit 6b9d42a

Browse files
committed
Make components info command compatible with new versioning schema
1 parent 27710ba commit 6b9d42a

2 files changed

Lines changed: 55 additions & 8 deletions

File tree

lib/pyxis/commands/components.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,25 @@ class Components < Thor
66
include PermissionHelper
77

88
desc 'info', 'Get the component versions for a reticulum build'
9-
method_option :build, aliases: '-b', desc: 'The build ID', required: true, type: :numeric
9+
method_option :build,
10+
aliases: '-b',
11+
desc: 'The build ID',
12+
required: false,
13+
type: :numeric
14+
method_option :container_tag,
15+
aliases: '-c',
16+
desc: 'The container tag excluding variant modifiers',
17+
required: false,
18+
type: :string
1019
def info
11-
component_versions = ManagedVersioning::ComponentInfo.new(options[:build]).execute
20+
if options[:build].nil? == options[:container_tag].nil?
21+
raise Pyxis::MessageError, 'Only one of build or container_tag must be given'
22+
end
23+
24+
component_versions = ManagedVersioning::ComponentInfo.new(
25+
build_id: options[:build],
26+
container_tag: options[:container_tag]
27+
).execute
1228

1329
raise Pyxis::MessageError, 'This build does not exist' if component_versions.nil?
1430

lib/pyxis/managed_versioning/component_info.rb

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@ module ManagedVersioning
55
class ComponentInfo
66
include SemanticLogger::Loggable
77

8-
attr_reader :build_id
8+
attr_reader :build_id, :container_tag
99

10-
def initialize(build_id)
10+
def initialize(build_id: nil, container_tag: nil)
1111
@build_id = build_id
12+
@container_tag = container_tag
1213
end
1314

1415
def execute
16+
unless container_tag.nil?
17+
@build_id = annotation_for(
18+
'code0-tech/reticulum/ci-builds/mise',
19+
container_tag,
20+
'tech.code0.reticulum.pipeline.id'
21+
)
22+
end
23+
24+
return nil if build_id.nil?
25+
1526
pipeline = GitlabClient.client.get_json(
1627
"/api/v4/projects/#{Project::Reticulum.api_gitlab_path}/pipelines/#{build_id}"
1728
)
@@ -22,6 +33,8 @@ def execute
2233
"/api/v4/projects/#{Project::Reticulum.api_gitlab_path}/pipelines/#{build_id}/jobs"
2334
)
2435

36+
container_version = find_container_version(jobs)
37+
2538
manifests = find_manifests(jobs)
2639

2740
components = {
@@ -32,9 +45,13 @@ def execute
3245
component = image.first.to_sym
3346
next if components.key?(component)
3447

35-
image_tag = image.length == 1 ? build_id : "#{build_id}-#{image.last}"
48+
image_tag = image.length == 1 ? container_version : "#{container_version}-#{image.last}"
3649

37-
components[component] = revision_for("code0-tech/reticulum/ci-builds/#{component}", image_tag)
50+
components[component] = annotation_for(
51+
"code0-tech/reticulum/ci-builds/#{component}",
52+
image_tag,
53+
'org.opencontainers.image.version'
54+
)
3855
end
3956

4057
components.compact
@@ -60,7 +77,7 @@ def token_for(image)
6077
response.body.token
6178
end
6279

63-
def revision_for(image, tag)
80+
def annotation_for(image, tag, annotation)
6481
token = token_for(image)
6582

6683
response = ghcr_client.get_json(
@@ -74,7 +91,7 @@ def revision_for(image, tag)
7491

7592
logger.warn('Failed to retrieve tag for image', image: image, tag: tag) unless response.response.status == 200
7693

77-
response.body.annotations&.[]('org.opencontainers.image.version')
94+
response.body.annotations&.[](annotation)
7895
end
7996

8097
def find_manifests(jobs)
@@ -89,6 +106,20 @@ def find_manifests(jobs)
89106
[image.first, image.last.delete_prefix('[').delete_suffix(']')]
90107
end
91108
end
109+
110+
def find_container_version(jobs)
111+
job = jobs.find { |job| job['name'] == 'generate-environment' }
112+
return build_id if job.nil? # fallback to build_id if job not found
113+
114+
trace = GitlabClient.client.get(
115+
"/api/v4/projects/#{Project::Reticulum.api_gitlab_path}/jobs/#{job['id']}/trace"
116+
)
117+
trace.body
118+
.lines
119+
.drop_while { |line| !(line.include?('section_start') && line.include?('glpa_summary')) }
120+
.find { |line| line =~ /RETICULUM_CONTAINER_VERSION=[0-9a-zA-Z-.]+$/ }
121+
.split('=')[1].chomp
122+
end
92123
end
93124
end
94125
end

0 commit comments

Comments
 (0)