Skip to content

Commit

Permalink
Merge pull request #6 from KanoComputing/rename
Browse files Browse the repository at this point in the history
Rename
  • Loading branch information
pazdera authored Aug 15, 2018
2 parents 6942066 + 9a9d616 commit 036b31d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 15 deletions.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,42 @@ setting the `algorithm` option to one of the following
* **overwrite**: Upload the new build into the bucket without removing everyting first.
* **sync**: Use `aws s3 sync` to deploy into the bucket.

### S3 Copy

```json
{
"method": "s3-copy",
"track": "internal",
"namePattern": ":project_:version-:number_:arch.:ext"
}
```

This method copies an archive to a release track. A release track is located in the same directory as an archive.
This method will not download and extract your archive, it will copy the s3 object across

#### Naming

Optionally, you can change the naming of the relased file using the namePattern option

This option will receive the following properties from the archive:
```
project
channel
version
number
arch
ext
```
And replace the keys in your name pattern

## TODO

* Additional deploy-methods
* Builds cleanup via the kart binary
* UI for remote configuration management via the kart binary
* Adding/removing projects
* UI for listing and downloading builds
* Tests using [mock-aws-s3](https://github.com/MathieuLoutre/mock-aws-s3)
* Make a Github release when pushing to certain channels
* Add --version flag

## Licence

Expand Down
19 changes: 18 additions & 1 deletion lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Release extends Build {
constructor(opts) {
super(opts);
this.releaseDate = new Date(opts.releaseDate);
this.namePattern = opts.namePattern || ':project_:version-:number_:arch.:ext';
}

toJSON() {
Expand All @@ -100,10 +101,26 @@ class Release extends Build {
metadata: this.metadata
});
}

updateReleaseDate () {
this.releaseDate = new Date();
}
get path() {
return `${this.project}/${this.channel}/` +
`${Release.generateName(this.namePattern, this)}`;
}
static generateName(pattern, build) {
const keys = [
'project',
'channel',
'version',
'number',
'arch',
'ext',
];
return keys.reduce((acc, key) => {
return acc.replace(new RegExp(`:${key}`, 'g'), build[key]);
}, pattern);
}
}

module.exports = {
Expand Down
23 changes: 11 additions & 12 deletions lib/deploy-methods/s3-copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ function _updateProgress(reporter, message) {
}
}

function _doRelease(build, track, reporter) {
function _doRelease(build, track, namePattern, reporter) {
// Copy the original build and change the channel to the target one
const targetBuild = Build.fromListEntry({ Key: build.path, LastModified: build.buildDate });
targetBuild.channel = track;
const release = new Release(Object.assign({}, build, { namePattern, channel: track }));
// Copt the s3 object to the new location
return (new Promise((resolve, reject) => {
s3.getInstance().copyObject({
Bucket: config.local.rootBucket.name,
CopySource: `${config.local.rootBucket.name}/${build.path}`,
Key: targetBuild.path,
Key: release.path,
}, (err, res) => {
if (err) {
return reject(err);
Expand All @@ -28,7 +27,6 @@ function _doRelease(build, track, reporter) {
}))
.then(() => {
_updateProgress(reporter, 'File moved to release channel')
const release = new Release(build);
release.updateReleaseDate();
return release;
});
Expand Down Expand Up @@ -110,20 +108,21 @@ 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.track Target track.
* @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.track Target track.
* @param {String} opts.namePattern A pattern for the naming of the released file.
* @param {String} opts.reporter An optional event listener to report events.
*/
function release(build, opts) {
if (!opts.track) {
throw new Error('No track specified');
}
const { track, reporter } = opts;
const { track, reporter, namePattern } = opts;

return _doRelease(build, track, reporter)
return _doRelease(build, track, namePattern, reporter)
.then((r) => {
return _uploadKartFile(r, config.local.rootBucket.name)
return _uploadKartFile(build, config.local.rootBucket.name)
.then(() => r);
});
}
Expand Down
13 changes: 13 additions & 0 deletions test/release-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,19 @@ describe('kart', function () {
assert.equal(status.version, release.version, 'Release status does not match');
});
});
it('rename archive', () => {
let build, release

return testUtil.generateAndArchiveBuilds([
{ project: 'testing', channel: 'rename', version: '1.2.3', metadata: { revision: '1234567' }, options: { fileCount: 1, subdirs: 0 } },
]).then((res) => {
build = res[0];
return kart.release(build.archive);
}).then((r) => {
release = r;
assert.equal(release.path, 'testing/testing-public/testing-1.2.3.tar.gz');
});
});
});
});
});
7 changes: 7 additions & 0 deletions test/test-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ class TestUtil {
method: "s3-copy",
track: "testing-public",
}
},
rename: {
deploy: {
method: "s3-copy",
track: "testing-public",
namePattern: ":project-:version.:ext"
}
}
}
}
Expand Down

0 comments on commit 036b31d

Please sign in to comment.