forked from alibaba/funcraft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docker-file-sharing-fixed (alibaba#353)
- Loading branch information
1 parent
e2f7870
commit 04def63
Showing
9 changed files
with
114 additions
and
5 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,46 @@ | ||
'use strict'; | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
const USER_HOME = require('os').homedir(); | ||
const defaultFileSharingPaths = [ | ||
'/Users', | ||
'/Volumes', | ||
'/private', | ||
'/tmp' | ||
]; | ||
|
||
async function getSharedPathsOfDockerForMac() { | ||
|
||
const settingsPath = path.join(USER_HOME, 'Library/Group Containers/group.com.docker/settings.json'); | ||
|
||
const fileData = await fs.readFile(settingsPath, 'utf8'); | ||
|
||
const settings = JSON.parse(fileData); | ||
|
||
if (settings.hasOwnProperty('defaultFileSharingPaths')) { | ||
return settings.defaultFileSharingPaths; | ||
} | ||
return defaultFileSharingPaths; | ||
} | ||
|
||
async function findPathsOutofSharedPaths(mounts) { | ||
|
||
const dockerSharedPaths = await getSharedPathsOfDockerForMac(); | ||
let pathsOutofSharedPaths = []; | ||
for (let mount of mounts) { | ||
const mountPath = mount.Source; | ||
let isMountPathSharedToDocker = false; | ||
for (let dockerSharedPath of dockerSharedPaths) { | ||
if (mountPath.startsWith(dockerSharedPath)) { | ||
isMountPathSharedToDocker = true; | ||
break; | ||
} | ||
} | ||
if (!isMountPathSharedToDocker) { | ||
pathsOutofSharedPaths.push(mountPath); | ||
} | ||
} | ||
return pathsOutofSharedPaths; | ||
} | ||
|
||
module.exports = { findPathsOutofSharedPaths }; |
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
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
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,35 @@ | ||
'use strict'; | ||
|
||
const expect = require('expect.js'); | ||
const sinon = require('sinon'); | ||
const sandbox = sinon.createSandbox(); | ||
const dockerSupport = require('../lib/docker-support'); | ||
const fs = require('fs-extra'); | ||
|
||
describe('test getMountPathsNotSharedToDocker', () => { | ||
let readFile; | ||
beforeEach(() => { | ||
readFile = sandbox.stub(fs, 'readFile'); | ||
}); | ||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
it('mount paths all shared to docker', async () => { | ||
readFile.returns('{}'); | ||
const mounts = [{'Source': '/Users/test'}, {'Source': '/Volumes/test'}]; | ||
|
||
const res = await dockerSupport.findPathsOutofSharedPaths(mounts); | ||
expect(res).to.eql([]); | ||
}); | ||
|
||
it('mount paths not shared to docker', async () => { | ||
readFile.returns('{}'); | ||
const mounts = [{'Source': '/uuu/test'}, {'Source': '/vvv/test'}]; | ||
|
||
const res = await dockerSupport.findPathsOutofSharedPaths(mounts); | ||
expect(res).to.eql(['/uuu/test', '/vvv/test']); | ||
}); | ||
|
||
|
||
}); |
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