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

Incorrect .profile.d #17

Closed schneems closed 1 year ago

schneems commented 2 years ago

The current .profile.d is broken in a few ways. It does not take into account the difference between build time and runtime differences. On Heroku the build directory will be different than the runtime directory. To account for this other buildpacks do not hardcode paths, but instead use $HOME in their .profile.d scripts. The other problem is that you're completely obliterating any prior $PATH, so if any other buildpack profile.d script runs before this one, this will wipe it out. That's because it does not include a :$PATH at the end to indicate you want to prepend to the PATH instead of overwriting it.

An example from heroku run bash

~ $ cat .profile.d/freetds.sh  | grep " PATH="
  export PATH="/app/freetds/bin:/tmp/build_b5beced7/.heroku/activestorage-preview/usr/bin:/usr/local/bin:/usr/bin:/bin"

Should be:

~ $ cat .profile.d/freetds.sh  | grep " PATH="
  export PATH="$HOME/freetds/bin:$PATH"

You can see this pattern used in other buildpacks:

~ $ cat .profile.d/000_activestorage_preview.sh  | grep " PATH="
export PATH="$HOME/.heroku/activestorage-preview/usr/bin:$PATH"

While the $HOME part isn't strictly necessary, it's a good practice. Not preserving prior $PATH can and does cause problems. When you use this buildpack along with the activestorage preview buildpack then ffmpeg cannot be found:

⛄️ 3.1.2 🚀 /tmp/3ce01b21867258f6d576c61710222b89 (main)
$ heroku run which ffmpeg
Running which ffmpeg on ⬢ warm-spire-40708... up, run.2284 (Free)
/app/.heroku/activestorage-preview/usr/bin/ffmpeg
$ heroku buildpacks:add https://github.com/rails-sqlserver/heroku-buildpack-freetds
Buildpack added. Next release on warm-spire-40708 will use:
  1. https://github.com/heroku/heroku-buildpack-activestorage-preview
  2. https://github.com/rails-sqlserver/heroku-buildpack-freetds
Run git push heroku main to create a new release using these buildpacks.
$ git push heroku main
Enumerating objects: 2, done.
Counting objects: 100% (2/2), done.
Delta compression using up to 16 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 270 bytes | 270.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpacks:
remote:        1. https://github.com/heroku/heroku-buildpack-activestorage-preview
remote:        2. https://github.com/rails-sqlserver/heroku-buildpack-freetds
remote: -----> ActiveStorage Preview app detected
remote: -----> Installing binary dependencies for ActiveStorage Preview
remote:        Reusing cache
remote:        Downloading packages..
remote:        Installing packages.....
remote: -----> FreeTDS app detected
remote:        BIN_DIR=/tmp/codon/tmp/buildpacks/89c5ba58d4a923295058e848b2f0751fa8f4f45e/bin, ROOT_DIR=/tmp/codon/tmp/buildpacks/89c5ba58d4a923295058e848b2f0751fa8f4f45e, BUILD_DIR=/tmp/build_59bb7b24, CACHE_DIR=/tmp/codon/tmp/cache, pwd=/tmp/codon/tmp/buildpacks/89c5ba58d4a923295058e848b2f0751fa8f4f45e
remote: -----> [2022-04-25 11:59:17] FreeTDS 1.00.109 building in /tmp/build_59bb7b24
remote: -----> [2022-04-25 11:59:17] Creating .profile.d entry
remote:        configured APP env vars:
remote:          export PATH="/app/freetds/bin:/tmp/build_59bb7b24/.heroku/activestorage-preview/usr/bin:/usr/local/bin:/usr/bin:/bin"
remote:          # tiny_tds extconf.rb uses FREETDS_DIR
remote:          # https://github.com/rails-sqlserver/tiny_tds/blob/5046755ca91594003f8b3ca541d136f3ed859973/ext/tiny_tds/extconf.rb#L36-L38
remote:          export FREETDS_DIR="/app/freetds"
remote:          export LD_LIBRARY_PATH="/app/freetds/lib:/tmp/build_59bb7b24/.heroku/activestorage-preview/usr/lib/x86_64-linux-gnu:/tmp/build_59bb7b24/.heroku/activestorage-preview/usr/lib/x86_64-linux-gnu/nss"
remote:          export LD_RUN_PATH="/app/freetds/lib:/usr/local/lib"
remote:          export LIBRARY_PATH="/app/freetds/lib:/tmp/build_59bb7b24/.heroku/activestorage-preview/usr/lib/x86_64-linux-gnu:/tmp/build_59bb7b24/.heroku/activestorage-preview/usr/lib/x86_64-linux-gnu/nss"
remote:          export SYBASE="/app/freetds"
remote:        Cached files not found - downloading and unpacking...
remote: -----> [2022-04-25 11:59:18] Building FreeTDS against OpenSSL OpenSSL 1.1.1f  31 Mar 2020
remote: -----> [2022-04-25 12:00:56] Testing build
remote:        Compile-time settings (established with the "configure" script)
remote:                                    Version: freetds v1.00.109
remote:                     freetds.conf directory: /app/freetds/etc
remote:             MS db-lib source compatibility: no
remote:                Sybase binary compatibility: no
remote:                              Thread safety: yes
remote:                              iconv library: yes
remote:                                TDS version: 7.3
remote:                                      iODBC: no
remote:                                   unixodbc: no
remote:                      SSPI "trusted" logins: no
remote:                                   Kerberos: no
remote:                                    OpenSSL: yes
remote:                                     GnuTLS: no
remote:                                       MARS: no
remote: -----> [2022-04-25 12:00:56] Caching FreeTDS installation
remote:        Unpacking cached files...
remote:        configured BUILDPACK env vars:
remote:        declare -x FREETDS_DIR="/tmp/build_59bb7b24/freetds"
remote:        declare -x LD_LIBRARY_PATH="/tmp/build_59bb7b24/freetds/lib:/app/freetds/lib:/tmp/build_59bb7b24/.heroku/activestorage-preview/usr/lib/x86_64-linux-gnu:/tmp/build_59bb7b24/.heroku/activestorage-preview/usr/lib/x86_64-linux-gnu/nss"
remote:        declare -x LIBRARY_PATH="/tmp/build_59bb7b24/freetds/lib:/app/freetds/lib:/tmp/build_59bb7b24/.heroku/activestorage-preview/usr/lib/x86_64-linux-gnu:/tmp/build_59bb7b24/.heroku/activestorage-preview/usr/lib/x86_64-linux-gnu/nss"
remote:        declare -x PATH="/tmp/build_59bb7b24/freetds/bin:/app/freetds/bin:/tmp/build_59bb7b24/.heroku/activestorage-preview/usr/bin:/usr/local/bin:/usr/bin:/bin"
remote:        declare -x SYBASE="/app/freetds"
remote:        Install of FreeTDS 1.00.109 complete
remote:        END Running script: compile
remote: -----> Discovering process types
remote:        Procfile declares types -> (none)
remote:
remote: -----> Compressing...
remote:        Done: 55.4M
remote: -----> Launching...
remote:        Released v5
remote:        https://warm-spire-40708.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/warm-spire-40708.git
   78d310e..5439868  main -> main
⛄️ 3.1.2 🚀 /tmp/3ce01b21867258f6d576c61710222b89 (main)
$ heroku run which ffmpeg
Running which ffmpeg on ⬢ warm-spire-40708... up, run.7308 (Free)

Note that before adding this buildpack which ffmpeg returns a result, after adding this buildpack it does not.

bf4 commented 1 year ago

Sorry that I missed this. @joshuaclayton Did you want to add that commit here?