Ruby version mismatch

I’ve spent a couple hours trying to get my first deploy of an existing rails app (running on Heroku) to deploy on Fly.io, but seem to keep getting stuck:

My cmd in the fly.toml is just

cmd = 'bin/rails server -p $PORT -e $RAILS_ENV'

(same as the Procfile for heroku)

but it just fails with:

Your Ruby version is 2.7.0, but your Gemfile specified 3.1.0

I switched buildpacks to use


[build]
  builder = "paketobuildpacks/builder:full"
  buildpacks = ["docker://gcr.io/paketo-buildpacks/mri:0.6.0", "gcr.io/paketo-buildpacks/ruby"]

and now ruby 3.1.0 and bundle install work, but the build process doesn’t have access to secrets or env vars now, so the builds fail:

Paketo Rails Assets Buildpack 0.4.1
  Executing build process
    Running 'bundle exec rails assets:precompile assets:clean'
failed to execute bundle exec output:
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
rails aborted!
KeyError: key not found: "MY_ENV_VAR"

I think my real issue is that the builder and buildpacks don’t have access to the env vars or secrets, so I’ll need to find a way to inject them into the [build.args section]


[build]
  builder = "paketobuildpacks/builder:full"
  buildpacks = ["docker://gcr.io/paketo-buildpacks/mri:0.6.0", "gcr.io/paketo-buildpacks/ruby"]
  [build.args]
    MY_ENV_VAR="1234567890"

[env]
  MY_ENV_VAR = "1234567890"

Finally got a build to deploy, just had to seed the build.args with copies of blank env vars (only used at runtime):

build]
  builder = "paketobuildpacks/builder:full"
  buildpacks = ["docker://gcr.io/paketo-buildpacks/mri:0.6.0", "gcr.io/paketo-buildpacks/ruby"]
  [build.args]
    DATABASE_URL="sqlite:///tmp/db.sqlite3"
    CRON_PROCESS=""
    RAILS_MASTER_KEY=""
    FIREBASE_API_KEY=""
    S3_BUCKET_NAME=""
    S3_REGION=""
    SECOND_DATABASE_URL=""
    SOME_API_KEY=""
    ANOTHER_API_KEY=""
    SENTRY_DSN=""
    THIRD_API_KEY=""
    SOME_OTHER_ENV=""
    HOSTNAME=""

[env]
    DATABASE_URL="postgres://user@host:5434/dbname?ssl_mode=verify"
    CRON_PROCESS="123456789"
    RAILS_MASTER_KEY="123456789"
    FIREBASE_API_KEY="123456789"
    S3_BUCKET_NAME="123456789"
    S3_REGION="123456789"
    SECOND_DATABASE_URL="123456789"
    SOME_API_KEY="123456789"
    ANOTHER_API_KEY="123456789"
    SENTRY_DSN="123456789"
    THIRD_API_KEY="123456789"
    SOME_OTHER_ENV="123456789"
    HOSTNAME="123456789"

I’m glad you got it working! Unfortunately that’s the best way to handle missing secrets during a build. We deliberately don’t leak secrets to flyctl because of the security risk, and you probably don’t want connections opening to your prod db anyway.

Thank you for not passing the secrets! My build command doesn’t and shouldn’t even rely on them. Just took me a second to figure things out. Thanks!

1 Like

It’s usually a library doing sanity checks when loaded as a byproduct of building assets. fwiw this conversation gave me an idea that might help make this less of an issue Inject placeholder secrets/envs into build vars · Issue #778 · superfly/flyctl · GitHub

1 Like

I’m seeing the exact same ruby mismatch error with the heroku/buildpacks:20 buildback!

My app is deployed and running just fine, but I need to run a one-off rake process (seeding the db with data), and so I ssh in with fly ssh console (which works), then I cd app, but I can’t run anything in the bin folder of my rails project! I’m getting these confusing errors:

# bin/rails console
Your Ruby version is 2.7.0, but your Gemfile specified 3.0.2
# bin/bundle exec rails console
bundler: command not found: rails
Install missing gem executables with `bundle install`
# bundle -v
/bin/sh: 6: bundle: not found

Maybe I am just new to Docker, but how is it that my app is running just fine and yet when I SSH in the container, bundler isn’t installed, nor rails, nor the proper version of ruby? Any links to resources where I can learn more about this aspect of Docker would also be appreciated.

Or even just tips on how to run a rake db:seed task as a one-off. Thank you!

1 Like

Same problem here, I haven’t found a way to run a rails console while ssh into the app.

@password @user98 I fixed it by checking the Dockerfile.

ARG RUBY_VERSION=X.X.X