commit b26f0aeb3e78bd170758b387cf05f8acebf9b538 Author: Kegan Myers Date: Thu Jun 9 16:13:33 2016 -0500 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..a3396c5 --- /dev/null +++ b/LICENSE.md @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c7d1df2 --- /dev/null +++ b/README.md @@ -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 diff --git a/finish.js b/finish.js new file mode 100644 index 0000000..62fcb94 --- /dev/null +++ b/finish.js @@ -0,0 +1,7 @@ +const utils = require("shipit-utils"); + +module.exports = function (gruntOrShipit, shipit, secretsConfig) { + utils.registerTask(gruntOrShipit, "secrets:finish", () => { + shipit.emit("secrets:done"); + }); +}; diff --git a/index.js b/index.js new file mode 100644 index 0000000..5d7c34e --- /dev/null +++ b/index.js @@ -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")); +}; + diff --git a/link.js b/link.js new file mode 100644 index 0000000..1501dea --- /dev/null +++ b/link.js @@ -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}"`); + } +}; + diff --git a/package.json b/package.json new file mode 100644 index 0000000..2028919 --- /dev/null +++ b/package.json @@ -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 ", + "license": "ISC", + "dependencies": { + "chalk": "^1.1.3", + "lodash": "^4.13.1", + "shipit-utils": "^1.3.1" + } +} diff --git a/prep.js b/prep.js new file mode 100644 index 0000000..a17bb3d --- /dev/null +++ b/prep.js @@ -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}`); + } +};