@@ -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
94125end
0 commit comments