Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#! /usr/bin/env node | ||
|
||
"use strict"; | ||
var fs = require('fs') | ||
var zlib = require('zlib') | ||
var tar = require('tar') | ||
var fstream = require('fstream') | ||
var args = process.argv.slice(2) | ||
|
||
function usage() { | ||
console.log('usage:') | ||
console.log('machine-share export <machine-name>') | ||
console.log('machine-share import <machine-name>') | ||
} | ||
|
||
if (args.length === 0) { | ||
usage() | ||
process.exit() | ||
} | ||
|
||
if (args.length < 2) { | ||
usage() | ||
process.exit() | ||
} | ||
|
||
var validCmds = new Set(['export', 'import']) | ||
var cmd = args[0] | ||
|
||
if (!validCmds.has(cmd)) { | ||
console.log(args[0] + ' not a command') | ||
} | ||
|
||
// TODO: | ||
// should consider the $MACHINE_STORAGE_PATH env var | ||
function doExport() { | ||
let machineName = args[1] | ||
console.log('exporting ' + machineName) | ||
var path = process.env.HOME + '/.docker/machine/machines/' + machineName | ||
console.log('looking in: ' + path) | ||
try { | ||
var dir = fs.readdirSync(path) | ||
} | ||
catch(e) { | ||
console.log('can\'t find that machine :(') | ||
process.exit() | ||
} | ||
createArchive(path) | ||
} | ||
|
||
function createArchive(path) { | ||
console.log('creating archive') | ||
var dirDest = fs.createWriteStream('dir.tar') | ||
|
||
var packer = tar.Pack({ noProprietary: true }) | ||
.on('error', function() { console.log('tar issues') }) | ||
.on('end', function() { console.log('archive complete') }); | ||
|
||
fstream.Reader({ path: path , type: "Directory" }) | ||
.on('error', function() { console.log('yoo') }) | ||
.pipe(packer) | ||
.pipe(dirDest) | ||
|
||
} | ||
|
||
function doImport() { | ||
|
||
} | ||
|
||
|
||
switch(cmd) { | ||
case 'export': doExport(); | ||
case 'import': doImport(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "machine-share", | ||
"version": "0.0.1", | ||
"description": "share docker machines with friendz", | ||
"bin": { | ||
"machine-share": "./cmd.js" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/bhurlow/machine-share.git" | ||
}, | ||
"keywords": [ | ||
"docker-machine", | ||
"docker", | ||
"export", | ||
"import" | ||
], | ||
"author": "Brian Hurlow", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/bhurlow/machine-share/issues" | ||
}, | ||
"homepage": "https://github.com/bhurlow/machine-share#readme", | ||
"dependencies": { | ||
"fstream": "^1.0.8", | ||
"tar": "^2.2.1" | ||
} | ||
} |