Unify the copy-to-container methods and add reading a file from a container

Open
#1,547 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 4 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
42/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
docker, node.js, typescript
Domain
api, backend

Research direction

Start with the four listed files and trace how copy methods, options, and StartedTestContainer are implemented and forwarded. Review #1522 and coordinate with #1518 before changing the shared copy API. Done means unified before and after start copy methods with matching options and behavior, a way to read one file, and deprecated aliases for existing methods.

Written by the indexing model from the issue text.

Description

enhancement minor

What happens

Copying into a container is spread over nine methods with slightly different shapes.

Before start:

  • withCopyFilesToContainer(files[])
  • withCopyDirectoriesToContainer(directories[])
  • withCopyContentToContainer(contents[])
  • withCopyArchivesToContainer(archives[])
  • withCopyToContainerOptions(options)

After start:

  • copyFilesToContainer(files[])
  • copyDirectoriesToContainer(directories[])
  • copyContentToContainer(contents[])
  • copyArchiveToContainer(tar, target?, options?)

The two sides do not behave the same (from reading the code):

  • DirectoryToCopy.mode is applied before start and ignored after start.
  • CopyToContainerOptions applies to every copy before start, but after start only copyArchiveToContainer accepts it.
  • The archive method is plural with an array before start, singular with positional arguments after.

Copying out is limited to copyArchiveFromContainer(path), which resolves to a tar stream. Reading one file's content means bringing a tar parser.

Expected

  • One withCopyToContainer and one copyToContainer that accept a list of entries, each a host path, inline content or an archive, with target and mode. The same options and behaviour on both sides.
  • A way to read a single file from a container, for example readFile(path): Promise<Buffer> or copyFileFromContainer(path, destination).
  • The existing methods stay as deprecated aliases.

Where

  • packages/testcontainers/src/test-container.ts
  • packages/testcontainers/src/generic-container/generic-container.ts
  • packages/testcontainers/src/generic-container/started-generic-container.ts
  • packages/testcontainers/src/types.ts

Notes

  • Java has withCopyToContainer(Transferable, containerPath) and withCopyFileToContainer(MountableFile, containerPath), plus copyFileFromContainer(containerPath, destinationPath) and a variant that passes the file's InputStream to a function. Go has Files []ContainerFile on the request and CopyFileFromContainer, which returns the file's content.
  • Related: #1526. The mode field should say it is an octal permission.

Dependencies

  • Stack on #1522: the reuse hash has to cover copied files. Changing how copies are stored first would move that target.
  • Coordinate with #1518: for the old method names.
  • Changes StartedTestContainer, which today means the interface, StartedGenericContainer and the forwarder on AbstractStartedContainer. Several other issues do the same. The edits do not overlap, so they can go in parallel.
Dominant language
TypeScript
Stars
2.7k
Forks
290
Avg merge
4d 1h
Merged PRs (30d)
22

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from testcontainers/testcontainers-node

All issues in testcontainers/testcontainers-node

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.