-
-
Notifications
You must be signed in to change notification settings - Fork 251
Add support for container commit #923
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
51ee497
feat: add support for container.commit() [884]
smcroskey 74585dc
lint fixes
smcroskey f8c67aa
update method signature to return image ID
smcroskey 097578a
add labels (use labels from source image)
smcroskey 55b19aa
expose deleteOnExit & changes options
smcroskey 8f112a8
address PR feedback
smcroskey 5a4b78e
export CommitOptions
smcroskey 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
52 changes: 52 additions & 0 deletions
52
packages/testcontainers/src/generic-container/generic-container-commit.test.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { RandomUuid } from "../common"; | ||
| import { deleteImageByName, getImageInfo, getImageLabelsByName } from "../utils/test-helper"; | ||
|
Check warning on line 2 in packages/testcontainers/src/generic-container/generic-container-commit.test.ts
|
||
| import { GenericContainer } from "./generic-container"; | ||
|
|
||
| describe("GenericContainer commit", { timeout: 180_000 }, () => { | ||
| const imageName = "cristianrgreco/testcontainer"; | ||
| const imageVersion = "1.1.14"; | ||
|
|
||
| it("should commit container changes to a new image", async () => { | ||
| const testContent = "test content"; | ||
| const newImageTag = `test-commit-${new RandomUuid().nextUuid()}`; | ||
| const testAuthor = "test-author"; | ||
| const testComment = "test-comment"; | ||
|
|
||
| // Start original container and make a change | ||
| const container = await new GenericContainer(`${imageName}:${imageVersion}`) | ||
| .withName(`container-${new RandomUuid().nextUuid()}`) | ||
smcroskey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .withExposedPorts(8080) | ||
| .start(); | ||
|
|
||
| // Make a change to the container | ||
| await container.exec(["sh", "-c", `echo '${testContent}' > /test-file.txt`]); | ||
|
|
||
| // Commit the changes to a new image | ||
| await container.commit({ | ||
| repo: imageName, | ||
| tag: newImageTag, | ||
| author: testAuthor, | ||
| comment: testComment, | ||
| }); | ||
|
|
||
| // Verify image author and comment are set | ||
| const imageInfo = await getImageInfo(`${imageName}:${newImageTag}`); | ||
| expect(imageInfo.Author).toBe(testAuthor); | ||
| expect(imageInfo.Comment).toBe(testComment); | ||
|
|
||
| // Start a new container from the committed image | ||
| const newContainer = await new GenericContainer(`${imageName}:${newImageTag}`) | ||
| .withName(`container-${new RandomUuid().nextUuid()}`) | ||
| .withExposedPorts(8080) | ||
| .start(); | ||
|
|
||
| // Verify the changes exist in the new container | ||
| const result = await newContainer.exec(["cat", "/test-file.txt"]); | ||
| expect(result.output.trim()).toBe(testContent); | ||
|
|
||
| // Cleanup | ||
| await container.stop(); | ||
| await newContainer.stop(); | ||
| await deleteImageByName(`${imageName}:${newImageTag}`); | ||
smcroskey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| }); | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.