Skip to content

Commit

Permalink
Merge pull request #172 from dmvict/docker_images
Browse files Browse the repository at this point in the history
READY: Add support of Docker registry images
  • Loading branch information
dmvict authored Oct 29, 2024
2 parents 27b285a + 98eb52a commit 4f25ee4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ It is a cause of failed jobs. For this case, the action `wretry.action` can retr
## Features

- Retries Github `JavaScript` actions.
- Retries `GitHub Docker` actions utilizing a `Dockerfile` as the image source.
- Retries `GitHub Docker` actions utilizing a `Dockerfile`'s and Docker registry image as the source.
- Retries private actions. The option `github_token` is used for private repositories.
- The action can be an action repository that is not published on `Marketplace`.
- Retries shell commands. Uses default shells to run commands.
Expand Down
3 changes: 3 additions & 0 deletions main/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ inputs:
command:
description: 'Command to run. Should be defined action or command, not both.'
required: false
pre_retry_command:
description: 'Command to run between retries.'
required: false
with:
description: 'An options map for Github action'
required: false
Expand Down
3 changes: 3 additions & 0 deletions post/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ inputs:
command:
description: 'Command to run. Should be defined action or command, not both.'
required: false
pre_retry_command:
description: 'Command to run between retries.'
required: false
with:
description: 'An options map for Github action'
required: false
Expand Down
3 changes: 3 additions & 0 deletions pre/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ inputs:
command:
description: 'Command to run. Should be defined action or command, not both.'
required: false
pre_retry_command:
description: 'Command to run between retries.'
required: false
with:
description: 'An options map for Github action'
required: false
Expand Down
34 changes: 27 additions & 7 deletions src/Docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,31 @@ function imageBuild( actionPath, image )
+ 'and select valid workflow runner.'
);

if( image === 'Dockerfile' )
const actionName = _.path.name( actionPath );
const imageName = `${ actionName }_repo:${ actionName }_tag`.toLowerCase();

if( _.uri.isGlobal( image ) )
{
const parsed = _.uri.parse( image );
const publicDockerImage = parsed.longPath;
const pullCommand = `docker image pull ${ publicDockerImage }`;
const pull = execSyncNonThrowing( pullCommand );
if( _.error.is( pull ) )
throw _.error.brief( pull );

const tagCommand = `docker image tag ${ publicDockerImage } ${ imageName }`;
const tagging = execSyncNonThrowing( tagCommand );
if( _.error.is( tagging ) )
throw _.error.brief( tagging );

core.info( `Docker image : ${ publicDockerImage }.` );
core.info( pullCommand );
core.info( pull.toString() );
core.info( tagCommand );
}
else if( _.str.ends( image, 'Dockerfile' ) && _.path.isRelative( image ) )
{
const actionName = _.path.name( actionPath );
const imageName = `${ actionName }_repo:${ actionName }_tag`.toLowerCase();
const dockerfilePath = _.path.nativize( _.path.join( actionPath, 'Dockerfile' ) );
const dockerfilePath = _.path.nativize( _.path.join( actionPath, image ) );
const command = `docker build -t ${ imageName } -f ${ dockerfilePath } ${ _.path.nativize( actionPath ) }`;
const build = execSyncNonThrowing( command );
if( _.error.is( build ) )
Expand All @@ -67,16 +87,16 @@ function imageBuild( actionPath, image )
core.info( `Dockerfile for action : ${ dockerfilePath }.` );
core.info( command );
core.info( build.toString() );

return imageName;
}

else
_.sure
(
false,
`The action does not support requested Docker image type "${ image }".`
+ '\nPlease, open an issue with the request for the feature.'
);

return imageName;
}

//
Expand Down
7 changes: 6 additions & 1 deletion test/Docker.test.s
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ function exists( test )
exists.timeOut = 15000;

//

function imageBuild( test )
{
const ubuntuIs = process.env.ImageOS && _.str.begins( process.env.ImageOS, 'ubuntu' );
Expand All @@ -75,6 +74,10 @@ function imageBuild( test )
var got = docker.imageBuild( a.routinePath, 'Dockerfile' );
test.identical( got, 'imagebuild_repo:imagebuild_tag' );

test.case = 'pull an image';
var got = docker.imageBuild( a.routinePath, 'docker://ghcr.io/pytooling/releaser' );
test.identical( got, 'imagebuild_repo:imagebuild_tag' );

/* - */

if( !Config.debug )
Expand All @@ -90,6 +93,8 @@ function imageBuild( test )
test.shouldThrowErrorSync( () => docker.imageBuild( a.routinePath, 'wrong:image' ), onResolve );
}

imageBuild.timeOut = 60000;

//

function commandArgsFrom( test )
Expand Down

0 comments on commit 4f25ee4

Please sign in to comment.