diwu86
diwu86

Reputation: 11

After capistrano deploy, there is no git repo in current path

I am deploying our rack app using capistrano 3. We can deploy branches as we expect. However after deployment, when I login to server in current folder with all the codes, I don't see .git. Even I git init, the next time I deploy, it will get lost again. Is there anyway I can keep .git and track which branch we are deploying? Thanks

Upvotes: 1

Views: 722

Answers (1)

Matt Brictson
Matt Brictson

Reputation: 11082

The current directory is not a git working copy. Capistrano purposely does not include the .git directory.

The actual git repository can be found in the repo directory that is alongside the current directory, but I don't think that is what you are asking for. It sounds like you want to be able to figure out what branch or SHA was used to deploy the contents of current.

Also alongside current should be a file named revisions.log. If you tail it you can see the most recent releases, including the branch, SHA, and user that performed the release:

$ tail -n 3 revisions.log 
Branch master (at 609bf349776b24f85f85b1950b92314b2d8f3bdc) deployed as release 20170927161115 by mbrictson
Branch master (at 6a77bde58a2de42428b44da669c8f01475d6cd46) deployed as release 20171107004019 by mbrictson
Branch master (at 6d0395ca4067180e0d76735c36b6852691b360ea) deployed as release 20171107011743 by mbrictson

Alternatively, you could write a custom Capistrano task to write the branch to a special file. For example:

desc "Write the branch to a .branch file in the release that was deployed"
task :write_branch do
  on release_roles(:all) do
    within release_path do
      execute :echo, "#{fetch(:branch)} > .branch"
    end
  end
end

after "deploy:updating", "write_branch"

Upvotes: 2

Related Questions