public static int getNumberOfDependentLayers ( String imageContent ) throws IOException { JsonNode history = Utils . mapper ( ) . readTree ( imageContent ) . get ( "history" ) ; if ( history == null ) { throw new IllegalStateException ( "Could not find 'history' tag" ) ; } int layersNum = history . size ( ) ; boolean newImageLayers = true ; for ( int i = history . size ( ) - 1 ; i >= 0 ; i -- ) { if ( newImageLayers ) { layersNum -- ; } JsonNode layer = history . get ( i ) ; JsonNode emptyLayer = layer . get ( "empty_layer" ) ; if ( ! newImageLayers && emptyLayer != null ) { layersNum -- ; } if ( layer . get ( "created_by" ) == null ) { continue ; } String createdBy = layer . get ( "created_by" ) . textValue ( ) ; if ( createdBy . contains ( "ENTRYPOINT" ) || createdBy . contains ( "MAINTAINER" ) ) { newImageLayers = false ; } } return layersNum ; }
Returns number of dependencies layers in the image .