Skip to content
This repository has been archived by the owner on Jul 13, 2020. It is now read-only.

Commit

Permalink
Add builderPath option
Browse files Browse the repository at this point in the history
All user to supply optional builder path relative to project base
directory for both docker and kaniko builds.

Increment minor version since this is a new feature.

Closes #42
  • Loading branch information
David Dooling committed Apr 8, 2019
1 parent ace778c commit 691b933
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions lib/docker/executeDockerBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ export interface DockerOptions {
* Optional arguments passed to the docker image builder
*/
builderArgs?: string[];

/**
* Path relative to base of project to build. If not provided,
* ".", i.e., the project base directory, is used.
*/
builderPath?: string;
}

export type DockerImageNameCreator = (p: GitProject,
Expand All @@ -113,6 +119,7 @@ export function executeDockerBuild(options: DockerOptions): ExecuteGoal {
const { goalEvent, context, project } = gi;

const optsToUse = mergeOptions<DockerOptions>(options, {}, "docker.build");
optsToUse.builderPath = (optsToUse.builderPath) ? optsToUse.builderPath : ".";

switch (optsToUse.builder) {
case "docker":
Expand Down Expand Up @@ -141,7 +148,7 @@ export function executeDockerBuild(options: DockerOptions): ExecuteGoal {

result = await gi.spawn(
"docker",
["build", "-f", dockerfilePath, ...tags, ...optsToUse.builderArgs, "."],
["build", "-f", dockerfilePath, ...tags, ...optsToUse.builderArgs, optsToUse.builderPath],
{
env: {
...process.env,
Expand Down Expand Up @@ -186,9 +193,10 @@ export function executeDockerBuild(options: DockerOptions): ExecuteGoal {
builderArgs.push(`--cache-dir=${baseImageCache}`, "--cache=true");
}

const kanikoContext = `dir://${project.baseDir}` + ((optsToUse.builderPath === ".") ? "" : `/${optsToUse.builderPath}`);
result = await gi.spawn(
"/kaniko/executor",
["--dockerfile", dockerfilePath, "--context", `dir://${project.baseDir}`, ..._.uniq(builderArgs)],
["--dockerfile", dockerfilePath, "--context", kanikoContext, ..._.uniq(builderArgs)],
{
env: {
...process.env,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@atomist/sdm-pack-docker",
"version": "1.1.1",
"version": "1.2.0",
"description": "Extension Pack for an Atomist SDM to integrate Docker",
"author": {
"name": "Atomist",
Expand Down

0 comments on commit 691b933

Please sign in to comment.