electron-release-server icon indicating copy to clipboard operation
electron-release-server copied to clipboard

How do I use Amazon S3 for storage?

Open vtardia opened this issue 8 years ago • 18 comments

Hi, what modifications are required to upload asset files to S3? It is a direct upload or pass-through upload? Thanks

vtardia avatar Apr 28 '16 15:04 vtardia

Hi @vtardia. I have not performed those modifications myself, but it should be fairly trivial. Simply replace skipper-disk with skipper-s3 throughout the application. That will give you an implementation which uses pass-through uploads and downloads. You could make further modifications to allow for direct downloads from s3. That cannot be said for uploads because the server must hash certain update types (.nupkg).

ArekSredzki avatar Apr 28 '16 21:04 ArekSredzki

Hi @ArekSredzki,

this is what I have in my sails.config.files, I'm in development env on my local machine:

module.exports.files = {
  maxBytes: 524288000,
  adapter: require('skipper-s3'),
  key: process.env.S3_API_KEY,
  secret: process.env.S3_API_SECRET,
  bucket: process.env.S3_BUCKET,
  region: process.env.S3_REGION
};

The env vars are parsed correctly, the bucket has read/write access for that credentials (tested with Transmit). But when I upload an asset, the server crashes after a minute or so:

events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: Request aborted
    at IncomingMessage.onReqAborted (/path/to/release-server/node_modules/skipper/node_modules/multiparty/index.js:175:17)
    at emitNone (events.js:67:13)
    at IncomingMessage.emit (events.js:166:7)
    at abortIncoming (_http_server.js:280:11)
    at Socket.serverSocketCloseListener (_http_server.js:293:5)
    at emitOne (events.js:82:20)
    at Socket.emit (events.js:169:7)
    at TCP._onclose (net.js:469:12)

What can it be?

vtardia avatar Apr 29 '16 12:04 vtardia

@vtardia I'll provide a full answer later but the issue here is that the config file should not require the actual adapter module, instead you should just specify the name.

Instead you must modify api/services/AssetService.js to use skipper-s3

ArekSredzki avatar Apr 29 '16 16:04 ArekSredzki

@ArekSredzki I've tried modifying only AssetService.js: the assets are uploaded locally and I receive an S3 error (missing key) when I try to delete an asset.

vtardia avatar May 02 '16 08:05 vtardia

@vtardia how exactly did you modify it? You must pass in authentication credentials of course

ArekSredzki avatar May 07 '16 06:05 ArekSredzki

@ArekSredzki I managed to make it work :-) I've modified AssetService.js like this:

var SkipperDisk = require('skipper-s3');
[...]
var s3Options = {
  key: process.env.S3_API_KEY,
  secret: process.env.S3_API_SECRET,
  bucket: process.env.S3_BUCKET,
  region: process.env.S3_REGION || undefined,
  endpoint: process.env.S3_ENDPOINT || undefined,
  token: process.env.S3_TOKEN || undefined
}
[...]
var fileAdapter = SkipperDisk(s3Options); // every time fileAdapter is created

And config/files.js like this:

module.exports.files = {
  // Maximum allowed file size in bytes
  // Defaults to 500MB
  maxBytes: 524288000,
  // The fs directory name at which files will be kept
  adapter: require('skipper-s3'),
  key: process.env.S3_API_KEY,
  secret: process.env.S3_API_SECRET,
  bucket: process.env.S3_BUCKET,
  region: process.env.S3_REGION || undefined,
  endpoint: process.env.S3_ENDPOINT || undefined,
  token: process.env.S3_TOKEN || undefined
};

On a staging DigitalOcean server, both upload and delete features are working properly, on my local machine I have problems uploading but I think it's due to my ISP.

vtardia avatar May 16 '16 08:05 vtardia

Thanks @vtardia

@ArekSredzki it would be great if this could be part of the core module

shoaibmerchant avatar May 16 '16 08:05 shoaibmerchant

I'll incorporate this slightly differently soon thanks!

ArekSredzki avatar May 16 '16 14:05 ArekSredzki

Any update on this?

kennyjwilli avatar Jul 08 '16 03:07 kennyjwilli

no, sorry

ArekSredzki avatar Jul 08 '16 04:07 ArekSredzki

I have configured my instance as @vtardia indicated and while I'm able to upload new content to S3, I get errors on download and delete. I am able to download and delete the same item via aws s3api using the same key/secret. Any ideas on a fix?

matts2s avatar Aug 03 '16 20:08 matts2s

@matts2s in 1.2/1.3 I stopped using skipper for serving files and deleting them because of unnecessary overhead (if one is using skipper-disk)

Take a look at AssetService.js there you'll be able to make the necessary changes

  • file serving: instead of streaming the file from the release server, redirect the request to the s3 asset with a 307 response code. Note that 307 would be better than 301 since you want to log the download action on your server, and the asset that is actually served can change with the uri staying the same.
  • deletion: just change it back to using skipper

ArekSredzki avatar Aug 03 '16 21:08 ArekSredzki

Hi, I forked and added S3 support, it only supports S3 for storing assets. CloudFront is also available for CDN.

https://github.com/abacigil/electron-release-server

abacigil avatar Aug 17 '16 18:08 abacigil

@abacigil Maybe you can file PR?

develar avatar Nov 01 '16 15:11 develar

Another option here is to use s3-fuse and mount a bucket as a disk, although of course better if it's directly integrated in the code for production.

hdn8 avatar Apr 21 '17 15:04 hdn8

Hey

Is there any guide on how to use S3 with this project?

@abacigil we tried using your fork but we got a make error unrecognized option -static. I'd post the issue in your repo but it seems those are disabled...

PierBover avatar Aug 23 '17 19:08 PierBover

Any update on this?

miguelangelvlc94 avatar Feb 06 '19 08:02 miguelangelvlc94

@DustinBrett It would be great to merge this in for out of the box configurable support

ArekSredzki avatar Oct 07 '19 02:10 ArekSredzki