-
Notifications
You must be signed in to change notification settings - Fork 293
Support serverless.yml and serverless.yaml in getBindPath() #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
59566e4
d221b7e
5d8a9a1
9750262
6101797
8e5ad85
1c72e9a
e012cd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
const { spawnSync } = require('child_process'); | ||
const isWsl = require('is-wsl'); | ||
const fse = require('fs-extra'); | ||
const path = require('path'); | ||
|
||
/** | ||
* Helper function to run a docker command | ||
|
@@ -32,24 +34,46 @@ function buildImage(dockerFile) { | |
return imageName; | ||
} | ||
|
||
/** | ||
* Find a file that exists on all projects so we can test if Docker can see it too | ||
* @param {string} servicePath | ||
* @return {string} file name | ||
*/ | ||
function findTestFile(servicePath) { | ||
if (fse.pathExistsSync(path.join(servicePath, 'serverless.yml'))) { | ||
return 'serverless.yml'; | ||
} | ||
if (fse.pathExistsSync(path.join(servicePath, 'serverless.yaml'))) { | ||
return 'serverless.yaml'; | ||
} | ||
if (fse.pathExistsSync(path.join(servicePath, 'serverless.json'))) { | ||
return 'serverless.json'; | ||
} | ||
throw new Error('Unable to find serverless.yml or serverless.yaml or serverless.json for getBindPath()'); | ||
} | ||
|
||
/** | ||
* Test bind path to make sure it's working | ||
* @param {string} bindPath | ||
* @return {boolean} | ||
*/ | ||
function tryBindPath(bindPath) { | ||
function tryBindPath(bindPath, testFile) { | ||
const options = [ | ||
'run', | ||
'--rm', | ||
'-v', | ||
`${bindPath}:/test`, | ||
'alpine', | ||
'ls', | ||
'/test/serverless.yml' | ||
`/test/${testFile}` | ||
]; | ||
try { | ||
const ps = dockerCommand(options); | ||
return ps.stdout.trim() === '/test/serverless.yml'; | ||
if (process.env.SLS_DEBUG) { | ||
console.log(`Trying bindPath ${bindPath} (${options})`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you use the serverless logging facility instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can get to it later this week. We should consider passing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like that idea! Get to it when you get to it 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It ended up being a bigger surgery than I expected as we don't always call these functions with |
||
console.log(ps.stdout.trim()); | ||
} | ||
return ps.stdout.trim() === `/test/${testFile}`; | ||
} catch (err) { | ||
return false; | ||
} | ||
|
@@ -99,10 +123,12 @@ function getBindPath(servicePath) { | |
bindPaths.push(`/mnt/${drive.toLowerCase()}/${path}`); | ||
bindPaths.push(`/mnt/${drive.toUpperCase()}/${path}`); | ||
bindPaths.push(`${drive.toUpperCase()}:/${path}`); | ||
|
||
const testFile = findTestFile(servicePath); | ||
|
||
for (let i = 0; i < bindPaths.length; i++) { | ||
const bindPath = bindPaths[i]; | ||
if (tryBindPath(bindPath)) { | ||
if (tryBindPath(bindPath, testFile)) { | ||
return bindPath; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did serverless drop support for
serverless.json
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not aware that's an option. Let me add that.