Skip to content

Docker, how to npm install for cloud code.... #4590

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

Closed
acinader opened this issue Feb 27, 2018 · 7 comments
Closed

Docker, how to npm install for cloud code.... #4590

acinader opened this issue Feb 27, 2018 · 7 comments
Labels
type:question Support or code-level question

Comments

@acinader
Copy link
Contributor

I've been trying to use the parse-server docker. I've run into a problem trying to use cloud code and I'm curious if anyone has a solution.

If my cloud code requires npm packages (would think this is almost always the case), is there a pattern or solution of how to npm install?

@stephentuso
Copy link
Contributor

stephentuso commented Feb 27, 2018

One option, which I've been using for parse-server-compose, is to install dependencies into the same directory as the cloud code and mount that in docker:

cloud
├── main.js
├── node_modules
│   └── ...
└── package.json

docker run -v /path/to/cloud:/parse-server/cloud ...

If any dependencies use native code and need to be built in the container you'll need to run this first:

docker run --rm -it -v $(pwd):/home/node --workdir /home/node node:boron npm install

@acinader acinader added discussion type:question Support or code-level question labels Feb 27, 2018
@acinader
Copy link
Contributor Author

@stephentuso so I worked out a super hacky workaround that is close to yours:

run npm install -S xxx in the ./cloud dir so that there is a package.json in that dir.

make sure to add parse-server as a dependency.

I'm using aws beanstalk (for now, hopefully switching to kubernetes as soon as I get the time). I overwrite the entry point in my Dockerrun.aws.json to:
"entryPoint": ["sh", "-c" , "/usr/local/bin/npm install /parse-server/cloud ; /usr/local/bin/node /parse-server/bin/parse-server /parse-server/config/configuration.json"],

I'll study what you've got there and see if its an improvement for me.

my hack really sucks because I have to cd into cloud, run install, cd out and then deploy.

i'm wondering if I can somehow adjust an npm-run-script, preinstall or postinstall to check if there is a a ./cloud/package.json and install that....

the ./cloud is hardcoded in the dockerfile

I'm also looking at @yongjhih to see how he does it in https://github.com/yongjhih/docker-parse-server

@stephentuso
Copy link
Contributor

Gotcha yeah that looks about the same, I was only thinking about running locally. Could potentially be easier to just write a new Dockerfile

@acinader
Copy link
Contributor Author

And I spoke too soon. My packages are getting installed. And my cloud code is being processed by parse (if I put a debug log in my cloud code files it ends up in the logs), but when I call my cloud functions parse doesn't fine them with ```error: Invalid function: "sendCode" code=141, message=Invalid function: "sendCode"``

enough debugging on this for today :(

@acinader
Copy link
Contributor Author

I'm going to close this as unresolved for now.

@milesrichardson
Copy link

Just write a regular express app, install parse-server as a dependency and mount it to the express app

@gateway
Copy link

gateway commented Apr 25, 2018

We are running into this issue as well with Docker.. Whats the proper procedure for getting cloud code to work in a container? I see some solutions but has this never been tested till now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question Support or code-level question
Projects
None yet
Development

No branches or pull requests

4 participants