Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify how we handle cache-from values when doing a pull. #137

Merged
merged 3 commits into from
Feb 7, 2020

Conversation

CyrusNajmabadi
Copy link
Contributor

No description provided.

@@ -260,18 +260,15 @@ 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[] = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first, passing around 'undefined' just made later code more complex. We can instead just pass around an empty array. The later code already checks that the array is non-empty before proceeding.

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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

second, concurrent execution of docker pull wasn't buying us anything. We would immediately get to a point where we would just await this promise unilaterally before proceeding. So it's not like this allowed us any extra performance. It was just extra complexity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: there is an opportunity for concurrency in that we can pull on all the different cache stages concurrently. However, we already don't do that today. And, if we did, it would be entirely in the body of pullCacheAsync.

I'm not going to make that change as i don't want that to cause any potential problems in case there's an issue with too many docker commands running concurrently, or interacting with some repository.

if (cacheFromImages && cacheFromImages.length) {
buildArgs.push(...["--cache-from", cacheFromImages.join()]);
if (cacheFrom.length) {
buildArgs.push(...["--cache-from", cacheFrom.join()]);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is where we effectively immediately did the awaiting of cacheFrom thus making the concurrency pointless. It's not like there was other expensive work we were doing in the meantime. We were simply building up the args to then just pass to docker build. Since that build had a dep on this, it's not like we had any benefit here. (i.e. it's not like we could kick off the build concurrently while this was executing).

@CyrusNajmabadi CyrusNajmabadi added the impact/no-changelog-required This issue doesn't require a CHANGELOG update label Feb 7, 2020
buildArgs.push(...["--cache-from", cacheFromImages.join()]);
}
if (cacheFrom.length) {
buildArgs.push(...["--cache-from", cacheFrom.join()]);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the check of build.cacheFrom is unnecessary. We would only have a non-empty cacheFrom value if build.cacheFrom was there.

@CyrusNajmabadi
Copy link
Contributor Author

Moving forward with this change. Have explained the logic behind it. LMK if there are any changes you'd like to see.

@CyrusNajmabadi CyrusNajmabadi merged commit ea48d60 into master Feb 7, 2020
@pulumi-bot pulumi-bot deleted the simplify branch February 7, 2020 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact/no-changelog-required This issue doesn't require a CHANGELOG update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant