A follow up to Disable irb autocomplete
I would like to disable IRB on Heroku, e.g. having an .irbrc with:
IRB.conf[:USE_AUTOCOMPLETE] = false
In the home directory of my heroku dyno/server
How can I do it?
If you don't want to update the .irbrc on Heroku because that would affect others' usage of it, you can also disable autocomplete on Heroku just for yourself via the command line when you open it. The quotes are critical, or you will get a Thor::InvocationError:
heroku run "rails console -- --noautocomplete"
Your application's root directory ends up being the application's user's home directory at Heroku so you could put a .irbrc in your application's root directory. So add your .irbrc with IRB.conf[:USE_AUTOCOMPLETE] = false to your app's root directory so that it looks like this:
$ cd your_app_root_directory
$ ls -1A
.git/
...
.irbrc # <-----------------
...
Gemfile
Gemfile.lock
Procfile
README.md
Rakefile
app/
bin/
config/
config.ru
db/
...
Then, once you push everything up to Heroku, heroku run console will use that .irbrc.
Create an .irbrc file with this content:
IRB.conf[:USE_AUTOCOMPLETE] = false
IRB.conf[:PROMPT_MODE] = :SIMPLE
Related
I am trying to perform a database backup as part of a Capistrano (v3) deployment script (for a NON-Rails app).
The script works fine -- if I hard-code database config into it.
Now I want to load in the database config from a .env file. On my local machine, my .env file (in the repo root next to the Capfile) reads as follows:
DB_NAME='local_name'
DB_USER='local_user'
DB_PASSWORD='local_pw'
DB_HOST='127.0.0.1'
On the server, the .env file (which Capistrano has placed in the shared folder & symlined to from the current folder) reads as follows:
DB_NAME='dev_name'
DB_USER='dev_user'
DB_PASSWORD='dev_pw'
DB_HOST='127.0.0.1'
However, when running cap deploy, I get the following:
INFO [292e2535] Running /usr/bin/env mysqldump -u local_user --password='local_pw' --databases local_name -h 127.0.0.1 | bzip2 -9 > /var/www/vhosts/xxxxx/backups/database_local_name_2014-05-29_22:52:07.sql.bz2 on <server>
I.e. it's using my local .env file, when actually I'd like it to load the .env file that is present on the server. I do not want all of my team to have to manage a separate .env.production file if at all possible!
The relevant portion of my script is as follows (using the Dotenv gem):
require 'dotenv'
Dotenv.load '.env'
username, password, database, host = ENV['DB_USER'], ENV['DB_PASSWORD'], ENV['DB_NAME'], ENV['DB_HOST']
Any help would be greatly appreciated!
You can use the Dotenv::Parser.call(string). I am using with Capistrano 2.14 (this is older version!)
desc <<-desc
ENV test
desc
task :test do
text = capture "cat #{shared_path}/.env"
ENV2 = Dotenv::Parser.call(text)
puts ENV2['DB_NAME']
end
Under Capistrano 3 I need fixed KrisztiƔn Ferenczi's answer
task :load_remote_environment do
on roles(:app) do
set :default_environment, Dotenv::Parser.call(capture("cat #{shared_path}/.env"))
end
end
after 'deploy:set_current_revision', 'load_remote_environment'
In the Capfile
require 'dotenv'
I have currently my octopress blog up and running on my digital ocean droplet and everything works fine. But it is in the root folder of the droplet and I want to move it to a blog folder. Is that just moving all content to that subfolder, or is there more work to do to get this done to be aware of?
According to the Octopress documentation, if you are deploying in a subdirectory you'll need to update the following files:
_config.yml
config.rb
Rakefile
If you're deploying to a subdirectory on your site, or if you're using
Github's project pages, make sure you set up your urls correctly in
your configs. You can do this almost automatically:
rake set_root_dir[your/path]
# To go back to publishing to the document root
rake set_root_dir[/] Then update your _config.yml and Rakefile as follows:
# _config.yml
url: http://yoursite.com/your/path
# Rakefile (if deploying with rsync)
document_root = "~/yoursite.com/your/path"
To manually configure deployment to a subdirectory, you'll change _config.yml, > config.rb and Rakefile. Here's an example for deploying a site to the /awesome
subdirectory:
# _config.yml
destination: public/awesome
url: http://example.com/awesome
subscribe_rss: /awesome/atom.xml
root: /awesome
# config.rb - for Compass & Sass
http_path = "/awesome"
http_images_path = "/awesome/images"
http_fonts_path = "/awesome/fonts"
css_dir = "public/awesome/stylesheets"
# Rakefile
public_dir = "public/awesome"
# If deploying with rsync, update your Rakefile path
document_root = "~/yoursite.com/awesome"
source: http://octopress.org/docs/deploying/subdir/
I just started a new app and I was able to push it to Heroku, But I it seems, that I can't access the console.
The command, that I am running is:
heroku run console --app myappname
What I get, is:
Running `console` attached to terminal... up, run.3951 Usage: rails
new APP_PATH [options]
Options: -r, [--ruby=PATH] # Path to the Ruby binary of
your choice
# Default: /app/vendor/ruby-1.9.3/bin/ruby -b, [--builder=BUILDER] #
Path to a application builder (can be a filesystem path or URL) -m,
[--template=TEMPLATE] # Path to an application template (can be a
filesystem path or URL)
[--skip-gemfile] # Don't create a Gemfile
[--skip-bundle] # Don't run bundle install -G, [--skip-git] # Skip Git ignores and keeps -O,
[--skip-active-record] # Skip Active Record files -S,
[--skip-sprockets] # Skip Sprockets files -d,
[--database=DATABASE] # Preconfigure for selected database
(options:
mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
# Default: sqlite3 -j, [--javascript=JAVASCRIPT] # Preconfigure for selected JavaScript
library
# Default: jquery -J, [--skip-javascript] # Skip JavaScript files
[--dev] # Setup the application with Gemfile pointing to your Rails checkout
[--edge] # Setup the application with Gemfile pointing to Rails repository -T, [--skip-test-unit] # Skip
Test::Unit files
[--old-style-hash] # Force using old style hash (:foo = 'bar') on Ruby >= 1.9
Runtime options: -f, [--force] # Overwrite files that already
exist -p, [--pretend] # Run but do not make any changes -q,
[--quiet] # Suppress status output -s, [--skip] # Skip files
that already exist
Rails options: -h, [--help] # Show this help message and quit
-v, [--version] # Show Rails version number and quit
Description:
The 'rails new' command creates a new Rails application with a default
directory structure and configuration at the path you specify.
You can specify extra command-line arguments to be used every time
'rails new' runs in the .railsrc configuration file in your home directory.
Note that the arguments specified in the .railsrc file don't affect the
defaults values shown above in this help message.
Example:
rails new ~/Code/Ruby/weblog
This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
See the README in the newly created application to get going.
I know, that the application name is correct, as I just pushed it and it is loaded.
When I look at the logs on Heroku for the moment, when I tried to hit the console, I see following:
2013-07-01T16:21:58.780979+00:00 heroku[api]: Starting process with command `bundle exec rails console` by mzaragoza#myemail.com
2013-07-01T16:22:09.000482+00:00 heroku[run.2993]: Awaiting client
2013-07-01T16:22:09.055474+00:00 heroku[run.2993]: Starting process with command `bundle exec rails console`
2013-07-01T16:22:10.342966+00:00 heroku[run.2993]: State changed from starting to up
2013-07-01T16:22:13.870963+00:00 heroku[run.2993]: Process exited with status 0
2013-07-01T16:22:13.889703+00:00 heroku[run.2993]: State changed from up to complete
What about heroku run rails c? Does it make any difference if you add rails?
PS: I'm unsure if you want to access Rails' console or just a normal shell, from the comments.
The correct form is => heroku run "any rails command here"
I had this problem when I upgraded to Rails > 4.0.0. The solution is to run locally the following command rake rails:update:bin. This will generate a bin directory in the root of your application. Make sure that it is not in your .gitignore file. Commit and then push the changes to Heroku.
For 3.2.x apps:
This also just happened to me when I removed script/rails from my repo and pushed to Heroku. Reverting the commit and pushing that change made things work again.
I have multiple users using a CLI app on the same system. In order to use a unreleased patch, the Gemfile points to a specific commit on github of the grit gem. The app has a Gemfile.lock. All users have the same $GEM_HOME and $GEM_PATH locations set.
Now, for all but one user 'cd app; bundle show grit' shows a path like this '$GEM_HOME/bundler/gems/grit-35b71d599549' (which exists cuz I ran bundle install). But for the odd-ball, 'cd app; bundle show grit' shows a path like this '/nfs/home_dirs/odd-ball/.bundler/ruby/2.0.0/grit-35b71d599549' (which doesn't exist). A Bundler::GitError is raised for this user.
I have looked for $BUNDLE_* environment variables and for ~/.bundle* configuration. I've also verified he has permissions to the $GEM_HOME/bundler/gems.
What other reasons could account for this difference?
Thanks.
I dug in and found that it came down to file permissions for this individual user. Specifically, in Bundler.requires_sudo?:
def requires_sudo?
...
# if any directory is not writable, we need sudo
dirs = [path, bin_dir] | Dir[path.join('*')]
sudo_needed = dirs.find{|d| !File.writable?(d) }
...
end
This user was not in the group allowed to write to "#{path}/lib". And I'm assuming that when Bundler.requires_sudo? returns true, bundler will divert install_path to the users home dir.
I've just loaded up a static app to Heroku using this tutorial and everything works quite well, except my images aren't showing up. When the same site is hosted on my own server as a plain static site (not through Heroku), all of the assets load up without a problem.
Currently, I have a Gemfile, Gemfile.lock, app.rb, config.ru and public (static site directory) in my repository that I'm loading to Heroku through git push heroku master to push to Heroku.
My images are in public/img and even the assets directly referenced from html aren't showing up. When I use firebug lite in Chrome to check the asset directory, it seems as though the image files are there, but they don't seem to have the image data (from what I could tell).
I do not have any further ruby/rails files. Should I have a production.rb file somewhere? Am I missing out on something?
Currently, my setup on Heroku is the free package. Will I need to upgrade to a paid package to see my assets (I only have 2MB of assets)? I've tried creating an "assets" directory inside the "public" directory and placing the img directory in there, but still no luck.
Here is my config.ru
use Rack::Static,
:urls => ["/img", "/js", "/css"],
:root => "public"
run lambda { |env|
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
File.open('public/index.html', File::RDONLY)
]
}
To diagnose issues like this where you believe the file contents on your dyno don't match the ones in your source, use heroku run bash to login into a remote, on-off dyno. This will drop you into a bash shell where you can explore the file system as seen by your dyno (although the dyno your shell is attached to is not the one actively serving your requests it will have the same filesystem contents).
$ heroku run bash
Running `bash` attached to terminal... up, run.4065
~ $ ls
pubic Gemfile Gemfile.lock app.rb config.ru
~ $ cd public/img
~/public/img $ ls -l
total 40
-rw------- 1 u36831 36831 2743 2013-02-15 18:54 facebook-1652d049.png
-rw------- 1 u36831 36831 2291 2013-02-15 18:54 feed-e8d78a2f.png
From here you should be able to see:
If the image files even exist on the dyno
If their contents are what you expect (do the file sizes match what you see in your local env?)