Where to put monger connection in Compojure app for Heroku? - heroku

I created a compojure app using lein new compojure mongotest with lein 2.0, and a Procfile web: lein ring server-headless $PORT. This worked fine, but now when I add
(def mongolab-url (System/getenv "MONGOLAB_URI"))
(println "mongolab-url")
(println mongolab-url)
(mg/connect-via-uri! mongolab-url)
when I try git push heroku master Heroku eventually gives me
Compiling mongotest.handler
mongolab-url
nil
Exception in thread "main" java.lang.NullPointerException, compiling:(handler.clj:13:1)
... 25 more
Compilation failed: Subprocess failed
Error encountered performing task 'compile' with profile(s): 'production'
Suppressed exit
! Failed to build.
! Push rejected, failed to compile Clojure (Leiningen 2) app
I added these lines at the top level of handler.clj. Some of the older documentation I see the connection is created in main, but that must have been for older versions of compojure, as there's no main anymore (that I've found) in the generated app. Where should the connection get established in the current version? (Or is my Procfile not right?)
(Yes, MONGOLAB_URI is defined in heroku config)

The answer that worked for me and seems most idiomatic is to put the above connection into a function init in that same file (myproject/handler.clj)
(defn init[] (mg/connect-via-uri! (System/getenv "MONGOLAB_URI")))
and update the project.clj file ring descriptor line from
:ring {:handler myproject.handler/app}
to
:ring {:handler myproject.handler/app :init myproject.handler/init}

You don't want side-effects (such as opening a database connection) to happen at namespace load time, which is effectively compile time. Often you can get away with such things, when you are compiling your code when clojure starts up, but in this case heroku is pre-compiling your app into a jar so that it can serve it up more quickly. Now, at compile time, you try to read the PORT environment variable; but it is not set until heroku tries to actually run your app.
The solution is to create it only at runtime, eg by doing so in -main, or in some other function, or by defining it as a delay which you only force at runtime.

Related

Reaction Commerce deployment to Heroku failing, boot_proxy.js not generated

I was trying to set up a running instance running on Heroku by following these instructions. All goes well but after the build is finished, an error occurs and the app crashed.
Error: Cannot find module /app/.meteor/heroku_build/bin/boot_proxy.js
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
Process exited with status 1
This is the content of the Procfile.
web: .meteor/heroku_build/bin/node .meteor/heroku_build/bin/boot_proxy.js .meteor/heroku_build/bin/node .meteor/heroku_build/app/main.js
I used heroku bash to explore the app and saw that The file boot_proxy.js is not being generated. Does anyone know a fix to this? Already filed a bug on git repo.
As it can be found in this forked repo the missing boot_proxy.js comes from a overdue startup of reaction:
Sometimes reaction takes too much time to start and Heroku thinks that there's a problem with your app. To sidestep this we have a simple proxy that answers every request until it's ready.
https://github.com/Zanobo/reaction-buildpack#boot-proxy
So in order to fix the issue, you should use this fork at the buildpack step:
heroku buildpacks:set https://github.com/Zanobo/reaction-buildpack.git
and add this environment variable in Heroku:
USE_BOOT_PROXY=1

Heroku build succeeds but deploy fails (no code change)

I'm getting the following error in LogDNA:
(node:28) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Cannot find module '/tmp/build_[long-hash]/my-project-[long-hash]/node_modules/bluebird'
Process exited with status 0
State changed from starting to crashed
That line contains an import of Bluebird. When I remove the dependency and remove the line, then I get the same error, except it references the next line (which is also a dependency import).
When I deploy a branch that was previously working, I get the same error. Of course, I cannot re-pro this issue locally.
I compared the Dyno's npm list against my local, and they're the same. Also, all of the expected node_modules are, in fact, present in the Dyno's filesystem.
If I use Heroku-bash run the build task manually (with nothing special), then deploy, it's fine.
We had hard-coded/fixed the version of Electrode we're depending on, but Electrode has a fuzzy version for WebPack, which released a new version 5 days ago that caused this error. It causes the imports' paths to be incorrectly resolved/transpiled to the build directory instead of remain relative.
The workaround is to use require() instead of import.

Jekyll Error - "serve" only works once

Started working on an update to my website. It was working fine the other day but now I get an error.
I generally type on CMD (i'm on Windows 10) "bundle exec Jekyll serve --watch" and the server goes. I can edit and save and its all reflected in browser upon refresh.
Now I can do this, but if I make one change to any file it works. Do another change and I get an error. I have to terminate and type again.
Below is the error:
D:\Tristen Grant\Documents\GitHub\portfolio>bundle exec jekyll serve --watch
DL is deprecated, please use Fiddle
Configuration file: D:/Tristen Grant/Documents/GitHub/portfolio/_config.yml
Source: D:/Tristen Grant/Documents/GitHub/portfolio
Destination: D:/Tristen Grant/Documents/GitHub/portfolio/_site
Incremental build: disabled. Enable with --incremental
Generating...
done in 0.595 seconds.
Auto-regeneration: enabled for 'D:/Tristen Grant/Documents/GitHub/portfolio'
Configuration file: D:/Tristen Grant/Documents/GitHub/portfolio/_config.yml
Server address: http://127.0.0.1:3000//
Server running... press ctrl-c to stop.
Regenerating: 1 file(s) changed at 2016-09-06 16:16:28 ...done in 0.521498 seconds.
Regenerating: 1 file(s) changed at 2016-09-06 16:16:30 ...error:
Error: No such file or directory - git rev-parse HEAD
Error: Run jekyll build --trace for more information.
[2016-09-06 16:19:35] ERROR Errno::ENOTSOCK: An operation was attempted on something that is not a socket.
C:/Ruby21-x64/lib/ruby/2.1.0/webrick/server.rb:170:in `select'
Terminate batch job (Y/N)? y
Terminate batch job (Y/N)? y
I'm using Ruby 2.1.5 64 bit version. RubyDevKit, Sass, Bourbon.
Any ideas how to fix this? I don't know much about Jekyll or ruby. Just starting out.
I also get this error in CMD. You should have github's desktop app installed; try running the same commands from the GitShell you get with that app.
For me that works, it saves me the trouble of installing git globally on Windows and setting it up.

Deploy meteor/meteorite 0.8.3 to heroku

I just updated my app to meteor 0.8.3. Locally it runs without problems. But when I try to push it to heroku, I'll get the following error:
Building meteor bundle
simple-schema: updating npm dependencies -- string...
iron-router: updating npm dependencies -- connect...
lodash: updating npm dependencies -- lodash...
Errors prevented bundling:
While building the application:
error: no such package: 'accounts-ui-bootstrap-3'
error: no such package: 'accounts-entry'
While building package `iron-dynamic-template`:
error: no such package: 'blaze'
tar: /app/tmp/cache/bundle.tar.gz: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: Child returned status 2
tar: Exiting with failure status due to previous errors
! Push rejected, failed to compile Meteor app app
For deployment, I used the buildpack of oortcloud. This worked proper in the past. https://github.com/oortcloud/heroku-buildpack-meteorite
I'm most confused by the earlier log entries before the error happens. Here it says that Meteor 0.8.1.1 is being installed. A couple of lines after that it confirms that Meteor 0.8.3 has been installed. I'm pretty sure that this is the same issue like this. https://github.com/EventedMind/iron-dynamic-template/issues/2
Installing Meteor 0.8.1.1
* 'meteor' build tool (vers
* 'meteor' build tool (version 43b8566b9f)
* Package updates: accounts-base accounts-meteor-developer accounts-oauth
accounts-password accounts-ui accounts-ui-unstyled amplify appcache
application-configuration autoupdate browser-policy browser-policy-common
browser-policy-content check coffeescript coffeescript-test-helper ctl
ctl-helper deps ejson email facebook facts follower-livedata force-ssl github
google html-tools htmljs http jquery-waypoints js-analyze less livedata
localstorage logging meetup meteor meteor-developer minifiers minimongo
mongo-livedata oauth oauth-encryption oauth1 oauth2 observe-sequence
reactive-dict routepolicy session showdown spacebars spacebars-compiler
spacebars-tests spiderable srp star-translate stylus templating test-helpers
test-in-browser tinytest twitter ui underscore-tests webapp weibo
Meteor 0.8.3 has been installed in your home directory (~/.meteor).
Now you need to do one of the following:
(1) Add ~/.meteor to your path, or
(2) Run this command as root:
cp ~/.meteor/tools/latest/launch-meteor /usr/bin/meteor
Then to get started, take a look at 'meteor --help' or see the docs at
docs.meteor.com.
I also tried to create a new meteorite app to get rid of dangling dependencies. But without success!
What can I do? Is there a chance to debug the push/deploy on the heroku server?
The outdated file .meteor/release caused the problem:
git heroku push master fetches the files to deploy from the origin git repository. It doesn't care about local, unstaged files. Somehow the file .meteor/release has not been pushed to the origin repository. So during the installation routine at heroku the meteor version was 0.8.1.1 and not 0.8.3.
Solution to avoid this problem:
Check/Add the files .meteor/release and .meteor/packages to your origin git repo
Test only what's in your origin repo before you deploy it. Use git pull

How to debug Errno::EIO error in Chef recipe using Chef::Provider::Git

I'm trying to use chef to check out a git repo to a windows client node.
This seems simple enough and I've got the following resource definition:
git "C:\\pathtocheckout" do
repo "https://gitserver/repo.git"
action [ :checkout, :sync]
end
But when this is reached by chef-client I get:
Errno::EIO: git[C:\pathtocheckout] (cookbook_name::test line 21) had an error: Errno::EIO: Input/output error - CreateProcessW
I've had a look at the stacktrace produced and it appears to be something to do with creating a process to run the git command - but this is the limit of my knowledge.
I've made sure git is installed on on Path, removed all other recipes from the run list, running as a different admin user and I've tried different repositories but all with the same error.
So I'm pretty stumped - anyone got a way I can dig into this error and see what is going on?

Resources