export interface IDockerImageParts { organization : string ; repository : string ; tag ? : string ; digest ? : string ; } export class DockerImageUtils { public static splitImageId ( imageId = '' ) { let imageParts ; if ( imageId . includes ( '@' ) ) { imageParts = imageId . split ( '@' ) ; } else { imageParts = imageId . split ( ':' ) ; } const repository = imageParts [ 0 ] ; const repositoryParts = repository . split ( '/' ) ; const organization = repositoryParts . slice ( 0 , - 1 ) . join ( '/' ) ; const lookup = imageParts . length > 1 ? imageParts . slice ( 1 ) . join ( ':' ) : '' ; let tag ; let digest ; if ( lookup ) { if ( lookup . startsWith ( 'sha256:' ) ) { digest = lookup ; } else { tag = lookup ; } } return { organization , repository , digest , tag } ; } public static generateImageId ( parts ) { if ( ! parts . repository || ! ( parts . digest || parts . tag ) ) { return undefined ; } let imageId ; if ( parts . digest ) { imageId = `${ parts . repository }@${ parts . digest }` ; } else { imageId = `${ parts . repository }:${ parts . tag }` ; } return imageId ; } }