keystonejs / keystone-classic

Node.js CMS and web app framework
http://v4.keystonejs.com
MIT License
14.64k stars 2.21k forks source link

Heroku deployment - Cloudinary issues #475

Closed tymekpudlik closed 8 years ago

tymekpudlik commented 10 years ago

Hello,

I am beginner with KeystoneJS and I am trying to deploy my first application on Heroku. Pushing repository works fine without errors but when I try to open site in web browser, there is an error and heroku logs shows information that I've pasted below. I assume that is an issue related with cloudinary service. I've tried all 3 options to configure it (env file and .set methods in keystone.js) and all of them works locally. I was trying to figure it out what's wrong here, but without any results. I thought that is related with Cloudinary types so I've created an empty Keystone app without blog, gallery examples - even in that case, there are similar issues that some of modules have problems with cloudinary config. Also I've found similar thread on Google discussion group but no one answered there. Are there any tips for pushing KeystoneJS app on Heroku?

Related thread: https://groups.google.com/forum/#!searchin/keystonejs/heroku/keystonejs/UBoHR107GbQ/VKvfVyZt1jsJ

Errors fragment: 2014-07-17T21:36:35.981052+00:00 app[web.1]: at Module.load (/app/node_modules/keystone/node_modules/cloudinary/nodemodule s/coffee-script/lib/coffee-script/register.js:45:36) 2014-07-17T21:36:35.981035+00:00 app[web.1]: 2014-07-17T21:36:35.981046+00:00 app[web.1]: at Function..each._.forEach (/app/node_modules/underscore/underscore.js:82:22 ) 2014-07-17T21:36:35.981056+00:00 app[web.1]: at require (module.js:380:17) 2014-07-17T21:36:35.981037+00:00 app[web.1]: See http://keystonejs.com/docs/configuration/#cloudinary for more information. 2014-07-17T21:36:35.981053+00:00 app[web.1]: at Function.Module._load (module.js:312:12) 2014-07-17T21:36:35.981032+00:00 app[web.1]: 2014-07-17T21:36:35.981034+00:00 app[web.1]: CloudinaryImage fields (Gallery.heroImage) require the "cloudinary config" optio n to be set. 2014-07-17T21:36:35.981042+00:00 app[web.1]: at List. (/app/node_modules/keystone/lib/list.js:202:16) 2014-07-17T21:36:35.981048+00:00 app[web.1]: at Object. (/app/models/Gallery.js:13:9) 2014-07-17T21:36:35.981067+00:00 app[web.1]: at Function.Module._load (module.js:312:12) 2014-07-17T21:36:35.981051+00:00 app[web.1]: at Object.Module._extensions..js (module.js:474:10) 2014-07-17T21:36:35.981066+00:00 app[web.1]: at Module.load (module.js:356:32) 2014-07-17T21:36:35.981060+00:00 app[web.1]: at [object Object].Keystone.import (/app/node_modules/keystone/index.js:1402:9 ) 2014-07-17T21:36:35.981044+00:00 app[web.1]: at List. (/app/node_modules/keystone/lib/list.js:232:5) 2014-07-17T21:36:35.981039+00:00 app[web.1]: at new cloudinaryimage (/app/node_modules/keystone/lib/fieldTypes/cloudinaryim age.js:35:9) 2014-07-17T21:36:35.981047+00:00 app[web.1]: at List.add (/app/node_modules/keystone/lib/list.js:206:4) 2014-07-17T21:36:35.981059+00:00 app[web.1]: at doImport (/app/node_modules/keystone/index.js:1380:28) 2014-07-17T21:36:35.981040+00:00 app[web.1]: at List.field (/app/node_modules/keystone/lib/list.js:329:14) 2014-07-17T21:36:35.981027+00:00 app[web.1]: Error: Invalid Configuration 2014-07-17T21:36:35.981057+00:00 app[web.1]: at /app/node_modules/keystone/index.js:1393:34 2014-07-17T21:36:35.981054+00:00 app[web.1]: at Module.require (module.js:364:17) 2014-07-17T21:36:35.981064+00:00 app[web.1]: at Object.Module._extensions..js (module.js:474:10) 2014-07-17T21:36:35.981069+00:00 app[web.1]: at startup (node.js:119:16) 2014-07-17T21:36:35.981068+00:00 app[web.1]: at Function.Module.runMain (module.js:497:10) 2014-07-17T21:36:35.981038+00:00 app[web.1]: 2014-07-17T21:36:35.981049+00:00 app[web.1]: at Module._compile (module.js:456:26) 2014-07-17T21:36:35.981058+00:00 app[web.1]: at Array.forEach (native) 2014-07-17T21:36:35.981071+00:00 app[web.1]: 2014-07-17T21:36:35.981061+00:00 app[web.1]: at Object. (/app/keystone.js:42:16) 2014-07-17T21:36:35.981063+00:00 app[web.1]: at Module._compile (module.js:456:26) 2014-07-17T21:36:35.981070+00:00 app[web.1]: at node.js:906:3 2014-07-17T21:36:37.241603+00:00 heroku[web.1]: State changed from starting to crashed 2014-07-17T21:36:37.234676+00:00 heroku[web.1]: Process exited with status 8 2014-07-17T21:36:38.240673+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=kajtekssc.hero kuapp.com request_id=3abd6fd7-a34a-4cc9-ab5c-11597fb03938 fwd="84.234.112.13" dyno= connect= service= status=503 bytes=

estilles commented 10 years ago

@tymekpudlik,

Use of Cloudinary in Keystone requires setting the cloudinary config option, see Keystone configuration. This can be done directly in your app using Keystone.set() function or by setting the environment variable CLOUDINARY_URL.

Given the attached log, I'm guessing you set CLOUDINARY_URL in your development environment (either manually or using .env), but not int Heroku. I can't comment on your use of .set() within your app because you didn't include any code.

So, basically you have two options. Either you set the cloudinary config option inside your app, in which case it should work properly in both your local development environment and Heroku, or you can set the CLOUDINARY_URL environment variable in Heroku. The Keystone configuration has a very clear explanation on how to set the cloudinary config option within your app.

If you choose the later method, you also have two options. First, you can set the CLOUDINARY_URL variable in the Heroku Dashboard for your app. In the Dashboard, under Settings, there a section called Config Variables. Click the button labeled Reveal config vars and you will be able to add your CLOUDINARY_URL variable there.

image

Your second option is to use the Heroku CLI to add the variable to your app, see Configuration and Config Vars. Specifically, use the heroku config:set command. See example below.

$ heroku config:set CLOUDINARY_URL=cloudinary://api_key:api_secret@cloud_name
Adding config vars and restarting myapp... done, v12
CLOUDINARY_URL: cloudinary://api_key:api_secret@cloud_name

$ heroku config
CLOUDINARY_URL: cloudinary://api_key:api_secret@cloud_name
NODE_ENV:    production

$ heroku config:get CLOUDINARY_URL
cloudinary://api_key:api_secret@cloud_name

$ heroku config:unset CLOUDINARY_URL
Unsetting CLOUDINARY_URL and restarting myapp... done, v13

Hope this clarifies your issue.

tymekpudlik commented 10 years ago

@JohnnyEstilles

Thank you very much for your quick feedback. Yes, I have defined these variables in .env file. And I've set them on my Heroku, as you said. It started to work. I am not so familar and just a beginner (both with KeystoneJS and Heroku deployment) so it was very helpful.

But I've tried also before to set these variables as I mentioned - in keystone.js. You've mentioned that with this kind of configuration it should work on Heroku without setting environment variable for application in Heroku's dashboard. And I know I did not paste my code but the only thing I've tried is to put .set() method in keystone.js file (as in your links from keystone site). So I've used code in the end of keystone.js file (of course with my Cloudinary credentials):

keystone.set('cloudinary config', { cloud_name: 'my-cloud', api_key: 'abc', api_secret: '123' });

And bigger fragment of keystone.js:

keystone.set('nav', {
    'posts': ['posts', 'post-categories'],
    'galleries': 'galleries',
    'enquiries': 'enquiries',
    'ys': 'ys'
});

// Cloudinary config (I've added it here)
keystone.set('cloudinary config', { cloud_name: 'my-cloud', api_key: 'abc', api_secret: '123' });

// Start Keystone to connect to your database and initialise the web server

keystone.start();

Maybe I am just pasting this method in the wrong place. Anyway - thank you for your help - now I am able to have KeystoneJS app on Heroku.

estilles commented 10 years ago

@tymekpudlik

Glad to be of service. Not quite sure why keystone.set() is not working for you. I typically keep configuration, such as API keys, outside of my apps (which I personally consider good practice), so all the production apps I have on Heroku use environment variables. That said, I did on one occasion hard coded the Cloudinary configuraiton using keystone.set() for quick demo, and it worked fine on both Heroku and AppFog.

I'm curious if anyone else has had any experience similar to that of @tymekpudlik.

grabbou commented 10 years ago

I am using Heroku and Cloudinary in my private project actually. If you can @tymekpudlik share an access with your repo or code somewhere (might be private github repo if you want), so we can help you - that'd be great. Please let me know if the error still persists.

jamesleebaker commented 9 years ago

I am having this same error message when deploying my keystone application to a VPS. I tried setting my cloudinary config in keystone.js like @JohnnyEstilles, but no avail.

sebmck commented 9 years ago

@jamesleebaker It's likely that you're importing your models before cloudinary config has been set, it's critical that your models are imported after configuration.

connor11528 commented 8 years ago

I added this in to my keystone.js file:

if (keystone.get('env') == 'production'){
    keystone.set('cloudinary config', process.env.CLOUDINARY_URL);
    keystone.set('cookie secret', process.env.COOKIE_SECRET);
    keystone.set('mandrill api key', process.env.MANDRILL_API_KEY);
}

To set the variables in heroku do

$ heroku config:set MANDRILL_API_KEY=YOUR_API_KEY
$ heroku config:set CLOUDINARY_URL=cloudinary://YOUR_URL@PROJECT_NAME
$ heroku config:set NODE_ENV=production
$ heroku config:set COOKIE_SECRET=YOUR_COOKIE_STRING

Values come from whatever is in your .env file

creynders commented 8 years ago

Closing due to inactivity, feel free to comment again if this issue persists for you!