Skip to content

Commit

Permalink
Simplify how we handle cache-from values when doing a pull. (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi authored Feb 7, 2020
1 parent eacd75d commit ea48d60
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions sdk/nodejs/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ async function buildAndPushImageWorkerAsync(
}

// If the container specified a cacheFrom parameter, first set up the cached stages.
let cacheFrom = Promise.resolve<string[] | undefined>(undefined);
let cacheFrom: string[] = [];
if (pullFromCache) {
const dockerBuild = <pulumi.UnwrappedObject<DockerBuild>>pathOrBuild;
const cacheFromParam = (typeof dockerBuild.cacheFrom === "boolean" ? {} : dockerBuild.cacheFrom) || {};
cacheFrom = pullCacheAsync(baseImageName, cacheFromParam, repositoryUrl, logResource);
cacheFrom = await pullCacheAsync(baseImageName, cacheFromParam, repositoryUrl, logResource);
}

// Next, build the image.
Expand Down Expand Up @@ -329,11 +329,11 @@ async function pullCacheAsync(
imageName: string,
cacheFrom: pulumi.Unwrap<CacheFrom>,
repoUrl: string,
logResource: pulumi.Resource): Promise<string[] | undefined> {
logResource: pulumi.Resource): Promise<string[]> {

// Ensure that we have a repository URL. If we don't, we won't be able to pull anything.
if (!repoUrl) {
return undefined;
return [];
}

pulumi.log.debug(`pulling cache for ${imageName} from ${repoUrl}`, logResource);
Expand Down Expand Up @@ -370,7 +370,7 @@ async function buildImageAsync(
imageName: string,
pathOrBuild: string | pulumi.Unwrap<DockerBuild>,
logResource: pulumi.Resource,
cacheFrom: Promise<string[] | undefined>): Promise<BuildResult> {
cacheFrom: string[]): Promise<BuildResult> {

let build: pulumi.Unwrap<DockerBuild>;
if (typeof pathOrBuild === "string") {
Expand Down Expand Up @@ -433,7 +433,7 @@ async function buildImageAsync(
async function dockerBuild(
imageName: string,
build: pulumi.Unwrap<DockerBuild>,
cacheFrom: Promise<string[] | undefined>,
cacheFrom: string[],
logResource: pulumi.Resource,
target?: string): Promise<void> {

Expand All @@ -450,11 +450,8 @@ async function dockerBuild(
if (build.target) {
buildArgs.push(...["--target", build.target]);
}
if (build.cacheFrom) {
const cacheFromImages = await cacheFrom;
if (cacheFromImages && cacheFromImages.length) {
buildArgs.push(...["--cache-from", cacheFromImages.join()]);
}
if (cacheFrom.length) {
buildArgs.push(...["--cache-from", cacheFrom.join()]);
}
if (build.extraOptions) {
buildArgs.push(...build.extraOptions);
Expand Down

0 comments on commit ea48d60

Please sign in to comment.