diff --git a/README.md b/README.md index 5d22488..3bfdb42 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Bitbucket Pipelines Runner -`bbrun` is a command line tool to execute [Bitbucket Pipelines](https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html) locally. -[![Build Status](https://travis-ci.org/mserranom/bbrun.svg?branch=master)](https://travis-ci.org/mserranom/bbrun) +`bbrun` is a command line tool to execute [Bitbucket Pipelines](https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html) locally. +[![Build Status](https://travis-ci.org/mserranom/bbrun.svg?branch=master)](https://travis-ci.org/mserranom/bbrun) ## Install @@ -62,6 +62,11 @@ hello world! $ bbrun test --env "EDITOR=vim, USER=root" ``` +## Caveats + +- Not all Bitbucket features are covered, check [open issues](https://github.com/mserranom/bbrun/issues) for an overview of the roadmap. +- [Private images](https://confluence.atlassian.com/bitbucket/use-docker-images-as-build-environments-792298897.html) are supported, but the user has to login in the Docker Registry before executing `bbrun` (thus credentials in the file are ignored). + ## Build and Test ```bash @@ -72,4 +77,4 @@ npm install && npm test ```bash $ npm install && npm link -``` \ No newline at end of file +``` diff --git a/src/bbrun.js b/src/bbrun.js index 448effa..3c38f26 100644 --- a/src/bbrun.js +++ b/src/bbrun.js @@ -36,9 +36,10 @@ module.exports = function(options, stepName) { `"script" section not found in step:\n${JSON.stringify(step, null, 4)}` ); const dockerImage = step.image || image; + const imageName = docker.extractImageName(dockerImage); console.log( - `executing step${stepName ? ` "${stepName}"` : ""} in "${dockerImage}"` + `executing step${stepName ? ` "${stepName}"` : ""} in "${imageName}"` ); - exec(step.script, dockerImage, options); + exec(step.script, imageName, options); } }; diff --git a/src/docker.js b/src/docker.js index d242fab..6b4ffff 100644 --- a/src/docker.js +++ b/src/docker.js @@ -50,5 +50,16 @@ function run(commands, image, dryRun, interactive, workDir) { } } +function extractImageName(image) { + if (typeof image === "string" || image instanceof String) { + return image; + } else if (image.name) { + return image.name; + } else { + throw new Error(`"${JSON.stringify(image)}" is not a valid image`); + } +} + module.exports.checkExists = checkExists; module.exports.run = run; +module.exports.extractImageName = extractImageName; diff --git a/test/__snapshots__/integration.test.js.snap b/test/__snapshots__/integration.test.js.snap index 8fd71fd..fae9a12 100644 --- a/test/__snapshots__/integration.test.js.snap +++ b/test/__snapshots__/integration.test.js.snap @@ -39,6 +39,16 @@ build script: " `; +exports[`should resolve private image names 1`] = ` +"executing step in \\"account-name/openjdk:8\\" +docker command: + docker run -P -v PWD:/ws -w /ws account-name/openjdk:8 sh .bbrun.sh +build script: + set -e + echo \\"testing stuff\\" +" +`; + exports[`single step pipeline executes the default step with no arguments 1`] = ` "executing step in \\"ubuntu\\" docker command: diff --git a/test/integration.test.js b/test/integration.test.js index cf67488..8aff45a 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -52,6 +52,15 @@ it("no image template should use default atlassian image", () => { expect(res.code).toBe(0); }); +it("should resolve private image names", () => { + const res = run( + "--template test/templates/private-image-template.yml --dry-run" + ); + expect(norm(res.stdout)).toMatchSnapshot(); + expect(res.stderr).toBe(""); + expect(res.code).toBe(0); +}); + describe("template with multiple steps in the default pipeline", () => { it("should execute all the default steps when no argument is provided", () => { const res = run( diff --git a/test/templates/private-image-template.yml b/test/templates/private-image-template.yml new file mode 100644 index 0000000..9781e93 --- /dev/null +++ b/test/templates/private-image-template.yml @@ -0,0 +1,12 @@ +pipelines: + default: + - step: + name: test + image: + name: account-name/openjdk:8 + username: $DOCKER_HUB_USERNAME + password: $DOCKER_HUB_PASSWORD + email: $DOCKER_HUB_EMAIL + script: + - echo "testing stuff" + \ No newline at end of file