Skip to content

Commit

Permalink
Merge pull request #8 from KanoComputing/s3-file-metadata
Browse files Browse the repository at this point in the history
feat: Allow overriding metadata when deploying to s3
  • Loading branch information
pazdera authored Jan 10, 2020
2 parents fa54746 + 59bffb3 commit a9b82d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kart",
"version": "0.9.1",
"version": "0.10.0",
"description": "Kano Archive and Release Tool. Managing releases mainly of static websites.",
"main": "lib/index.js",
"bin": {
Expand Down

0 comments on commit a9b82d4

Please sign in to comment.