Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Commit

Permalink
Merge pull request #28 from mserranom/enhancement/issue-22-add-suppor…
Browse files Browse the repository at this point in the history
…t-private-images

add support for private images
  • Loading branch information
mserranom authored Jul 12, 2018
2 parents a0d88ad + c5ef39c commit 4e266c8
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 5 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -72,4 +77,4 @@ npm install && npm test

```bash
$ npm install && npm link
```
```
5 changes: 3 additions & 2 deletions src/bbrun.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
11 changes: 11 additions & 0 deletions src/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
10 changes: 10 additions & 0 deletions test/__snapshots__/integration.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 12 additions & 0 deletions test/templates/private-image-template.yml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 4e266c8

Please sign in to comment.