Excluding files from being deployed with Capistrano while still under version control with Git
Asked Answered
J

3

10

I want to start testing the JavaScript in my Rails apps with qUnit and I'm wondering how to keep the test JavaScript and test runner HTML page under version control (I'm using Git, of course) but keep them off the production server when I deploy the app with Capistrano. My first thought is to let Capistrano send all the code over as usual including the test files, and write a task to delete them at the end of the deployment process. This seems like sort of a hack, though. Is there a cleaner way to tell Capistrano to ignore certain parts of the repository when deploying?

Jesusa answered 1/4, 2010 at 5:11 Comment(0)
B
5

As of August 30th, 2013, you can simply create a .gitattributes file and export-ignore the files/folders of your choice.

features/ export-ignore
spec/     export-ignore

Reference: https://github.com/capistrano/capistrano/pull/626

Bokbokhara answered 18/11, 2014 at 0:52 Comment(0)
M
7

There are many ways to accomplish this, you can keep your tests in a test branch of the app like VonC suggested, but that would mean that you would make all your changes in your main branch and then sync it to your test branch. (Not without its merits, but sometimes a pain)

You can use the .gitignore file to your directory.

Any file that you add to this will not be added to your repository. Since capistrano just pulls and posts from your repository, not having the files included will keep them off your production server.

Last but not least, if you want the test files in your main repository for version control, you can add a recipe to your config/deploy.rb file.. something like:

desc "Remove Test Files"  
    task :remove_test_files , :roles => :web do
      sudo %{rm -f #{current_path}/public/javascripts/testfile.js}
      sudo %{rm -f #{current_path}/public/javascripts/anothertestfile.js}
    end

after 'deploy:remove_test_files'

And specify the files you want to remove, this will remove any files you want when you deploy. :)

Any of the above will work. Pick the method that works for you.

Milla answered 1/4, 2010 at 15:39 Comment(3)
I didn't see your answer at the time. +1Stupefy
@Stupefy & Dustin - How would you recommend handling if your cap files are in your deploy repo but you do not want them on your production server? They would be deployed to releases/variable_directory_namePaynter
@ChristopherIckes - Personally I don't keep my deploy.rb scripts in my production repo. Again, if you need it for version control I would keep them out of the master branch so they are not deployed. i.e. I would have my deploy scripts in a "deploy" branch for version control and then use that branch to execute "cap deploy". My deploy scripts pull the master from github, so having the deploy.rb in a different branch should work.Milla
B
5

As of August 30th, 2013, you can simply create a .gitattributes file and export-ignore the files/folders of your choice.

features/ export-ignore
spec/     export-ignore

Reference: https://github.com/capistrano/capistrano/pull/626

Bokbokhara answered 18/11, 2014 at 0:52 Comment(0)
S
0

You could have those tests in a test branch (on which you merge your main branch before any test)

That way, when you ask Capistrano to deploy what is on your main branch, no test of any sort is ever included.

Stupefy answered 1/4, 2010 at 6:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.