Skip to content
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

fix(exec-script-tmp): uses tmp and mounts volume instead of creating locally #53

Merged
merged 10 commits into from Mar 21, 2017

Conversation

ksafranski
Copy link
Member

@ksafranski ksafranski commented Mar 18, 2017

Instead of creating local devlab.sh this will create in the OS's temp dir, mount, and execute.

Why this wasn't done initially is on me; I just defaulted to /tmp but this caused issues on Mac and Circle. Now the temp directory is determined by the /src/tempdir module which will allow either a custom setting via the DEVLAB_TMP environment variable, or will try to determine the best temp directory to use.

Tested both on my linux server and on my local Mac.

Closes #49 by no longer storing this exec script local.

@ksafranski ksafranski self-assigned this Mar 18, 2017
@ksafranski
Copy link
Member Author

Looks like this approach is still causing issues:

docker: Error response from daemon: Mounts denied: ces for more info.
.
folders/3c/3fxzr4l11l353xd26xg4psnm0000gn/T
is not shared from OS X and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> File Sharing.
See https://docs.docker.com/docker-for-mac/osxfs/#namespa.
ERRO[0000] error getting events from daemon: net/http: request canceled 

@ksafranski
Copy link
Member Author

Mac's default TMPDIR is /var/folders/... which is not a shared folder with the docker client. I don't like the idea of forcing users to share /var, so the latest fix has multiple approaches to fixing this issue.

  1. It will check for a (user defined) DEVLAB_TMP which will allow a user to explicitly set this path
  2. It will check for TEMPDIR (the Mac designation) and use /tmp
  3. If all else fails it uses os-tmpdir to try to get the temp location

@taghost
Copy link

taghost commented Mar 19, 2017

@Fluidbyte I pulled this branch and ran npm run test on my local Mac. Two tests failed due to it using /var/folders/... but then I setup export DEVLAB_TMP=/tmp in my ~/.profile and ran npm run test again, and all tests passed!

src/index.js Outdated
// If override set, use that
? process.env.DEVLAB_TMP
// If MacOS TEMPDIR, use /tmp, else try to find using os-tmpdir
: process.env.TEMPDIR ? '/tmp' : require('os-tmpdir')()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎

@ksafranski
Copy link
Member Author

I'm not really happy with this approach because it seems to be hit or miss. It worked fine for me just letting it default to /tmp, but seems like this could vary on Mac's and having to set an env var (for anything more than customization, fringe cases) seems hacky.

@ksafranski
Copy link
Member Author

Latest commit creates a module which will (I think) do a better job. It's process is:

  1. If DEVLAB_TMP is specified, check if writeable, use that
  2. If not 1, Check if /tmp is writable, use that
  3. If not 2, Check if os-tmpdir suggests a writeable dir, use that
  4. If all else fails, error with notification about manually specifying DEVLAB_TMP, exit

Seems to work everywhere I've tested. Would love some local testing both with and without DEVLAB_TMP set.

The best way to check this is with npm run e2e which will run end-to-end tests.

@ksafranski
Copy link
Member Author

ksafranski commented Mar 19, 2017

The latest approach seems to be checking out where I've tested it. If I can get a couple/few people to check it out it would be appreciated.

QA Test Process

  1. Clone the repo and checkout fix/exec-script-tmp, run npm install
  2. cd test/project and run ../../index.js env and ensure it works
  3. export DEVLAB_TMP=/tmpthen run ../../index.js env and ensure that works
  4. Try setting DEVLAB_TMP to another location like /var and test

If the above look good give me a nod and once I'll get it merged and published.

README.md Outdated
@@ -25,6 +25,8 @@ npm install devlab -g

*Obvious Note: You need to have [Docker](https://www.docker.com/) installed as well.*

**Important Note**: In order to run the tasks, Devlab creates a temp file (`devlab.sh`). The tool will do it's best to determine the best location (usually `/tmp`), but this can be explicitly set by specifying the environment variable `DEVLAB_TMP`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's -> its

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed, just not showing up here...

} else if (isWriteable('/tmp')) {
// Use (most common) /tmp
return '/tmp'
} else if (isWriteable(require('os-tmpdir')())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be preferred over /tmp?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would think that, the problem is it tries to use TMPDIR on Mac which is /var/folders/... and is not shared with Docker on install. In most cases /tmp should work fine and is how you would expect an application to work on *nix systems. This basically is just used when all else fails.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. I do remember having odd trouble with os-tmpdir in the past, which seemed silly since the whole point of that module is that it should just work. Thanks for the explanation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this really is the use-case for weird, non-standard setups or Windows.

@taghost
Copy link

taghost commented Mar 20, 2017

I pulled the latest and ran npm run test which passed tests. I commented out export DEVLAB_TMP=/tmp and ran again, which also passed tests now. So this appears to work for me on my local Mac, yet fwiw I tried the QA Test instructions and couldn't get it working and also npm run e2e didn't all appear to work. Let me know if you want to screenshare and try this together.

@ksafranski
Copy link
Member Author

Checked out ^^^. All good.

@levithomason
Copy link
Member

Sorry for the delay, this is on my list for testing.

@levithomason
Copy link
Member

levithomason commented Mar 21, 2017

2 failures on a fresh pull and deps install. Output trimmed to relevant parts. LMK what I can do to help:

#----------------------------------------------
# basic multiple: Runs multiple tasks
# devlab env test
#----------------------------------------------

> devlab-demo@1.0.0 test /DevLab/test/project
> mocha ./test --recursive

sh: mocha: not found

#----------------------------------------------
# ignore disable: Passes because service is not disabled for all tasks
# devlab env redis:disable
#----------------------------------------------

Error: Cannot find module 'redis'
    at Object.<anonymous> (/DevLab/test/project/scripts/connect.js:1:77)

#----------------------------------------------
# TEST RESULTS: 2 failures
# basic multiple, ignore disable
#----------------------------------------------

Just to be sure, ran it again with fresh deps and got the same results.

@ksafranski
Copy link
Member Author

cd test/project/ && node ../../index.js install

That will install department in the test project, then cd ../../ && npm run e2e

@levithomason
Copy link
Member

hang tight

@levithomason
Copy link
Member

🎉

#----------------------------------------------
# TEST RESULTS: 0 failures
#----------------------------------------------

@ksafranski
Copy link
Member Author

👍

@ksafranski ksafranski merged commit c313d61 into master Mar 21, 2017
@ksafranski ksafranski deleted the fix/exec-script-tmp branch March 21, 2017 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants