Skip to content

Commit

Permalink
fix: Fix mounting into Tizen Docker image on macOS
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
joeyparrish committed Aug 5, 2020
1 parent 37e1922 commit 9c47c93
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 13 deletions.
96 changes: 96 additions & 0 deletions backends/tizen/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion backends/tizen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"tizen-webdriver-server": "./tizen-webdriver-server.js"
},
"dependencies": {
"generic-webdriver-server": "^1.0.0"
"generic-webdriver-server": "^1.0.0",
"tmp-promise": "^3.0.2"
}
}
55 changes: 43 additions & 12 deletions backends/tizen/tizen-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/


const fs = require('fs');
const path = require('path');
const tmp = require('tmp-promise');
const util = require('util');

const execFile = util.promisify(require('child_process').execFile);
Expand All @@ -33,7 +35,7 @@ const dockerImageAppTemplatePath = '/tmp/app-template';
* the URL into it. If null, send the Tizen device back to the home screen.
* @return {!Promise}
*/
function loadOnTizen(flags, log, url) {
async function loadOnTizen(flags, log, url) {
/**
* We build a set of commands which will be combined and executed in bash -c.
* For locally-installed copies of Tizen Studio, these will be executed in
Expand Down Expand Up @@ -106,18 +108,47 @@ function loadOnTizen(flags, log, url) {

if (flags.localTizenStudio) {
// Run the command locally in bash.
return execFile('bash', ['-c', command]);
await execFile('bash', ['-c', command]);
} else {
// Run the command inside a Docker image.
return execFile('docker', [
'run',
// Mount the app template into the Docker image.
'-v', `${hostAppTemplatePath}:${dockerImageAppTemplatePath}:ro`,
// The name of the image.
flags.tizenStudioDockerImage,
// The command is then run inside bash inside the Docker image.
'bash', '-c', command,
]);
// Docker on macOS will not allow arbitrary paths to be mounted into an
// image by default. Rather than require extra configuration, copy the app
// template into a temporary directory first.
const tmpDir = await tmp.dir({
mode: 0o700, // Only accessible to the owner
prefix: 'tizen-webdriver-server-',
unsafeCleanup: true, // Remove directory contents on cleanup

// Set the parent directory of our temporary directory.
// On macOS, the default for this is not /tmp, but /tmp is what Docker
// allows to be mounted without special configuration. So we need to
// override the default here.
// TODO: test on Windows
tmpdir: '/tmp',
});

try {
// Copy the app template into our temp directory.
const filenames = fs.readdirSync(hostAppTemplatePath);
for (const filename of filenames) {
fs.copyFileSync(
path.resolve(hostAppTemplatePath, filename),
path.resolve(tmpDir.path, filename));
}

// Run the command inside a Docker image.
await execFile('docker', [
'run',
// Mount the app template into the Docker image.
'-v', `${tmpDir.path}:${dockerImageAppTemplatePath}:ro`,
// The name of the image.
flags.tizenStudioDockerImage,
// The command is then run inside bash inside the Docker image.
'bash', '-c', command,
]);
} finally {
// Remove our temporary directory.
tmpDir.cleanup();
}
}
}

Expand Down

0 comments on commit 9c47c93

Please sign in to comment.