rails-sqlserver / heroku-buildpack-freetds

This is a Heroku buildpack for vendoring the FreeTDS binaries into your project.
MIT License
10 stars 31 forks source link

heroku-buildpack-freetds

This is a Heroku buildpack for vendoring the FreeTDS binaries into your project.

Note on Heroku config

Optionally, set the FreeTDS version in a Heroku config like this:

heroku config:set FREETDS_VERSION=1.00.109

Make sure the version you're referencing exists on as a .tar.gz file on the FreeTDS releases.

See load_env_vars in bin/compile for additional configurable variables.

You may also force the buildpack to rebuild the binary. This may be necessary when updating the buildpack.

heroku config:set FREETDS_REBUILD=true

Just don't forget, after a successful release, to unset it.

heroku config:unset FREETDS_REBUILD

How it works

Rather than pulling down binary dependencies from a package manager and extracting them into place, this buildpack compiles FreeTDS from source the first time an app is built with it. The compiled binaries are cached for future builds, so this penalty is only incurred once.

This has the downside of a (potentially very long) deploy time for the first push, with the benefit of a less-fragile build product that's somewhat less likely to break due to platform and dependency shifts. Or at least, that's the hope!

Stack compatibility

This buildpack is tested primarily against the heroku-22 stack.

Allows for usage of TinyTDS on Heroku.

Usage

This is used alongside the Ruby buildpack.

It may be useful to load any client libraries as part of the release task to ensure the libraries linked correctly. For example, in a ruby app, you may add to the Procfile: release: bundle exec ruby -e "p(require 'tiny_tds')"

Install

Use master

heroku buildpacks:set --index 1 https://github.com/rails-sqlserver/heroku-buildpack-freetds

or use a stable tag, like v1.1.5

heroku buildpacks:set --index 1 https://github.com/rails-sqlserver/heroku-buildpack-freetds#v1.1.5

Changelog

Debugging

From 'heroku run bash'.

Print FreeTDS build logs to the screen:

for file in freetds/build_log-*; do echo -e "\n\n----------------------- $file------------------\n\n"; cat "$file"; done

Print TinyTDS build logs to the screen:

# change env vars as needed
( export TINY_TDS_VERSION="2.1.0"; export RUBY_PATH_VERSION="2.5.3"; for cmd in "ld /app/vendor/bundle/ruby/2.5.0/gems/tiny_tds-${TINY_TDS_VERSION}/lib/tiny_tds/tiny_tds.so" \
"cat /app/vendor/bundle/ruby/${RUBY_PATH_VERSION}/gems/tiny_tds-${TINY_TDS_VERSION}/ext/tiny_tds/Makefile" \
"cat /app/vendor/bundle/ruby/${RUBY_PATH_VERSION}/extensions/x86_64-linux/${RUBY_PATH_VERSION}-static/tiny_tds-${TINY_TDS_VERSION}/gem_make.out" \
"cat   /app/vendor/bundle/ruby/${RUBY_PATH_VERSION}/extensions/x86_64-linux/${RUBY_PATH_VERSION}-static/tiny_tds-${TINY_TDS_VERSION}/mkmf.log" ; do
echo -e "\n\n----------------------- $cmd------------------\n\n"; eval "$cmd"; done ; )

Connection Timeout

If you receive connection timeout errors (e.g. "Adaptive Server connection failed"), consider whether TLS/gnutls is interacting poorly with heroku or the server where your mssql server lives. You can set the environment variable heroku config:set USE_GNUTLS=" " and temporarily set heroku config:set FREETDS_REBUILD=true to rebuild the code using TLS. See https://github.com/FreeTDS/freetds/issues/336 for more information.

License

'heroku-buildpack-freetds' is distributed under the MIT license. FreeTDS http://www.freetds.org/ which is licensed under the GNU LGPL license at http://www.gnu.org/licenses/lgpl-2.0.html