-
-
Notifications
You must be signed in to change notification settings - Fork 203
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
Performance improvements #453
Merged
cristianrgreco
merged 10 commits into
testcontainers:main
from
henrinormak:performance-improvements
Feb 28, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
67c07af
refactor: move determining auth config inside pullImage
henrinormak 7351062
feat: add lock around image pulling
henrinormak 02cf578
feat: add enabled flag to logger
henrinormak 3c2c518
feat: cache image existance check results
henrinormak e9a2ff5
fix: disable exec logging if logs are not enabled
henrinormak 4389dd8
fix: typo
henrinormak f01cb0d
revert: re-enable tty in port-check
henrinormak dce37c1
refactor: move log enabled check in port-check
henrinormak bea27a8
test: make sure logging is enabled in port-check tests
henrinormak 68e8185
refactor: drop polling from execContainer
henrinormak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
import { DockerImageName } from "../../../docker-image-name"; | ||
import { listImages } from "./list-images"; | ||
import { log } from "../../../logger"; | ||
import Dockerode from "dockerode"; | ||
import AsyncLock from "async-lock"; | ||
import { listImages } from "./list-images"; | ||
|
||
const existingImages = new Set<string>(); | ||
const imageCheckLock = new AsyncLock(); | ||
|
||
export const imageExists = async (dockerode: Dockerode, imageName: DockerImageName): Promise<boolean> => { | ||
log.debug(`Checking if image exists: ${imageName}`); | ||
return (await listImages(dockerode)).some((image) => image.equals(imageName)); | ||
|
||
return imageCheckLock.acquire(imageName.toString(), async () => { | ||
if (existingImages.has(imageName.toString())) { | ||
return true; | ||
} | ||
|
||
const images = await listImages(dockerode); | ||
images.forEach((name) => { | ||
existingImages.add(name.toString()); | ||
}); | ||
|
||
return existingImages.has(imageName.toString()); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to provide a timeout here, in case something goes wrong and the lock can't be acquired? Likewise does the lock need to be released in some
finally
block?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lock implementation handles the release in case the user code throws, it also allows configuring a timeout, but for now I left it out, as presumably the underlying operations already have timeouts?