I'm trying to set an auth token for my gemfile to access a private git repo.
i.e.
gem 'mygem', git: "https://ENV['GITHUB_AUTH_TOKEN']:x-oauth-basic#github.com/my_account/my_repo.git", tag: "0.0.1"
I can't work out how to store this in Figaro but make it accessible to bundle when I run bundle install.
Very similar to
This question
Except that rather than having a config/heroku_env.rb I have an config/application.yml file.
I'm sure the answer is ridiculously straightforward.
I'd like to keep it in that file as it keeps everything neatly in one place, but if not I can put it somewhere specific so long as it lines up with heroku nicely.
Any ideas?
I have found one way to do it that works, it's slightly annoying in that you have to keep the credentials in two different places.
.bundle
BUNDLE_GITHUB__COM: <auth_token>:x-oauth-basic
Gemfile
gem 'mygem', git: "https://github.com/my_account/my_repo.git", tag: "0.0.1"
# Note that you don't put anything in here, bundler sorts it out automagically
And then
heroku config:set BUNDLE_GITHUB__COM=<auth_token>:x-oauth-basic
Works.
Annoying because now application.yml has different content to my heroku file. But so be it.
Update:
Better solution
Just put
BUNDLE_GITHUB__COM: <auth_token>:x-oauth-basic
into both your application.yml and heroku config.
I wish someone had documented that somewhere, would have saved me a ton of trouble...
I think you need to run
figaro heroku:set -e production
for it to set set the environment variables in your config/application.yml file as Heroku environment variables.
Related
gem 'dotenv-rails' is required in gemfile test and development environments.
.env file is saved in root
I believe variables use correct syntax; USERNAME=username
I am using Rails 5.0.4
I have not required 'dotenv-rails' anywhere, as the docs do not suggest that I need to.
When playing in the console, the only way I can access the variables is by calling, Dotenv.load in each session. Suggesting that Dotenv.load should be called somewhere in config of my app.
Add Dotenv::Railtie.load to your config/application.rb
You may also need to restart Spring.
bin/spring stop
It will restart once you run another rails command.
In case this helps anyone else:
This happened to me once. As it turns out, I was mistakenly passing RAILS_ENV=production in the environment variables, disabling it.
For me the bin/spring stop fixed the issue and I am using ruby 3.1.2 and rails 7.0.4.
In my config\environments\development.rb and config\environments\production.rb files, I set some global variables. In the example below, I have a a Redis instance that points to our cache, and a Statsd instance that points to the DataDog agent.
config.x.cache = Redis.new(url: ENV["CACHE"])
config.x.statsd = Statsd.new('localhost', 8125)
In the case of Redis, I added gem 'redis' to my gem file, ran bundle install and everything worked fine. In the case of StatsD, however, it seems that I need to also add require 'statsd' at the top of the development.rb and production.rb files in order to be able to create the instance. Of course, I also added gem 'dogstatsd-ruby' to my gem file and ran bundle install, but that didn't seem to be enough. If I don't add the require statement at the top of the config files, I get the following error when I try to run my Rails app:
uninitialized constant Statsd (NameError)
Can anyone explain why I have to add the require statement only in this particular case (StatsD), or is there is a better way to do this? Thanks!
I am trying to deploy my Rails application to a staging server with Capistrano, nginx and Puma. I am using the Figaro gem to setting ENV variables. When deploying, the standard Capistrano configuration does not look for and copy the application.yml file before deploying the app, and of course the deployment fails because of missing credentials. I have found a few Gists with a snippet to insert into the deploy.rb. These looked promising but I was insure about the before/after actions because the ones they were using, didn't match up with the actions used in my deploy.rb file. I also tried the capistrano-figaro-yml gem which seamed to copy the file but would not update the file if it was changed locally.
Is there a more standard way to trigger a copy of the application.yml file with the Capistrano deployment? Thanks
Adding set :linked_files, %w{config/application.yml} to deploy.rb got it going.
I would like to use gems 'better_errors' and 'binding_of_caller' for my debugging in rails app, but i DON'T want to include those in Gemfile. Is it possible to do? My first thought was to simply
gem install better_errors
gem install binding_of_caller
but it doesnt work, i mean installation finishes without problems, but thats it, gem doesnt seem to work at all when i run my app on localhost. Do I need some kind of config set, anybody?
but i DON'T want to include those in Gemfile. Is it possible to do?
Yes, it is possible. You can just download the respective directories in desire folder (ex. lib) and add that gem class in your initializer so it will be loaded at the time of starting. Configuration varies as per gem.
My first thought was to simply .... but it doesnt work,
Ofcourse, it wont. How can your rails app magically detects without knowing it that you have better way to show error. It is simply saying like you have cancer formula and doctors automatically applied that formula to there patient without you telling them. There should be some commucaition between two parties rails-app and gem so they can coordinate and work better.
Do I need some kind of config set, anybody?
Yes, explained above.
i dont want to force those gems on my coworkers. KRUKUSA any more details? // said in comment
Yes, including this gems in your rails app can do this job. This extension will be available automatically to your worked. (no force applied :P)
it looks like all you want to not show those gems to other co-worker, if so, you can use this trick with git.
To achieve this thing, first simply add the gems in your gemfile, run bundle and then make it untrackable with git. You can put Gemfile and Gemfile.lock in your .gitignore file. or you can add the first add the gems and mark it ignore with below command. Read more here
git update-index --assume-unchanged Gemfile Gemfile.lock
Another possibility would be to create your own environment and use it accordingly.
Have your own configuration for myenv:
$ cp config/environments/{development,myenv}.rb
In config/database.yml, add the environment myenv and use the same config as development:
development: &development
<rest of the code you have on config/databases.yml>
...
myenv:
<< *development
In Gemfile add your custom gems to use on your mydev group:
group :myenv do
gem 'better_errors'
gem 'binder_of_caller'
end
Run rails and rake with RAILS_ENV like this: RAILS_ENV=myenv rails c
The advantage of this approach is that you still get the updates from Gemfile from the repo, and if you need to add a gem in the Gemfile for everybody to see, you still can.
Also, nobody will see the gems you installed inside the myenv group in your Gemfile.
I have a couple static pages which when running locally work as localhost:3000/foo.html, but this doesn't work once uploaded to heroku.
I tried adding the following to the routes.rb file:
match '/foo', :to => redirect('/public/foo.html')
but that doesn't seem to work, it redirects me to foobar.com/public/foo.html, but still finds nothing there.
Per this article, you will need to tell Rails to serve static assets itself with:
config.serve_static_assets = true
in your config/environments/production.rb
Alternatively you can add the rails_12factor gem to the production group:
gem 'rails_12factor', group: :production
according to Heroku. This will also redirect log to stdout as also required by Heroku.
This baffled me for hours, but here's another potential solution. For some reason, I could generate documentation into /public/docs, but the documentation would not load, even immediately after I generated it. I would run a Heroku bash console, generate the documentation, exit, then re-run Heroku bash only to find that /public no longer contained my docs folder.
So, the only solution I found was to include the documentation in the Git repository. That was the only way that Heroku persisted /public/docs across deploys and bash instances.
I have no idea why this is... I opened a support ticket with Heroku and am awaiting a response.