Skip to content

Commit

Permalink
feat: Allow overriding metadata when deploying to s3
Browse files Browse the repository at this point in the history
Sometimes, the ContentType detection fails for certain files when
uploading. This adds the option to set metadata in project config.
  • Loading branch information
pazdera committed Jan 9, 2020
1 parent fa54746 commit f1f0d63
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/deploy-methods/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function _updateProgress(reporter, message) {
}
}

function _doRelease(build, target, algorithm, reporter) {
function _doRelease(build, target, algorithm, fileOptions, reporter) {
return new Promise((resolve, reject) => {
const bucketMap = {};
const extract = tarStream.extract();
Expand Down Expand Up @@ -52,14 +52,19 @@ function _doRelease(build, target, algorithm, reporter) {
_updateProgress(reporter, `Uploading ${header.name}`);
}

let contentType = mime.lookup(header.name) || 'application/octet-stream';
if (fileOptions[header.name] && fileOptions[header.name].ContentType) {
contentType = fileOptions[header.name].ContentType;
}

s3.getInstance().upload(
{
Bucket: target,
Key: header.name,
Body: stream,
ACL: 'public-read',
CacheControl: 'max-age=600',
ContentType: mime.lookup(header.name) || 'application/octet-stream',
ContentType: contentType,
},
(err) => {
if (err) {
Expand Down Expand Up @@ -144,18 +149,19 @@ function _downloadKartFile(project, channel) {
* * overwrite: Writes all the files into the bucked without clearing it out first.
* * sync: Uses the `aws sync` command to minimise bandwith usage.
*
* @param {Object} build The build object to be released.
* @param {Object} opts Options.
* @param {String} opts.bucket Name of the bucket to deploy to.
* @param {String} opts.algorithm Either 'clear', 'overwrite' or 'sync'.
* @param {String} opts.reporter An optional event listener to report events.
* @param {Object} build The build object to be released.
* @param {Object} opts Options.
* @param {String} opts.bucket Name of the bucket to deploy to.
* @param {String} opts.algorithm Either 'clear', 'overwrite' or 'sync'.
* @param {Object} opts.fileOptions Per-file options that will be applied when uploading to S3 (metadata, etc).
* @param {String} opts.reporter An optional event listener to report events.
*/
function release(build, opts) {
const { bucket, algorithm = 'clear' } = opts;
const { bucket, algorithm = 'clear', fileOptions = {} } = opts;
let releaseObject;

return build.fetchMetadata()
.then(() => (algorithm === 'clear' ? s3.clearBucket(bucket) : Promise.resolve())).then(() => _doRelease(build, bucket, algorithm, opts.reporter)).then((r) => {
.then(() => (algorithm === 'clear' ? s3.clearBucket(bucket) : Promise.resolve())).then(() => _doRelease(build, bucket, algorithm, fileOptions, opts.reporter)).then((r) => {
releaseObject = r;
return _uploadKartFile(releaseObject, bucket);
})
Expand Down

0 comments on commit f1f0d63

Please sign in to comment.