-
-
Notifications
You must be signed in to change notification settings - Fork 251
perf: replace archiver and tar-fs with modern-tar #1161
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import archiver from "archiver"; | ||
| import AsyncLock from "async-lock"; | ||
| import { Container, ContainerCreateOptions, HostConfig } from "dockerode"; | ||
| import { Readable } from "stream"; | ||
| import { buffer } from "stream/consumers"; | ||
| import { containerLog, hash, log, toNanos } from "../common"; | ||
| import { ContainerRuntimeClient, getContainerRuntimeClient, ImageName } from "../container-runtime"; | ||
| import { CONTAINER_STATUSES } from "../container-runtime/clients/container/types"; | ||
|
|
@@ -178,9 +178,30 @@ export class GenericContainer implements TestContainer { | |
| await client.container.connectToNetwork(container, network, this.networkAliases); | ||
| } | ||
|
|
||
| if (this.filesToCopy.length > 0 || this.directoriesToCopy.length > 0 || this.contentsToCopy.length > 0) { | ||
| const archive = this.createArchiveToCopyToContainer(); | ||
| archive.finalize(); | ||
| const sources = [ | ||
| ...this.filesToCopy.map((file) => ({ | ||
| type: "file" as const, | ||
| source: file.source, | ||
| target: file.target, | ||
| mode: file.mode, | ||
| })), | ||
| ...this.directoriesToCopy.map((dir) => ({ | ||
| type: "directory" as const, | ||
| source: dir.source, | ||
| target: dir.target, | ||
| mode: dir.mode, | ||
| })), | ||
| ...(await Promise.all( | ||
| this.contentsToCopy.map(async ({ content, target, mode }) => { | ||
| const data = content instanceof Readable ? await buffer(content) : content; | ||
| return { type: "content" as const, content: data, target, mode }; | ||
|
Comment on lines
+196
to
+197
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }) | ||
| )), | ||
| ]; | ||
|
|
||
| if (sources.length > 0) { | ||
| const { packTar } = await import("modern-tar/fs"); | ||
| const archive = packTar(sources); | ||
| await client.container.putArchive(container, archive, "/"); | ||
| } | ||
|
|
||
|
|
@@ -255,22 +276,6 @@ export class GenericContainer implements TestContainer { | |
| } | ||
| } | ||
|
|
||
| private createArchiveToCopyToContainer(): archiver.Archiver { | ||
| const tar = archiver("tar"); | ||
|
|
||
| for (const { source, target, mode } of this.filesToCopy) { | ||
| tar.file(source, { name: target, mode }); | ||
| } | ||
| for (const { source, target, mode } of this.directoriesToCopy) { | ||
| tar.directory(source, target, { mode }); | ||
| } | ||
| for (const { content, target, mode } of this.contentsToCopy) { | ||
| tar.append(content, { name: target, mode }); | ||
| } | ||
|
|
||
| return tar; | ||
| } | ||
|
|
||
| protected containerStarted?( | ||
| container: StartedTestContainer, | ||
| inspectResult: InspectResult, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // Can be removed if testcontainers switches to ESM. | ||
| declare module "modern-tar/fs" { | ||
| export * from "modern-tar/dist/fs/index"; | ||
| } | ||
|
Comment on lines
+1
to
+4
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Alternatively, we could modernize the whole tsconfig stack. Then you could still export to CJS via something like
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have a few dependencies which are ESM only, such as |
||
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.
I think this is a bug/edge case from
archiver, becausenode-tarandmodern-tardo not mix directory modes and file modes together. That's not very standard behaviour.