pulumi-command icon indicating copy to clipboard operation
pulumi-command copied to clipboard

Feature Request: Support AssetArchives via temporary copy directive

Open hanseltime opened this issue 9 months ago • 3 comments

Hello!

  • Vote on this issue by adding a 👍 reaction
  • If you want to implement this feature, comment to let us know (we'll work with you on design, scheduling, etc.)

Issue details

Right now, if I want to copy files to the remote, I need to create a path based asset and copy all of those files into a temporary directory. (The directory needs to be referenced as a local path that is relative to my pulumi root so that it works on different machines when it's state is stored).

This leads to lots of boilerplate that I think could be brought into the CopyToRemote Command. Ideally, it would be nice to make use of the AssetArchive class, have that class copied to a temporary directory and then cleaned afterwards.

    const myArchive = new pulumi.asset.AssetArchive({
         file: new pulumi.asset.StringAsset('This is a dynamically created file'),
         folder: someOtherAssetArchive,
    })

    new remote.CopyToRemote('copy-asset-archive', {
         connection,
         source: myArchive,
         path: '/some/path',
         // Required if the source is not path based
         tmpCopyDir: './tmp',
    })

On the provider side this would look like:

  1. If source is non-path, verify that there is a tmpCopyDir
  2. If the tmpCopyDir is not relative throw an error since that will be non-deterministic on other machines
  3. make <tmpCopyDir>/<id>, if non-empty clear the contents // Needs to be deterministic
  4. iterate assets and create files in <tmpCopyDir>/<id>
  5. perform SFTP upoad
  6. defer rm -rf <tmpCopyDir>/<id>

Affected area/feature

pulumi-command provider

hanseltime avatar May 08 '25 16:05 hanseltime

If the team agrees that this is a useful feature and interface, I'm willing to submit a PR.

hanseltime avatar May 08 '25 16:05 hanseltime

This sounds reasonable to me, but I'm not familiar enough with this provider to gauge how much effort might be involved. If you're willing to submit a PR that would be great! Note the implementation lives in here https://github.com/pulumi/pulumi-command/tree/master/provider/pkg/provider

If source is non-path, verify that there is a tmpCopyDir If the tmpCopyDir is not relative throw an error since that will be non-deterministic on other machines

Does this mean it would be a user input? Why not use os.TempDir()?

blampe avatar May 16 '25 23:05 blampe

Hey @blampe,

I'll try to take a stab at it in a bit. I wrote a typescript only helper class that ran into a fair bit of problems with the provider trying to resolve source so it might be harder than I originally proposed.

As for the "tmpCopyDir", I discovered that the path is hashed as part of the archived resource and that caused a bunch of replaces in my pulumi resources when I didn't use a relative path. I guess though, since this would already be in the provider, we might not need it to be relative.

hanseltime avatar May 19 '25 15:05 hanseltime