SFTP direct access to Volumes

If your files are small, like config files you don’t want to build into the image, I’d suggest looking into sending them along with the Machine config:

(Docs)

(Edit: I suspect the above doesn’t work to deposit the files on a persistent volume, but I haven’t asked or tried it)

Otherwise, there are a few ways to get a generic Machine running long enough to transfer files up, then either update that Machine or destroy it and attach a new one to the volume. One possible route is to add this to your fly.toml for your first deployment, to override the CMD in your Docker image:

[experimental]
 cmd = ["sleep", "inf"]

(Docs)

Once the Machine boots up, do your file transfer with fly sftp or whatever, then remove that section from fly.toml and redeploy.

If you’re planning multiple instances, look into fly volume fork to copy the volume to your desired region once you’ve populated it, before scaling up with fly machine clone using the --attach-volume flag.

Another way that’s convenient, when practical, is to write an entrypoint script that checks for the assets on the volume and retrieves them from somewhere if they’re absent, before carrying on with starting up your app process. That would, I think, let you scale out using fly scale count.

Hope something in there is useful!

1 Like