initial commit

This commit is contained in:
Kegan Myers 2016-06-09 16:13:33 -05:00
commit b26f0aeb3e
8 changed files with 127 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
node_modules

10
LICENSE.md Normal file
View file

@ -0,0 +1,10 @@
Copyright (c) 2016, Skejul, Inc
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby
granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.

25
README.md Normal file
View file

@ -0,0 +1,25 @@
shipit-secrets
==============
A simple secret inclusion task for shipit, inspired by capistrano.
Usage
=====
shipit-secrets works out of the box with shipit-deploy. Simply include files/paths to link as `secrets.files` in your shipit config.
```
module.exports = function(shipit) {
require("shipit-deploy")(shipit);
require("shipit-secrets")(shipit);
shipit.initConfig({
"default": {
secrets: {
files: {
}
}
}
});
});
```js

7
finish.js Normal file
View file

@ -0,0 +1,7 @@
const utils = require("shipit-utils");
module.exports = function (gruntOrShipit, shipit, secretsConfig) {
utils.registerTask(gruntOrShipit, "secrets:finish", () => {
shipit.emit("secrets:done");
});
};

35
index.js Normal file
View file

@ -0,0 +1,35 @@
const utils = require("shipit-utils");
const _ = require("lodash");
module.exports = function (gruntOrShipit) {
const shipit = init(utils.getShipit(gruntOrShipit));
const config = shipit.config || {};
const secretsConfig = Object.assign({}, shipit.config.secrets, {
files: {},
removeBefore: true,
runAfter: "published",
resolveSource: _.template("<%= shipit.config.deployTo %>/secrets/<%= source %>"),
resolveTarget: _.template("<%= shipit.config.deployTo %>/current/<%= target %>")
});
const files = _.mapValues(_.mapKeys(files, (source, target) => {
return resolveTarget({target, shipit})
}), (source) => {
return resolveSource({source, shipit})
});
require("./finish.js")(gruntOrShipit, files);
require("./link.js")(gruntOrShipit, files);
require("./prep.js")(gruntOrShipit, files);
const task = ["secrets:prep", "secrets:link", "secrets:finish"]
if (removeBefore !== true) {
//remove the :prep task
task.shift();
}
utils.registerTask(gruntOrShipit, "secrets", task);
shipit.on(secretsConfig.runAfter, () => shipit.start("secrets"));
};

14
link.js Normal file
View file

@ -0,0 +1,14 @@
const utils = require("shipit-utils");
const chalk = require("chalk");
module.exports = function (gruntOrShipit, files) {
utils.registerTask(gruntOrShipit, "secrets:link", () => Promise.all(_(files).map(linkFile).toArray()).then(() => {
shipit.log(chalk.green("Secrets linked."));
return shipit.emit("secrets:copied");
}));
function linkFile(source, target) {
return shipit.remote(`ln -s "${source}" "${target}"`);
}
};

22
package.json Normal file
View file

@ -0,0 +1,22 @@
{
"name": "shipit-secrets",
"version": "0.0.1",
"description": "A simple way to include secrets ala Capistrano",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"shipit",
"secrets",
"deploy",
"link"
],
"author": "Kegan Myers <kegan@keganmyers.com>",
"license": "ISC",
"dependencies": {
"chalk": "^1.1.3",
"lodash": "^4.13.1",
"shipit-utils": "^1.3.1"
}
}

13
prep.js Normal file
View file

@ -0,0 +1,13 @@
const utils = require("shipit-utils");
const chalk = require("chalk");
module.exports = function (gruntOrShipit, shipit, secretsConfig) {
utils.registerTask(gruntOrShipit, "secrets:prep", () => Promise.all(_(secretsConfig.files).map(removeFile).toArray()).then(() => {
shipit.log(chalk.green("Secrets prepped."));
return shipit.emit("secrets:prepped");
}));
function removeFile(source, target) {
return shipit.remote(`rm -f ${target}`);
}
};