Giter VIP home page Giter VIP logo

gulp-s3's Introduction

gulp-s3 NPM version

s3 plugin for gulp

Usage

First, install gulp-s3 as a development dependency:

npm install --save-dev gulp-s3

Then, use it in your gulpfile.js:

var s3   = require('gulp-s3')
var gulp = require('gulp')

var AWS = {
  "key":    process.env.AWS_ACCESS_KEY_ID,
  "secret": process.env.AWS_SECRET_ACCESS_KEY,
  "bucket": "dev.example.com",
  "region": "eu-west-1"
}

gulp.task('default', () => {
  gulp.src('./dist/**').pipe(s3(AWS));
});

API

options.uploadPath

Type: String
Default: ``

Set the remote folder on the S3 bucket

var options = { uploadPath: 'remote-folder' } // It will upload the 'src' into '/remote-folder'
gulp.src('./dist/**', {read: false})
    .pipe(s3(AWS, options));

options.headers

Type: Object
Default: {}

Headers to set to each file uploaded to S3

var options = { 
  headers: {
    'Cache-Control': 'max-age=315360000, no-transform, public',
    'x-amz-acl': 'private'
  } 
};
gulp.src('./dist/**', {read: false})
    .pipe(s3(AWS, options));

options.gzippedOnly

Type: Boolean
Default: false

Only upload files with .gz extension, additionally it will remove the .gz suffix on destination filename and set appropriate Content-Type and Content-Encoding headers.

var options = { gzippedOnly: true };
gulp.src('./dist/**').pipe(gzip())
    .pipe(s3(AWS, options));

options.failOnError

Type: Boolean Default: false

Throw error if upload to s3 fails.

var options = { failOnError: true };
gulp.src('./dist/**').pipe(gzip())
    .pipe(s3(AWS, options));

License

MIT License

gulp-s3's People

Contributors

abhisekpaul avatar and-re avatar austinhallock avatar brunosiqueira avatar cyruskazemi avatar jtblin avatar mathisonian avatar mbjorkegren avatar mjackson avatar nitaigao avatar pon avatar steadicat avatar subinsebastien avatar zoltanradics avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gulp-s3's Issues

Signature v4 Support

Newly added regions only supports v4 signatures. What is sufficient to support this needs to be added to gulp-s3 since many will be using new regions in future. The lack of this feature may be one reason to get 400 FAILED responses.

Download or Copy from S3

On a project that I am on we have a need to download some files from S3 prior to uploading our files (using gulp). I could create a separate project to do this; however, I think it would be better to include this in an existing project. I wanted to see if there would be any interest in adding download functionality to the gulp-s3 project.

Thanks

Shannon

Uploading to a subdirectory

Allow for user to define a subdirectory for files to be uploaded to.

eg

aws = {
      "key": gutil.env.aws_key,
      "secret": gutil.env.aws_secret,
      "bucket": gutil.env.aws_bucket,
      "region": gutil.env.aws_region,
      "subdirectory": "aSubDirectory/"
    };

    gulp.src('./dist/**')
        .pipe(s3(aws));

this will upload everything in dist to aSubDirectory on S3

Typo in headers options for docs.

Hey @nkostelnik ,

Just trying to convert over a gruntfile to gulp and one of the grunt tasks was using grunt-s3 so I'm giving your gulp equivalent a go.

I did however notice that here

var options = { headers: ['Cache-Control': 'max-age=315360000, no-transform, public'] }
gulp.src('./dist/**', {read: false})
    .pipe(s3(aws, options));

options is actually an object and not an object array I think according to the source so options should be defined with

var options = {headers: {'Cache-Control': 'max-age=315360000, no-transform, public' } }

Please do correct me if I'm wrong but I tried to run the example code not really looking at it and it of course threw an error.

Hope that helps.

Best

@jh3y

Specify charset for HTML files

Is there a way to set the charset to UTF-8 only on files with a Content-Type: text/html?

These are my settings currently:

gulp.task('deploy', function() {
  var awsConfig = require('./lib/config/aws.js');
  var s3Options = {
    headers: {
      'Cache-Control': 'max-age=3600, no-transform, public'
    }
  };
  gulp.src('./public/**')
    .pipe(gzip())
    .pipe(gulpS3(awsConfig, s3Options));
});

Event 'end' emit

Can you please have the EventSteam emit the "end" event? So when binding to the standard event, my gulp tasks can execute the 'done' callback and can continue synchronously as I'm codependent on this completion to cleanup.

I've forked the repo and may try myself if you're unavailable, do you actually manage pull requests?

question: what AWS IAM policies are required?

Thanks for the package, works great!

I'm trying to figure out what permissions are required. Right now if I attach the S3 full access policy, everything works fine, but if I try to make a more restricted policy that only works on a particular bucket, I get a 403 error.

Any advice on this?

Here is my policy JSON (sensitive fields changed):

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1494895366000",
      "Effect": "Allow",
      "Action": [
        "s3:DeleteObject",
        "s3:GetObject",
        "s3:PutObject"
      ],
      "Resource": [
        "arn:aws:s3:::foobar-bucket"
      ]
    }
  ]
}

Versions missing for dependencies

Is there a particular reason why dependencies async and knox do not have a version explicitly set in package.json?

https://github.com/nitaigao/gulp-s3/blob/master/package.json#L26
https://github.com/nitaigao/gulp-s3/blob/master/package.json#L29

On npm install these are being bypassed and not installed, and thus bringing up errors.
As far as I understand, leaving the version empty is not accounted for in semantic versioning: https://docs.npmjs.com/getting-started/semantic-versioning#semver-for-consumers

Random FAILED assets

Been using this plugin for quite sometime and never had issues. Recently I have been getting a lot of random assets failing. Anyone know what would cause this? Any help would be great.

Obsolete Package

This package no longer works with aws v4 signatures. All PUT requests to S3 buckets will return a 400 HTTP code.

If you are looking for an alternative, use gulp-awspublish.

Errors are undetectable

Hey, I noticed in the code that errors appear to be logged but then nothing is done about them:

      client.putBuffer(file.contents, uploadPath, headers, function(err, res) {
        if (err || res.statusCode !== 200) {
          gutil.log(gutil.colors.red('[FAILED]', file.path + " -> " + uploadPath));
        } else {
          gutil.log(gutil.colors.green('[SUCCESS]', file.path + " -> " + uploadPath));
          res.resume();
        }
      });

It would be nice if an error event or something was emitted, so that gulp tasks could raise errors instead of having the process exit with status code 0 even though things went amiss.

Syncing

Is it possible to sync with this plugin? (Add new files & remove old ones.) Is it a planned feature?

New Repo - gulp-s3-ls

Hi everyone,
So it's been quite some time since this repo has been active and I think there are some great pull requests that are still open! So I decided to fork the repo and publish it under a new name "gulp-s3-ls". Check it out, and resubmit your pull requests to it. Ill review them all and accept them if they're worthy with expediency!

Always getting FAILED (StatusCode 400)

I'm always getting an FAILED error. If I take a look into the index.js I can see an status code of 400.
Anyone else having this issue and/or a solution?

npm package is out of date

npm package is on version 0.11.0 but code has been merged since that version was published. Please publish a new version with the updated code.

Thanks,
Cyrus

gulp-s3 removes .gz suffix

I was surprised that gulp-s3 now removes .gz extensions from gzipped files. It wasn't the case with 0.2.x. Is there any reason why? It is pretty annoying and broke my deployments when upgrading.

if (regexGzip.test(file.path)) {
      // Set proper encoding for gzipped files, remove .gz suffix
      headers['Content-Encoding'] = 'gzip';
      uploadPath = uploadPath.substring(0, uploadPath.length - 3);
  }

Setting the header is good but why removing the extension?

Question: How can I delete the previous version files from the s3 bucket?

Hey guys,

I am using gulp-s3 to deploy a web app to S3.

Since the .js and .css files are versioned on each deploy I would like to delete the previous versions of these files (or even rotate it) from the S3 bucket.

I thought about deploying the files to a versioned directory inside the bucket, but I didn't find an option on the code to pass the name of the directory to upload the files.

Can you please give me any suggestion about how to delete or rotate the previous version?

Thank you.

uploadPath with file name

i have a requirement to deploy files to S3 with different name than local file name. right now uploadPath concates the actual file name with this.
gulp-rename plugin also doesn;t work .. anythoughts..

e.g) src_file_name >> SOURCE_GEN_1.js
gulp.src(src_file_name)
.pipe(s3(aws,{'uploadPath':'/SOURCE_GEN.js','encoding':'UTF-8'})) );

currently s3 plugin creates file like
/SOURCE_GEN.jsSOURCE_GEN_1.js

File is always null

Hi I'm not sure what I'm doing wrong here. The file is showing null.
var s3_creds = {
"key": "xxxxxxxxx",
"secret": "xxxxxxxxxxx",
"bucket": "sample",
"region": "ireland"
};

/* upload the dist files */
gulp.task('deploy_s3', function(){
var options = { gzippedOnly: true };

return gulp.src('app/builds/index.html', {read: false})
.pipe(gzip({append: true}))
.pipe(s3(s3_creds, options));
});

`uploadPath` fails without tailing slash

var aws = JSON.parse(fs.readFileSync('./aws.json')),
    options = {
        uploadPath: '/site/js'
    };
gulp.src('./dist/file.js').pipe(s3(aws, options));

Results in the file being uploaded as: /site/jsfile.js instead of /site/js/file.js.

Setting the `Expires` header option.

Could this be added?

For example, grunt-s3 accepts an object, something like

headers: {
    // Two Year cache policy (1000 * 60 * 60 * 24 * 730)
    "Cache-Control": "max-age=630720000, public",
    "Expires": new Date(Date.now() + 63072000000).toUTCString()
}

SVG uploaded with wrong MIME type

Hi,

Whenever I upload SVG files with gulp-s3, they have MIME "text/plain" rather than "image/svg+xml". I'm using gulp-s3 version 0.2.0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.