├── lib └── .gitkeep ├── .travis.yml ├── .gitignore ├── package.json ├── LICENSE ├── README.md └── src ├── index.js └── clean-help-command.js /lib/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.12" 4 | - "0.11" 5 | - "0.10" 6 | - "iojs" 7 | - "iojs-v1.0.0" 8 | - "iojs-v2.0.0" 9 | - "iojs-v3.0.0" 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Commenting this out is preferred by some people, see 24 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- 25 | node_modules 26 | 27 | # Users Environment Variables 28 | .lock-wscript 29 | 30 | lib 31 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dokku-toolbelt", 3 | "version": "1.1.3", 4 | "description": "Toolbelt for dokku, similar to the heroku toolbelt", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo true" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/digitalsadhu/dokku-toolbelt.git" 12 | }, 13 | "keywords": [ 14 | "dokku", 15 | "toolbelt", 16 | "cli", 17 | "docker" 18 | ], 19 | "author": "Richard Walker ", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/digitalsadhu/dokku-toolbelt/issues" 23 | }, 24 | "homepage": "https://github.com/digitalsadhu/dokku-toolbelt#readme", 25 | "dependencies": { 26 | "dokku-app-ssh": "^1.0.1", 27 | "dokku-git-remote-parser": "^1.1.2", 28 | "highland": "^2.5.1", 29 | "minimist": "^1.1.3" 30 | }, 31 | "preferGlobal": true, 32 | "bin": { 33 | "dt": "src/index.js" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Richard Walker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dokku-toolbelt 2 | 3 | Toolbelt for dokku, similar to the heroku toolbelt 4 | 5 | ## HELP, MAINTAINER WANTED. 6 | 7 | I no longer use dokku personally and would really appreciate someone stepping up to take ownership of this project from me. If you are interested, please create an issue to put your hand up. 8 | 9 | ## Installation 10 | ``` 11 | npm install -g dokku-toolbelt 12 | ``` 13 | 14 | ## Example usage 15 | 16 | ``` 17 | cd /path/to/my/dokku/app 18 | dt config 19 | 20 | =====> app config vars 21 | NODE_ENV: production 22 | ``` 23 | 24 | ## Help 25 | 26 | Running `dt help` or `dt` will output the help text information 27 | 28 | ## Explanation 29 | 30 | Dokku toolbelt essentially just proxies running the `dokku` command on servers 31 | remotely via ssh with a little 'context aware sugar' supplied by running 32 | `git remote -v` in the current directory and parsing out `host` and `appname` 33 | 34 | ## Context aware 35 | 36 | The toolbelt knows from which directory you are in, which server and project you are working with. 37 | It can determine this by using `git remote -v` and looking for the correct host by looking for a dokku@ username 38 | and parsing out the project name from the part after the : character. 39 | 40 | ``` 41 | dokku dokku@my-host.me:my-awesome-project 42 | 43 | # host -> my-host.me 44 | # project -> my-awesome-project 45 | ``` 46 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | 4 | var dokkuGitRemoteParser = require('dokku-git-remote-parser') 5 | var dokkuAppSsh = require('dokku-app-ssh') 6 | var cp = require('child_process') 7 | var _ = require('highland') 8 | var minimist = require('minimist'); 9 | var cleanHelpCommand = require('./clean-help-command') 10 | 11 | var argv = minimist(process.argv.slice(2)) 12 | Object.keys(argv) 13 | .filter(function (arg) { 14 | return arg !== '_' 15 | }) 16 | .forEach(function (arg) { 17 | argv._.push('-' + arg) 18 | }) 19 | var command = argv._.join(' ') 20 | 21 | dokkuGitRemoteParser(function (err, host, appName) { 22 | if (err) { 23 | console.error('Dokku Toolbelt Error:', err.message) 24 | process.exit() 25 | } 26 | 27 | try { 28 | var sshCommand = dokkuAppSsh(host, command, appName) 29 | } catch (err) { 30 | console.error('Dokku Toolbelt Error:', err.message) 31 | process.exit() 32 | } 33 | 34 | //run the command 35 | var commandArgs = sshCommand.split(' ') 36 | var cmd = commandArgs.shift() 37 | var dt = cp.spawn(cmd, commandArgs) 38 | 39 | _(dt.stdout) 40 | .map(function (buffer) { 41 | return buffer.toString() 42 | }) 43 | .through(function (stream) { 44 | if (argv._[0] === 'help' || !argv._[0]) 45 | return cleanHelpCommand(stream) 46 | 47 | return stream 48 | }) 49 | .pipe(process.stdout) 50 | 51 | dt.stderr.pipe(process.stderr) 52 | }) 53 | -------------------------------------------------------------------------------- /src/clean-help-command.js: -------------------------------------------------------------------------------- 1 | var _ = require('highland') 2 | var os = require('os') 3 | 4 | var trim = function (text) { 5 | return text.trim() 6 | } 7 | 8 | var cleanHelpText = function (text) { 9 | if (text.match('Usage')) return text += os.EOL 10 | if (text.match('Options')) return text 11 | if (text.match('apps:create')) return text 12 | 13 | var columnA = text.slice(0, 60) 14 | var columnB = text.slice(60) 15 | 16 | columnA = columnA 17 | .replace(//gi, '') 18 | .replace(/\(\|--global\)/gi, '') 19 | .replace(/\s{2,}/gi, ' ') 20 | while (columnA.length < 60) { 21 | columnA += ' ' 22 | } 23 | 24 | columnB = columnB.replace(' global or ', ' ') 25 | 26 | return columnA + columnB 27 | } 28 | 29 | var indentCommands = function (text) { 30 | if (text.match('Usage')) return text 31 | if (text.match('Options')) return text 32 | 33 | return ' ' + text 34 | } 35 | 36 | var blacklist = [ 37 | 'apps:destroy', 38 | 'backup:export', 39 | 'backup:import', 40 | 'shell', 41 | 'version', 42 | 'ps ' 43 | ] 44 | var blacklistedHelpCommands = function (text) { 45 | for (var item in blacklist) { 46 | if (blacklist.hasOwnProperty(item)) { 47 | if (text.match(item)) { 48 | return 49 | } 50 | } 51 | } 52 | return text 53 | } 54 | 55 | var joinWithNewLines = function (a, b) { 56 | return a + '\n' + b 57 | } 58 | 59 | module.exports = function (stream) { 60 | return stream 61 | .split() 62 | .map(trim) 63 | .filter(blacklistedHelpCommands) 64 | .map(cleanHelpText) 65 | .map(indentCommands) 66 | .reduce1(joinWithNewLines) 67 | } 68 | --------------------------------------------------------------------------------