Snowflake on Heroku Via ODBC - ruby-on-rails

Update - I got it working by using Sequel and Ruby-ODBC gems and a different build pack for Heroku (https://elements.heroku.com/buildpacks/daasity/heroku-buildpack-snowflake-odbc)
Had to amend the AptFile line
https://sfc-repo.snowflakecomputing.com/odbc/linux/2.18.3/snowflake-odbc-2.18.3.x86_64.deb
to
https://sfc-repo.snowflakecomputing.com/odbc/linux/latest/snowflake-odbc-2.21.0.x86_64.deb
I am looking for some advice to help resolve an issue I am having trying connect a Rails 5.1 app to a Snowflake database via ODBC on Heroku.
I have tried various methods but keep hitting different issues.
Steps taken so far:
Added heroku-community/apt buildpack
Created AptFile with the below packages:
unixodbc
unixodbc-dev
https://raw.githubusercontent.com/carwow/heroku-buildpack-snowflake-odbc/master/snowflake-odbc.deb
Added odbc_adapter gem (https://github.com/localytics/odbc_adapter)
Modified my database.yml file to include :snowflake connection details.
Created a new class to mirror a table held in Snowflake, added a line to establish_connection to snowflake and a method to test the connection.
When I run this locally, everything works perfectly. When I deploy to Heroku and try to run the same method I get this error:
ODBC::Error: S1000 (-1) [unixODBC][DSI] The error message SFRestRequestFailed could not be found in the en-US locale. Check that /app/.apt/usr/lib/snowflake/odbc/lib/SFMessages_en-US.xml exists.
When I check the file structure on Heroku, I can see that SFMessages_en_US.xml is in a different path.
I tried using isql -v to see if I could get more details but that returns an error:
[28000][unixODBC][DSI] The error message DSIReqSettingNotFound could not be found in the en-US locale. Check that /app/.apt/usr/lib/snowflake/odbc/lib/ODBCMessages_en-US.xml exists.
I've been trying to get this to work but without being able to see the underlying error I am stuck.

Try adding the following (copied from Dockerfile, so you need to change that to match Heroku) before installing SNFLK ODBC drivers:
ENV LANGUAGE=en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
RUN apt-get install locales && locale-gen

Related

How to setup Rails System Test

I am currently trying to set up some system testing for my rails web application (using Rails version 7.0.3.1)
When running rails test:system to run a single system test I had written, I am getting the below setup-related error
Command '/usr/bin/chromium-browser' requires the chromium snap to be installed.
Please install it with:
snap install chromium
.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/webdrivers-5.0.0/lib/webdrivers/system.rb:190:in `call': Failed to make system call: ["/usr/bin/chromium-browser", "--product-version"] (RuntimeError)
And then, when I try to run
snap install chromium
as suggested by the error I am getting back, I then run into the following error
error: cannot communicate with server: Post http://localhost/v2/snaps/chromium: dial unix /run/snapd.socket: connect: no such file or directory
I am lost as to how to move forward with this issue, which is preventing me from being able to run any system tests. There also seem to not be too many related issues online currently that applied to this case. Any help/ suggestions on where to look to further troubleshoot this error would be greatly appreciated.
Try to install it from the Google, depends on your ubuntu versions:
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
apt install ./google-chrome-stable_current_amd64.deb

How does one make sure that their rails environment on one machine is the same as another?

I have three macs. I have a rails app, that I can run on two of them. On the third, I can create a new rails app and it works fine and some of my other rails apps from the other machines work fine, however the one that I need to have work on the one machine always gives me a message about not being able to find an image:
/Users/woo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require': dlopen(/Users/woo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError)
Referenced from: /usr/local/opt/mysql/lib/libmysqlclient.21.dylib
Reason: image not found - /Users/woo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle
I have followed suggestions about installing the mysql2 bundle using:
gem install mysql2 -v '0.5.3' -- --with-cflags=\"-I/usr/local/opt/openssl/include\" --with-ldflags=\"-L/usr/local/opt/openssl/lib\"
then bundle install, and it says all is fine. Yet 'rails s' produces that unable to find image message.
I use rbenv to manage versions and on all machines ruby is 2.6.3 and rails is 5.2.4.
What other aspects of the configuration of the app do I need to check to make sure they are the same? I have a script called 'laptop' that I obtained using:
cd ~
curl --remote-name https://raw.githubusercontent.com/monfresh/laptop/master/mac
curl --remote-name https://raw.githubusercontent.com/monfresh/laptop/master/Brewfile
/usr/bin/env bash mac 2>&1 | tee ~/laptop.log
I run this on each machine when I am setting up to install or run a rails app. On the problem machine I do get messages like:
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
File "/usr/local/Cellar/python#2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
during the laptop run, but at the end it says all modules were installed correctly. I have a feeling that's not really true and may be part of the problem. If so, what is causing this? I'm running OS X 10.14.6 on the machine in question.
I also notice that libssl.1.0.0.dylib is NOT present at the specified location. How do I install this and moreover, how to I make sure that all of these pieces are properly coordinated?
Found it finally! Thank you:
https://rorguide.blogspot.com/2011/07/getting-error-library-not-loaded.html
I had looked at a lot of these and tried the making a soft link to no effect, but this was the first time I found this one!:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
worked!

rails s command does not run from ssh

I am using Putty to connect to my localhost, and I don't have any problems apparently, however, when I run command rails s to start my rails 4.0.0 application from Putty, it gives me this message:
jose#jose-laptop:~/rails/dedicated-agenda$ rails s
The program 'rails' can be found in the following packages:
ruby-railties-3.2
ruby-railties-4.0
Try: sudo apt-get install
I don't get that message from the terminal though, the application starts running just fine.
I had to reinstall ubuntu so I upgraded to ubuntu 14.04 just in case you need to know.
I don't know if I am missing something in my ssh settings or how could I use rails s from Putty.
Thanks in advance.
Your PATH environment variable is set differently when you are executing programs in an interactive shell and by ssh(using putty).
Use absolute path of the program to not depend on the PATH variable.
You can also set the right PATH variable at ~/.profile file and load the updated variables using the command source ~/.profile.
Now, you should be able to run the command.
You can use the command
>which rails
to see where rails is installed on your working session.
Then you need to make sure that is in your path when you ssh in.
If you are ssh'ing in as a different use then that user may not have permission to see the rails executable.

How to use rails bundler behind a proxy network?

I am using ubuntu 12.04. I am trying to run
bundle install
behind the proxy network of my institute.I have correctly setup the apt.conf file and all other downloads from terminal are working fine. I added the following to ~/.bashrc
export HTTP_PROXY=http://user:password#proxy_url:port
alias curl="curl -x http://proxy_url:port/ -U user:password"
alias rvm="rvm --proxy http://user:password#proxy_url:port"
And i added the following to my environment file:
http_proxy="http://user:password#proxy_url:port/"
https_proxy="https://user:password#proxy_url:port/"
ftp_proxy="ftp://user:password#proxy_url:port/"
socks_proxy="socks://user:password#proxy_url:port/"
I also added the following to ~/.gemrc:
http-proxy:http://user:password#proxy_url:port
After making all these changes when i run the bundler using with or without sudo on the terminal i get back the source code of some html page.The code of html page is followed by the line:
Net::HTTPProxyAuthenticationRequired:
Please tell me what to do to make rails run behind the proxy.
This isn't a Rails question per-se, it's a Bundler question.
I would try the following on the command line (either should work):
export HTTP_PROXY=http://user:password#proxy_url:port
export http_proxy=http://user:password#proxy_url:port
Potentially your ~/.bashrc file isn't being executed on login/etc.
I would also change the ~/.gemrc file to: http_proxy=http://user:password#proxy_url:port
Check out the source code in Bundler for any extra information you may need.

Node.js not found by Rails / execjs

I have node.js installed by compiling and installing it from the root user. I think this maybe where the hangup is. From the user running the rails app I checked for node.js.
$ which node
/usr/local/bin/node
When I launched my rails app (Rails 3.2.9) I get the universally unhelpful "We're sorry, but something went wrong." Checking the the production error log I saw that the Javascript runtime was not found. That's confusing as it is obviously installed. So I went about forcing the Node javascript runtime. I edited config/boot.rb to include:
ENV['EXECJS_RUNTIME'] = 'Node'
I checked my app again, while watching the production log. This time I got the error
ActionView::Template::Error (Node.js (V8) runtime is not available on this system
Still confused. I went to the execjs gem and changed the runtime command to the exact installed path.
Node = ExternalRuntime.new(
:name => "Node.js (V8)",
:command => "/usr/local/bin/node",
:runner_path => ExecJS.root + "/support/node_runner.js",
:encoding => 'UTF-8'
)
I still get the same error. Node is installed and accessible by the user but the gem/rails can't seem to use it.
The server is run CentOS 6.3. The specific javascript file causing the error to be thrown is jquery.nivo.slider.pack.js. Which I didn't edit after downloading it from nivo.
So, I have Ruby 2.0.0 installed and Rails 4.0.2 on CentOS 5.10 using Apache2 with Passenger. My first step I tried was opening the rails console and typing in the following command:
ExecJS.runtime
It returned the following value:
#<ExecJS::ExternalRuntime:0x99ab380 #name="Node.js (V8)", #command=["nodejs", "node"],#runner_path="/home/foo/vendor/bundle/ruby/2.0.0/gems/execjs-2.1.0
/lib/execjs/support/node_runner.js", #encoding="UTF-8", #deprecated=false, #binary="node">
Which meant that node was indeed installed and detected, but for some reason it was not working.
So, I tried the example on the website:
ExecJS.eval("'red yellow blue'.split(' ')")
and I got the correct response. So, now I am wondering why Passenger isn't picking it up.
Then, I noticed that passenger shows the path variable and it looks like:
/home/foo/vendor/bundle/ruby/2.0.0/bin:/usr/local/rvm/gems/ruby-2.0.0-p481/bin:/usr/local/rvm/gems/ruby-2.0.0-p481#global/bin:/usr/local/rvm/rubies/ruby-2.0.0-p481/bin:/usr/kerberos/bin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/rvm/bin:/home/foo/bin
But, it seems to be missing the usr/local/bin. I'm no expert on Linux, so for me the easiest way to fix this is with a symbolic link. So, I execute ln -s /usr/local/bin/node /usr/bin/node. You may want to note that I found the path to my nodejs using the command find / -name node.
I then refreshed my web application and wouldn't you know it worked. So, if it worked for me I am hoping that it can help someone else out.
UPDATE (Probably Better Way): This is probably a better way to do it. We can compile it from source like so:
mkdir ~/install
cd ~/install
wget https://nodejs.org/dist/v7.2.1/node-v7.2.1.tar.gz
tar xvf node-v7.2.1.tar.gz
cd node-v7.2.1
./configure --prefix=/usr/
make && make install
This way Node.js will be installed in the path where Passenger expects it to be.
I have had similar issue installing nodejs with source on my centos 6.3 system. It was successfully installed but I keep failing in compiling my ror app assets until I explicitly set the PATH to where it was installed (nodejs)
[root]# make install
...
installing /usr/local/lib/node_modules/npm/html/doc/folders.html
symlinking ../lib/node_modules/npm/bin/npm-cli.js -> /usr/local/bin/npm
updating shebang of /usr/local/bin/npm to /usr/local/bin/node
[root]# export PATH=/usr/local/bin:$PATH
Now it works. Hope that helps!
I don't know if this will help but check your $PATH that node is in there. Also, you should be using rvm if you want to use node. Check that your node install is done correctly.

Resources