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

withCopyFilesToContainer should follow symlinks by default #713

Open
jackvincentnz opened this issue Feb 3, 2024 · 1 comment
Open

withCopyFilesToContainer should follow symlinks by default #713

jackvincentnz opened this issue Feb 3, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@jackvincentnz
Copy link

Summary

I am trying to use withCopyFilesToContainer to copy files onto a container. The build system I am using is Bazel, which runs the javascript inside a sandbox. The sandbox contains only symlinks to the actual files that need to be copied and so I need a way for testcontainers to follow the symlink and copy the linked file instead of the link itself.

My workaround currently is to read the file and then use withCopyContentToContainer instead.

E.g.

  const schema = fs.readFileSync(
    `${RUNFILES}/_main/infra/local/router/schema/supergraph.graphql`,
  );

  const routerContainer = new GenericContainer(
    "ghcr.io/apollographql/router:v1.38.0",
  )
    .withCopyContentToContainer([
      {
        content: schema,
        target: "/dist/schema/local.graphql",
      },
    ]).start();

This would be simpler if the tar we copy to the container follows symlinks by default. With tar we can use -h, -H or -L for this behaviour:

-L, --dereference
(c and r modes only) All symbolic links will be followed. Normally, symbolic links are archived as such. With this option, the target of the link will be archived instead.


Expected Behaviour
withCopyFilesToContainer should follow symlinks referenced by source when copying files into the container so that the copied file can be read rather than remaining a link to the linked file.

Actual Behaviour
withCopyFilesToContainer puts the file at the right target, but if it is a symlink it remains a symlink rather than following the link and copying the linked file.

Testcontainer Logs

2024-02-03T00:12:12.808Z testcontainers [DEBUG] Creating container for image "ghcr.io/apollographql/router:v1.38.0"...
2024-02-03T00:12:12.886Z testcontainers [DEBUG] [d792c2d98366] Created container for image "ghcr.io/apollographql/router:v1.38.0"
2024-02-03T00:12:12.888Z testcontainers [DEBUG] [d792c2d98366] Putting archive to container...
2024-02-03T00:12:12.912Z testcontainers [DEBUG] [d792c2d98366] Put archive to container
2024-02-03T00:12:12.912Z testcontainers [INFO] [d792c2d98366] Starting container for image "ghcr.io/apollographql/router:v1.38.0"...
2024-02-03T00:12:12.912Z testcontainers [DEBUG] [d792c2d98366] Starting container...
2024-02-03T00:12:13.143Z testcontainers [DEBUG] [d792c2d98366] Started container
2024-02-03T00:12:13.143Z testcontainers [INFO] [d792c2d98366] Started container for image "ghcr.io/apollographql/router:v1.38.0"
2024-02-03T00:12:13.143Z testcontainers [DEBUG] [d792c2d98366] Inspecting container...
2024-02-03T00:12:13.322Z testcontainers [DEBUG] [d792c2d98366] Inspected container
2024-02-03T00:12:13.322Z testcontainers [DEBUG] [d792c2d98366] Fetching container logs...
2024-02-03T00:12:13.331Z testcontainers [DEBUG] [d792c2d98366] Demuxing stream...
2024-02-03T00:12:13.331Z testcontainers [DEBUG] [d792c2d98366] Demuxed stream
2024-02-03T00:12:13.331Z testcontainers [DEBUG] [d792c2d98366] Fetched container logs
2024-02-03T00:12:13.331Z testcontainers [DEBUG] [d792c2d98366] Waiting for container to be ready...
2024-02-03T00:12:13.331Z testcontainers [DEBUG] [d792c2d98366] Host port wait strategy complete
2024-02-03T00:12:13.331Z testcontainers [INFO] [d792c2d98366] Container is ready
2024-02-03T00:12:13.331Z testcontainers:containers [d792c2d98366] total 16
2024-02-03T00:12:13.331Z testcontainers:containers [d792c2d98366] drwxr-xr-x 1 root root 4096 Feb  3 00:12 .
2024-02-03T00:12:13.331Z testcontainers:containers [d792c2d98366] drwxr-xr-x 1 root root 4096 Jan 19 20:47 ..
2024-02-03T00:12:13.331Z testcontainers:containers [d792c2d98366] lrwxrwxrwx 1 root root   71 Feb  2 22:45 local.graphql -> ../../../../../../../../../infra/local/router/schema/supergraph.graphql

Steps to Reproduce

  1. With a source that is a symlink.
  2. Copy symlink to a target on the container.
  3. See that the copied file is still a symlink, rather than a real file with the contents of the original.

E.g.

  const routerContainer = new GenericContainer("ghcr.io/apollographql/router:v1.38.0")
    .withCopyFilesToContainer([
      {
        source: `${RUNFILES}/_main/infra/local/router/schema/supergraph.graphql`,
        target: "/dist/schema/local.graphql",
      },
    ])
    .withEntrypoint(["ls"]).withCommand(["-al", "/dist/schema"])
    .start();

Environment Information

  • Operating System: Mac
  • Docker Version: Docker version 24.0.7, build afdd53b
  • Node version: 18
  • Testcontainers version: 10.6.0
@cristianrgreco
Copy link
Collaborator

cristianrgreco commented Feb 4, 2024

Hi @jackvincentnz, thanks for raising. The archiving library we use is node-archiver, I've read through their docs and dereferencing is not supported. It only supports copying in symlinks, but without the source file the contents is lost. I'd happily accept a PR which swaps this library with another that supports this functionality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants