Feature Request: Support AssetArchives via temporary copy directive
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:
- 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
- make
<tmpCopyDir>/<id>, if non-empty clear the contents // Needs to be deterministic - iterate assets and create files in
<tmpCopyDir>/<id> - perform SFTP upoad
- defer
rm -rf <tmpCopyDir>/<id>
Affected area/feature
pulumi-command provider
If the team agrees that this is a useful feature and interface, I'm willing to submit a PR.
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()?
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.