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

Commit

Permalink
Fix up push enablement
Browse files Browse the repository at this point in the history
  • Loading branch information
cdupuis committed Jan 11, 2019
1 parent 6f328d1 commit d2a1032
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/docker/DockerBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class DockerBuild extends FulfillableGoalWithRegistrations<DockerBuildReg
}

public with(registration: DockerBuildRegistration): this {
const optsToUse = mergeOptions<DockerOptions>(DefaultDockerOptions, registration.options, "sdm.docker.build");
const optsToUse = mergeOptions<DockerOptions>(DefaultDockerOptions, registration.options, "docker.build");

// Backwards compatibility
// tslint:disable:deprecation
Expand Down Expand Up @@ -105,7 +105,7 @@ const DockerBuildDefinition: GoalDefinition = {
export function mergeOptions<OPTIONS>(defaults: OPTIONS, explicit: OPTIONS, configurationPath?: string): OPTIONS {
const options: OPTIONS = _.merge(defaults, explicit || {});
if (!!configurationPath) {
const configurationOptions = configurationValue<OPTIONS>(configurationPath) || {};
const configurationOptions = configurationValue<OPTIONS>(`sdm.${configurationPath}`) || {};
return _.merge(options, configurationOptions);
}
return options;
Expand Down
36 changes: 23 additions & 13 deletions lib/docker/executeDockerBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,19 @@ export function executeDockerBuild(options: DockerOptions): ExecuteGoal {

} else if (options.builder === "kaniko") {
// 2. run kaniko build
const builderArgs = options.builderArgs.length > 0 ? options.builderArgs : ["--cache=true", "--snapshotMode=time", "--reproducible"];
const tags = _.flatten(images.map(i => ["-d", i]));
const builderArgs: string[] = [];

if (await pushEnabled(gi, options)) {
builderArgs.push(..._.flatten(images.map(i => ["-d", i])), "--cache=true");
} else {
builderArgs.push("--no-push");
}
builderArgs.push(
...(options.builderArgs.length > 0 ? options.builderArgs : ["--snapshotMode=time", "--reproducible"]));

result = await gi.spawn(
"/kaniko/executor",
["--dockerfile", dockerfilePath, "--context", `dir://${project.baseDir}`, ...tags, ...builderArgs],
["--dockerfile", dockerfilePath, "--context", `dir://${project.baseDir}`, ...builderArgs],
);

if (result.code !== 0) {
Expand Down Expand Up @@ -204,17 +211,9 @@ async function dockerPush(images: string[],
options: DockerOptions,
gi: ProjectAwareGoalInvocation): Promise<ExecuteGoalResult> {

let push;
// tslint:disable-next-line:no-boolean-literal-compare
if (options.push === true || options.push === false) {
push = options.push;
} else {
push = !isInLocalMode();
}

let result = Success;

if ((await projectConfigurationValue("docker.push.enabled", gi.project, push))) {
if (await pushEnabled(gi, options)) {

if (!options.user || !options.password) {
const message = "Required configuration missing for pushing docker image. Please make sure to set " +
Expand Down Expand Up @@ -259,8 +258,19 @@ export const DefaultDockerImageNameCreator: DockerImageNameCreator = async (p, s
};

async function checkIsBuilderAvailable(cmd: string, ...args: string[]): Promise<void> {
const result = await spawnLog(cmd, args, { log: new LoggingProgressLog("docker-build")});
const result = await spawnLog(cmd, args, { log: new LoggingProgressLog("docker-build") });
if (result.code !== 0) {
throw new Error(`Configured Docker image builder '${cmd}' is not available`);
}
}

async function pushEnabled(gi: ProjectAwareGoalInvocation, options: DockerOptions): Promise<boolean> {
let push;
// tslint:disable-next-line:no-boolean-literal-compare
if (options.push === true || options.push === false) {
push = options.push;
} else {
push = !isInLocalMode();
}
return projectConfigurationValue("docker.build.push", gi.project, push);
}

0 comments on commit d2a1032

Please sign in to comment.