@@ -87,8 +87,8 @@ public static void addFailsafeMetadata(GoalMetadataProvider.Context context) {
8787 buildScanApi .tag ( "h2" );
8888 }
8989 else {
90- addDockerfileShortImageRef ( context ,
91- "database/%s.Dockerfile" .formatted ( dbKind ), null );
90+ addDockerfileMetadata ( context ,
91+ "database/%s.Dockerfile" .formatted ( dbKind ), dbKind , null , false );
9292 }
9393 }
9494 }
@@ -109,17 +109,22 @@ public static void addFailsafeMetadata(GoalMetadataProvider.Context context) {
109109 && ( explicitBackend == null || "elasticsearch" .equals ( explicitBackend ) )
110110 && !context .properties ().getBoolean ( "test.elasticsearch.skip" ) ) {
111111 var distribution = context .properties ().getString ( "test.elasticsearch.distribution" );
112- addDockerfileShortImageRef ( context ,
112+ addDockerfileMetadata ( context ,
113113 "search-backend/%s.Dockerfile" .formatted ( distribution ),
114- context .properties ().getString ( "test.elasticsearch.version" ) );
114+ "elastic" .equals ( distribution ) ? "elasticsearch" : distribution ,
115+ context .properties ().getString ( "test.elasticsearch.version" ), true );
115116 }
116117 }
117118
118- private static void addDockerfileShortImageRef (GoalMetadataProvider .Context context ,
119- String dockerfileRelativePath , String versionOverride ) {
119+ private static void addDockerfileMetadata (GoalMetadataProvider .Context context ,
120+ String dockerfileRelativePath , String tag , String versionOverride , boolean tagVersion ) {
120121 var buildScanApi = context .buildScan ();
121122 var path = Path .of ( context .metadata ().getSession ().getExecutionRootDirectory (),
122123 "build/container" , dockerfileRelativePath );
124+ if ( tag != null ) {
125+ // Tag without version
126+ buildScanApi .tag ( tag );
127+ }
123128 try {
124129 String ref ;
125130 try ( var stream = Files .lines ( path ) ) {
@@ -139,15 +144,19 @@ private static void addDockerfileShortImageRef(GoalMetadataProvider.Context cont
139144 if ( !Strings .isBlank ( versionOverride ) ) {
140145 ref = ref .substring ( 0 , ref .lastIndexOf ( ':' ) + 1 ) + versionOverride ;
141146 }
142- String shortImageRef = toShortImageRef ( ref );
143- buildScanApi .tag ( shortImageRef .replace ( ':' , '-' ) );
144- buildScanApi .value (
145- shortImageRef .substring ( 0 , shortImageRef .lastIndexOf ( ':' ) ),
146- ref .substring ( ref .lastIndexOf ( ':' ) + 1 )
147- );
147+ context .buildScanDeduplicatedValue ( "Container" , ref );
148+
149+ // Tag with version
150+ if ( tag != null && tagVersion ) {
151+ String shortImageRef = toShortImageRef ( ref );
152+ int colonIndex = shortImageRef .indexOf ( ':' );
153+ if ( colonIndex >= 0 ) {
154+ buildScanApi .tag ( tag + "-" + shortImageRef .substring ( colonIndex + 1 ) );
155+ }
156+ }
148157 }
149158 catch (RuntimeException | IOException e ) {
150- Log .warn ( "Unable to add tag from Dockerfile at %s: %s" .formatted ( path , e .getMessage () ) );
159+ Log .warn ( "Unable to add metadata from Dockerfile at %s: %s" .formatted ( path , e .getMessage () ) );
151160 }
152161 }
153162
0 commit comments