1- import { SpawnPromiseResult } from 'child-process -promise' ;
1+ import * as sleep from 'sleep -promise' ;
22
33import * as processWrapper from '../../common/process' ;
44import * as config from '../../common/config' ;
@@ -33,7 +33,7 @@ function prefixRespository(target: string, type: SkopeoRepositoryType): string {
3333export async function pull (
3434 image : string ,
3535 destination : string ,
36- ) : Promise < SpawnPromiseResult > {
36+ ) : Promise < void > {
3737 const creds = await credentials . getSourceCredentials ( image ) ;
3838 const credentialsParameters = getCredentialParameters ( creds ) ;
3939
@@ -43,7 +43,24 @@ export async function pull(
4343 args . push ( { body : prefixRespository ( image , SkopeoRepositoryType . ImageRegistry ) , sanitise : false } ) ;
4444 args . push ( { body : prefixRespository ( destination , SkopeoRepositoryType . DockerArchive ) , sanitise : false } ) ;
4545
46- return processWrapper . exec ( 'skopeo' , ...args ) ;
46+ await pullWithRetry ( args ) ;
47+ }
48+
49+ async function pullWithRetry ( args : Array < processWrapper . IProcessArgument > ) : Promise < void > {
50+ const MAX_ATTEMPTS = 10 ;
51+ const RETRY_INTERVAL_SEC = 0.2 ;
52+
53+ for ( let attempt = 1 ; attempt <= MAX_ATTEMPTS ; attempt ++ ) {
54+ try {
55+ await processWrapper . exec ( 'skopeo' , ...args ) ;
56+ return ;
57+ } catch ( err ) {
58+ if ( attempt + 1 > MAX_ATTEMPTS ) {
59+ throw err ;
60+ }
61+ await sleep ( RETRY_INTERVAL_SEC * 1000 ) ;
62+ }
63+ }
4764}
4865
4966export function getCredentialParameters ( credentials : string | undefined ) : Array < processWrapper . IProcessArgument > {
0 commit comments