Loomio
Mon 26 Oct 2015 1:38PM

Help porting Loomio to Sandstorm

ND Nolan Darilek Public Seen by 886

Hello. For the past several days, I've been working on a port of Loomio to the Sandstorm app platform. I think it's going well, and my hope is to have v0.15.0 on the Sandstorm app market sometime this week or next. I'd also like to push the Sandstorm-specific changes upstream for inclusion into Loomio if possible. I built a function that determines whether Loomio is running as a Sandstorm grain, and am selectively disabling/tweaking functionality when that variable is set.

But I'm encountering an odd issue, and I can't seem to find anything in the tech manual. When I delete the initial discussion from new groups, the discussion vanishes but the "plan a trip to the moon" proposal sticks around. When I click on it, I get a "not found" page.

Digging through the code, I see that @discussion.delayed.destroy is called. This leads me to believe that I need to start scripts/delayed_job, but I see nothing about this in the manual. Also, starting it doesn't seem to make the proposal vanish either, so I'm wondering if perhaps it's crashing and not logging its failure on stdout. That's something I'll be investigating next.

But do I in fact need to start scripts/delayed_job, and if so, is there any setup work I need to do first? (I.e. initializing the delayed_job database tables)

I haven't done Rails in quite a while. Can delayed_job periodically run tasks like the automatic closing of proposals? Since the app isn't constantly running, cron isn't an option. Having the tasks run immediately on startup and every 15 minutes or so would be acceptable.

Thanks.

JK

James Kiesel Sat 7 Nov 2015 6:56PM

Hm, yes we're doing semi-weekly releases, so we're actually up to 0.17.0 now (you can note the current version # on production - as of this writing 0.17.8). However, the changes aren't so massively severe as to cripple it, especially given that you're likely not dealing with the angular frontend that much.

Looking at that 2.1.2 tag is making my head hurt as well; I'm not sure why it's there.

ND

Nolan Darilek Mon 16 Nov 2015 5:03PM

I'm working on upgrading my port to 0.17.0. Unfortunately, it refuses to load any static assets with the following errors:

Started GET "/js/app.js?1447692365" for 127.0.0.1 at 2015-11-16 16:46:05 +0000

ActionController::RoutingError (No route matches [GET] "/js/app.js"):
  actionpack (4.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.3) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.3) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.3) lib/rails/rack/logger.rb:20:in `call'
  ahoy_matey (1.1.1) lib/ahoy/engine.rb:20:in `call_with_quiet_ahoy'
  request_store (1.1.0) lib/request_store/middleware.rb:8:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.4) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/static.rb:116:in `call'
  heroku-deflater (0.5.3) lib/heroku-deflater/skip_binary.rb:19:in `call'
  rack (1.6.4) lib/rack/deflater.rb:35:in `call'
  heroku-deflater (0.5.3) lib/heroku-deflater/serve_zipped_assets.rb:50:in `call'
  rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
  airbrake (4.1.0) lib/airbrake/user_informer.rb:16:in `_call'
  airbrake (4.1.0) lib/airbrake/user_informer.rb:12:in `call'
  railties (4.2.3) lib/rails/engine.rb:518:in `call'
  railties (4.2.3) lib/rails/application.rb:165:in `call'
  rack (1.6.4) lib/rack/content_length.rb:15:in `call'
  thin (1.6.3) lib/thin/connection.rb:86:in `block in pre_process'
  thin (1.6.3) lib/thin/connection.rb:84:in `catch'
  thin (1.6.3) lib/thin/connection.rb:84:in `pre_process'
  thin (1.6.3) lib/thin/connection.rb:53:in `process'
  thin (1.6.3) lib/thin/connection.rb:39:in `receive_data'
  eventmachine (1.0.7) lib/eventmachine.rb:187:in `run_machine'
  eventmachine (1.0.7) lib/eventmachine.rb:187:in `run'
  thin (1.6.3) lib/thin/backends/base.rb:73:in `start'
  thin (1.6.3) lib/thin/server.rb:162:in `start'
  rack (1.6.4) lib/rack/handler/thin.rb:19:in `run'
  rack (1.6.4) lib/rack/server.rb:286:in `start'
  railties (4.2.3) lib/rails/commands/server.rb:80:in `start'
  railties (4.2.3) lib/rails/commands/commands_tasks.rb:80:in `block in server'
  railties (4.2.3) lib/rails/commands/commands_tasks.rb:75:in `tap'
  railties (4.2.3) lib/rails/commands/commands_tasks.rb:75:in `server'
  railties (4.2.3) lib/rails/commands/commands_tasks.rb:39:in `run_command!'
  railties (4.2.3) lib/rails/commands.rb:17:in `<top (required)>'
  script/rails:6:in `require'
  script/rails:6:in `<main>'

This worked fine with 0.15.0 so I don't know what the cause is. Also, unfortunately I haven't done Rails in half a decade, so I have no idea where to begin looking. Was something changed WRT static assets between 0.15.0 and 0.17.0? I looked at the diff of 0.17.0 and my sandstorm branch, but nothing jumps out at me.

I'd appreciate any help, as I'm officially out of ideas. Check out my repository https://dev.thewordnerd.info/nolan/loomio-sandstorm. You'll need Vagrant and Vagrant-spk installed, but at that point you can spin up an instance inside a VM and see it in action.

git clone --recursive https://dev.thewordnerd.info/git/nolan/loomio-sandstorm

I think if you do:

cd loomio
git checkout 4b81bb6

you should be back to the working version, as that looks like my initial changes pre 0.17.0 merge.

Thanks.

RG

Robert Guthrie Mon 16 Nov 2015 9:06PM

Arrrrr... Our funky lineman build system stikes again. Sorry about this.

The secret is hidden in lib/tasks/deploy.task

You need to run lineman build and cp -R lineman/dist/* public/ so that the client files are able to be served by the rails app.

ND

Nolan Darilek Tue 17 Nov 2015 2:13AM

Aha, that more or less did it. Thanks.

Now I have another issue in that I was editing the haml files under app/views, not the Lineman UI. When building/running the app, I set a SANDSTORM=1 environment variable so I can tweak the UI. In Lineman, what is the most idiomatic way to check for this environment variable and export something I can query for in the haml templates during the build?

One example is the logo. If the Loomio install isn't official, you output the hostname instead. I expect this is usually OK, but in Sandstorm that appears as something like "eb4c7aa000d30f9f31a5477b2a9920d5.local.sandstorm.io" which is a bit ugly. :) I'd rather replace that with something like "Loomio" in cases where SANDSTORM=1 is set in the build environment where Lineman is run. I'd also like to disable the link to your pricing plans in the start group form for self-hosters, unless there's some reason you'd like that intact (maybe you can check for officialness there too?)

I'm sure I can find the answer, but I'd probably have to understand Lineman/Grunt/several other frameworks first, and I'd honestly just rather get this done so folks have a nice one-click Loomio install. :) Thanks a bunch.

JK

James Kiesel Tue 17 Nov 2015 5:11AM

Hi @nolandarilek,

Check out app/helpers/angular_helper.rb, there you'll see where we set up the app configuration which is passed into the angular interface as the AppConfig.

I reckon some sort of line there like
custom: { sandstorm: ENV['SANDSTORM'] }

which will allow you to use AppConfig.custom.sandstorm in the angular side of things.

ND

Nolan Darilek Tue 17 Nov 2015 5:34AM

Excellent, thanks, that's entirely not where I was looking. :) I was in lineman/config/application.coffee, setting:

  haml:
    options:
      context:
        isInSandstorm: process.env.SANDSTORM?

Then accessing this.isInSandstorm from the templates. Unfortunately something appears to be swallowing the SANDSTORM environment variable somewhere and I can't figure out what.

I'll give your solution a try.

ND

Nolan Darilek Tue 17 Nov 2015 5:39AM

OK, spoke too soon, I don't see app/helpers/angular_helper.rb in 0.17.0. Was that created after 0.17 was released?

JK

James Kiesel Tue 17 Nov 2015 5:58AM

Oh.. right, it's been recently added. If you update to the latest (18.0), it will be there, alternatively in 17.0 it'll be in app/controllers/base_controller.rb

ND

Nolan Darilek Thu 26 Nov 2015 3:16AM

Hey, sorry for the slowness on this, I'm poking at it in my free time, and no offense, but this project is a bit heavy on dependencies and technologies. :)

Trying to get 0.18 running in Loomio, I see lots of attempts to connect to http://localhost:9292. I assume this is some sort of real-time thing for the Angular interface? If so, how do I start it, and is it something that only the app needs to connect to? Or do I need to expose it externally somehow?

Also, I see the following in my logs:

Started GET "/default-cover-photo.png" for 127.0.0.1 at 2015-11-26 02:54:08 +0000

ActionController::RoutingError (No route matches [GET] "/default-cover-photo.png"):

Thoughts on how to fix that? I thought I was generating all my static assets correctly.

I also see that the API uses the PATCH method in places, in setting volumes in comments for instance. Any chance this might be changed? Looks like Sandstorm's HTTP server may block the PATCH method for non-external APIs. I'm asking them about this as well, so perhaps there's hope of changing this from Sandstorm's side.

Thanks.

JD

Josef Davies-Coates Wed 30 Dec 2015 10:16AM

I just joined this group to say THANK YOU @nolandarilek I for one think it is utterly wonderful that you are porting Loomio to Sandstorm! :)

Load More