nixops-aws icon indicating copy to clipboard operation
nixops-aws copied to clipboard

Uploading to S3 buckets

Open chris-martin opened this issue 8 years ago • 6 comments

NixOS/nixops#173 discusses creating S3 buckets.

Can nixops also upload things into the buckets?

chris-martin avatar Nov 01 '16 03:11 chris-martin

@edolstra I plan to try to build a solution for uploading to S3 buckets, but I am wondering if it is more appropriate to build it as part of the existing S3BucketState class, or as a separate resource/class (S3BucketFile) that depends on an existing bucket (whether the bucket is NixOps managed or not). I think the latter, but I'm not yet familiar enough with how NixOps works to be certain.

cessationoftime avatar May 11 '17 14:05 cessationoftime

I'm not sure. On the one hand, fine-grained resources are nice because they can be managed (created/deleted/...) separately. On the other hand, there could be a lot of files which would potentially clutter up the UI.

edolstra avatar May 11 '17 15:05 edolstra

I've made progress on this and I can upload files to S3 buckets. However I want to upload the output of a custom derivation.

So I have code like:

let
  mypkgs = import ./my-pkgs { };

  ec2Machine =
    { config, pkgs, resources, ... }:
    { deployment.targetEnv = "ec2";
...
...
    };

in
{
  ...
  ...
  resources.s3BucketUploads.frontend-upload =
    { inherit region accessKeyId;
      description = "web frontend";
      bucketName = "deploy.haste.us";
      source = "${mypkgs.frontend}/bin";
      #source = "/home/cessationoftime/workspace/frontend/dist/bin";
      bucketDestination = "frontendFolder";
    };

    web1 = ec2Machine;
}

When I use a source directory value of "/home/cessationoftime/workspace/frontend/dist/bin" the upload works fine, but if I use "${mypkgs.frontend}/bin" then the directory cannot be found. I need a way to trigger the build for ${mypkgs.frontend} before performing the upload and I'm not sure how best to go about that. I see the build_configs function, do I need to create a similar function in my resource or is there another way to trigger the build for ${mypkgs.frontend}?

cessationoftime avatar Jun 08 '17 02:06 cessationoftime

I'll fix that shortly.

domenkozar avatar Aug 19 '17 09:08 domenkozar

I ended up calling nix-build within the resource. See: s3_bucket_upload.py. It is working well and I have a derivation that runs webpack and uploads to S3 which deploys alongside a website that references the S3 location. But I think it could be cleaner. @domenkozar

cessationoftime avatar Aug 19 '17 15:08 cessationoftime

@cessationoftime did you ever end up making more progress on this, or is your code available somewhere? This is something I'd like

glittershark avatar Oct 10 '20 01:10 glittershark