git post-receive hook not running bundle install - ruby-on-rails

I am having trouble running the post-receive hook as follows:
#!/bin/sh
unset $(git rev-parse --local-env-vars)
cd ~/commodity
git pull origin master
bundle install
bundle exec rake assets:precompile
thin restart
I am pushing from local to remote and I am getting this error:
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 319 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: From /var/www/html/test
remote: * branch master -> FETCH_HEAD
remote: Updating a06129c..c3c3da3
remote: hooks/post-receive: line 19: bundle: command not found
remote: hooks/post-receive: line 20: bundle: command not found
remote: hooks/post-receive: line 21: thin: command not found
error: cannot run hooks/post-receive: No such file or directory
When I clone my repository on the server and push, the hook runs and everything is great.
Any ideas why the push wont trigger the bundle commands when pushing from my local machine?
Thanks!

Try to add this line to your post-receive hook (at least before your first bundle ... call):
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
On Unix systems, rvm adds this line automatically to the ~/.bash_profile. In any none-bash contexts (crontab, git hooks) you have to add it manually.

Related

Heroku Deploy Error: No Default Language

I am trying to push some ruby code with git and keep getting stopped part way through. Here is my setup and error I get..
root#slacker:~/ruby# git remote -v
heroku https://git.heroku.com/warm-woodland-27175.git (fetch)
heroku https://git.heroku.com/warm-woodland-27175.git (push)
root#slacker:~/ruby# ls
config.ru myapp.rb
root#slacker:~/ruby# git push heroku master
Counting objects: 4, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 398 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: ! No default language could be detected for this app.
remote: HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
remote: See https://devcenter.heroku.com/articles/buildpacks
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to warm-woodland-27175.
remote:
To https://git.heroku.com/warm-woodland-27175.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/warm-woodland- 27175.git'
root#slacker:~/ruby#
I am still trying to understand the ins and outs of git but I am pretty lost as to why git doesn't recognize the file extensions in my compilation folder. I thought that was how it fetched what language to use, .rb .pl etc... Any help would be much appreciated.
I had this error when trying to deploy my Sinatra app to Heroku.
heroku buildpacks:set heroku/ruby
I read https://devcenter.heroku.com/articles/buildpacks which helped me finish the solution.
But I started with https://devcenter.heroku.com/articles/rack
which helped me understand the files that you need to add such as the Gemfile etc. Make sure you do the bundle install.
Make sure you committed your changes after you added the Gemfile, etc. So
git add .
or whatever you need to do it then commit
git commit -m "Added files for Heroku deployment"
or change the message as you want. and then can you deploy using
git push heroku master
Now I have my site running using heroku
If I am missing something that you need, just ask in comments so I can clarify.
I had the same issue when I was trying to deploy to Heroku with Ruby Sinatra. The issue in my case was that I'm brand new to Ruby and Sinatra and didn't know anything about the gems and bundling.
I literally only had my app.rb file in the folder.
I took the following steps, based on some guides 1 I read:
If my app is called app.rb, create a file called config.ru:
require './hello'
run Sinatra::Application
Create a file called Gemfile:
source 'https://rubygems.org'
gem 'sinatra'
Then I found this article that reminded me that I need to run bundle install.
Then I add these files to my git, pushed it, and mine is working!

bundle install not running from my post-update hook

I've setup a post-update hook for my project. I have a bare repository (/var/git/myproject) which I push to, and a live repository (/var/www/myproject) where my app is running. I also included bundle install and bundle exec rake db:migrate to install gems and update db.
Below is my post-update hook
#!/bin/bash
echo "Pulling changes into Live..."
cd /var/www/myproject || exit
unset GIT_DIR
git pull origin master
# check if ruby app
if [ -f /var/www/myproject/Gemfile ];
then
echo " Ruby app detected..."
bundle install --without development test
bundle exec rake db:migrate # migrate database
fi
exec git-update-server-info
When I push my changes though I get the following message (notice the "bundle command not found" error):
martyn#localhost:~/www/myproject$ git push -u origin master
martyn#192.168.0.100's password:
Counting objects: 832, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (783/783), done.
Writing objects: 100% (832/832), 487.70 KiB, done.
Total 832 (delta 434), reused 0 (delta 0)
remote: Pulling changes into Live...
remote: From /var/git/myproject
remote: * branch master -> FETCH_HEAD
remote: Ruby app detected...
remote: hooks/post-update: line 13: bundle: command not found
remote: hooks/post-update: line 14: bundle: command not found
To 192.168.24.100:/var/git/myproject.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
Why is bundle not running? I cd to the live app directory in the script. When I'm in terminal myself and I cd to the live directory and run bundle install it works so bundle is there.
Your hook shell ins't the same than the one you logged in (and which has the proper PATH)
You can try using at the beginning your your hook script:
#!/bin/bash -l
(See this answer
The -l parameter executes the command in a login shell, which means that it inherits your path and other settings from your shell profile.
)
Or you can make sure your script gets the same environment than your current session, by adding in the first lines of your hook:
$ source $HOME/.bash_profile # single user RVM setup
$ source /etc/profile # multi user RVM setup
Or (final alternative) you can add (before calling bundle) (for a single-user rvm installation)
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

git push heroku master will not recognize my Gemfile.lock file

My first time pushing to Heroku using Git and I'm getting the error message: Gemfile.lock is required. Please run "bundle install" locally and commit your Gemfile.lock.
I have ran bundle install, added the files to the git repo, commited the changes. See the Gemfile.lock in both the repository and my directory but when I run the command git push heroku master it consistently throws that error.
What am I doing wrong:
Here is the git repo on my PC
$git ls-files
.bundle/config
.gitignore
.rspec
Gemfile
Gemfile.lock
README
Rakefile
app/assets/images/rails.png
app/assets/javascripts/application.js
app/assets/stylesheets/application.css
..<snip>..
Here is the git status of the repo.
$git status
# On branch ch_ruby_intro
# Your branch is ahead of 'origin/ch_ruby_intro' by 6 commits.
#
nothing to commit (working directory clean)
Error when I try to deploy.
$git push heroku master
Counting objects: 239, done.
Compressing objects: 100% (140/140), done.
Writing objects: 100% (239/239), 50.30 KiB, done.
Total 239 (delta 74), reused 215 (delta 67)
-----> Heroku receiving push
-----> Ruby/Rails app detected
!
! Gemfile.lock is required. Please run "bundle install" locally
! and commit your Gemfile.lock.
!
! Heroku push rejected, failed to compile Ruby/rails app
Why is it not seeing the Gemfile.lock file?
Might it be that you're committing to the wrong branch? You're pushing master and committing to ch_ruby_intro.

Invalid path in Heroku

Everytime I try to deploy my rails app onto heroku it says
Michael$ heroku create
Creating stormy-window-812..... done, stack is bamboo-mri-1.9.2
http://stormy-window-812.heroku.com/ | git#heroku.com:stormy-window-812.git
Michael$ git push heroku master
! Invalid path.
! Syntax is: git#heroku.com:.git where is your app's name
fatal: The remote end hung up unexpectedly
I'm not sure what's wrong. I do a normal heroku create and my git is working for github to load code. Is there something I'm missing? The path seems to be the right format so I don't know that the problem is.
Your .git/config is borked.
Ensure that the remote for heroku points to:
git#heroku.com:stormy-window-812.git
There must be a bit of misstep somewhere in your process, I created a sample app, using the following commands - hopefully this will help you identify where things aren't going right.
Just the list of commands:
$ rails new sample_app
$ cd sample_app/
$ git init
$ git add .
$ git commit -m "Initial commit"
$ heroku create
$ git push heroku master
$ heroku open
And the commands, with some truncated output:
$ rails new sample_app
create
create README
create Rakefile
create config.ru
create .gitignore
# ..snip..
$ cd sample_app/
$ git init
Initialized empty Git repository in /sample_app/.git/
$ git add .
$ git commit -m "Initial commit"
[master (root-commit) 487a313] Initial commit
37 files changed, 1138 insertions(+), 0 deletions(-)
create mode 100644 .gitignore
create mode 100644 Gemfile
create mode 100644 Gemfile.lock
create mode 100644 README
# ..snip..
$ heroku create
$ git push heroku master
Counting objects: 63, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (47/47), done.
Writing objects: 100% (63/63), 24.81 KiB, done.
Total 63 (delta 2), reused 0 (delta 0)
-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Detected Rails is not set to serve static_assets
Installing rails3_serve_static_assets... done
-----> Configure Rails 3 to disable x-sendfile
Installing rails3_disable_x_sendfile... done
-----> Configure Rails to log to stdout
Installing rails_log_stdout... done
-----> Gemfile detected, running Bundler version 1.0.7
Unresolved dependencies detected; Installing...
Using --without development:test
Fetching source index for http://rubygems.org/
Installing rake (0.9.2)
Installing multi_json (1.0.3)
Installing activesupport (3.1.0.rc6)
# ..snip..
-----> Compiled slug size is 5.6MB
-----> Launching... done, v4
http://gentle-water-874.heroku.com deployed to Heroku
To git#heroku.com:gentle-water-874.git
* [new branch] master -> master
$ heroku open
I think you need to cd into your app directory. Then do the push again.
Also, make sure you add heroku as your remote then you can try again:
git remote add heroku git#heroku.com:appname.git
I had this problem after renaming my app. If you do
heroku rename newname
you will then have to do
git remote rm heroku
git remote add heroku git#heroku.com:newname.git
My .git/config was clearly dorked - I attempted changing to first_app as shown above (newby: RoR Tutorial chapter 1) several times. Deleting the /.git/config and doing the steps above starting with 'git init' fixed the config: url = git#heroku.com:dry-eyrie-8108.git
It also be as simple as:
$ heroku login
$ heroku git:clone -a appname ( this line right here solved it for me)
$ git add .
$ git commit -am "make it better"
$ git push heroku master
Not sure if anyone else has ran into this same misunderstanding. The error from heroku mentions the url to your app needs to meet this syntax, "https://git.heroku.com/my-app.git".
This did not work for me. However, the syntax, "my-app.herokuapp.com", resolved the error.

I get this same error everytime I try to run rake db:migrate on a cloned project from Github

Everything I clone a project on Github and then run rake db:migrate, I get this error (project name is mini_fb_demo):
$ git clone http://github.com/appoxy/mini_fb_demo.git
Initialized empty Git repository in /Users/ben/rails_projects/mini_fb_demo/.git/
remote: Counting objects: 102, done.
remote: Compressing objects: 100% (91/91), done.
remote: Total 102 (delta 24), reused 0 (delta 0)
Receiving objects: 100% (102/102), 77.94 KiB | 47 KiB/s, done.
Resolving deltas: 100% (24/24), done.
$ cd mini_fb_demo/
$ ls
README.markdown Rakefile app config db doc public script test
$ rake db:migrate
(in /Users/ben/rails_projects/mini_fb_demo)
rake aborted!
No such file or directory - /Users/ben/.minifb-demo-config.yml
What is causing this? I Thanks for reading.
Please read the wiki for the project here. You need to create the minifb-demo-config.yml file as specified there.

Resources