R
Railwayβ€’3y ago
macwilko

Connecting to the rails console with railway CLI

I'm using the Planetscale database (MySQL). Since moving to nix packs from Heroku buildpacks, I had to add some additional changes to the project, including some dependencies. Whilst the project itself builds and runs fine, I'm unable to boot up the Rails console due to an SSL error. In the database.yml I use the following:
production:
<<: *default
username: <%= ENV.fetch("DB_USERNAME") %>
host: <%= ENV.fetch("DB_HOST") %>
password: <%= ENV.fetch("DB_PASSWORD") %>
ssl_mode: verify_identity
sslca: /etc/ssl/certs/ca-certificates.crt
production:
<<: *default
username: <%= ENV.fetch("DB_USERNAME") %>
host: <%= ENV.fetch("DB_HOST") %>
password: <%= ENV.fetch("DB_PASSWORD") %>
ssl_mode: verify_identity
sslca: /etc/ssl/certs/ca-certificates.crt
The SSL Mode is verify_idenity and loads the CA.
Matts-Workhorse:zen-api wilko$ railway run rails c
:heavy_check_mark: Service: zen-api
Loading production environment (Rails 6.1.5)
3.0.0 :001 > test = User.first
/Users/wilko/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.5/lib/active_record/connection_adapters/mysql2_adapter.rb:45:in `rescue in new_client': SSL connection error: SSL_CTX_set_default_verify_paths failed (ActiveRecord::ConnectionNotEstablished)
/Users/wilko/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:95:in `connect': SSL connection error: SSL_CTX_set_default_verify_paths failed (Mysql2::Error::ConnectionError)
Matts-Workhorse:zen-api wilko$ railway run rails c
:heavy_check_mark: Service: zen-api
Loading production environment (Rails 6.1.5)
3.0.0 :001 > test = User.first
/Users/wilko/.rvm/gems/ruby-3.0.0/gems/activerecord-6.1.5/lib/active_record/connection_adapters/mysql2_adapter.rb:45:in `rescue in new_client': SSL connection error: SSL_CTX_set_default_verify_paths failed (ActiveRecord::ConnectionNotEstablished)
/Users/wilko/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:95:in `connect': SSL connection error: SSL_CTX_set_default_verify_paths failed (Mysql2::Error::ConnectionError)
I'm wondering if there's some issue using the CA file when executing the railway run command?
7 Replies
macwilko
macwilkoOPβ€’3y ago
oo, I think i have a solution on macOS the ca is in a different location
/etc/ssl/cert.pem
/etc/ssl/cert.pem
I've changed database.yml to include a ENV variable for the path, and I think if I try run
SSL_CA_PATH="/etc/ssl/cert.pem" railway run rails c
SSL_CA_PATH="/etc/ssl/cert.pem" railway run rails c
Is there a way to execute
railway run
railway run
with some environment variables set? ok! I fixed this:!!!
railway run env SSL_CA_PATH="/etc/ssl/cert.pem" rails c
railway run env SSL_CA_PATH="/etc/ssl/cert.pem" rails c
so this is needed to run locally on macOS
JustJake
JustJakeβ€’3y ago
You could add this to railway itself then use railway run as your local runner railway run rails c
macwilko
macwilkoOPβ€’3y ago
Thanks Jake! How do I add this to railway itself?
JustJake
JustJakeβ€’3y ago
SSL_CA_PATH="/etc/ssl/cert.pem" Slam that into Variables for your service! And, if it's different for each person, you can change it across environments πŸ˜„
macwilko
macwilkoOPβ€’3y ago
Ohh! Yes it will be different depending on the OS the person uses I think
JustJake
JustJakeβ€’3y ago
mhm. Hence why we have those environments
Tair Asim
Tair Asimβ€’2y ago
is it expected that rails console does not have shared variables exposed? for example, I am sharing postgres shared variables, getting into console and they're empty. The app works fine tho otherwise.
Want results from more Discord servers?
Add your server