mina-deploy / mina

Blazing fast deployer and server automation tool
https://rubygems.org/gems/mina
Other
4.35k stars 490 forks source link

run :local deletes local files and directories #489

Closed KjellMorgenstern closed 7 years ago

KjellMorgenstern commented 7 years ago

I tried using

run :local do
 # something
end

within the deploy scripts. (in the "deploy do ... end" block, as in the deploy.rb example). This will delete the local .git directory. While the comment in the example deploy.rb states that 'run :local' should be used before or after, not during, I still wish there was some kind of protection against this.

Also, lets say we have a task that does local operations, how would the task to be protected from being called within the deploy script? I tried that as well, and it also deleted the local .git directory.

PS: Don't worry, my repo is save. I always wanted to test if the backups work ;-)

KjellMorgenstern commented 7 years ago

One minimal taks to reproduce the issue:

desc "Deploys the current version to the server. Not!"
task :deploy do
  deploy do
    invoke :'git:clone'
    invoke :'deploy:cleanup'
    # uncommenting the line below might delete stuff on your local machine. 
    # The deletion will be triggered with the deploy:cleanup command above. You have been warned.
    #run :local do
      command 'ls .git'
    end
  end
end

And a quick, not yet really verified workaround:

desc "Deploys the current version to the server."
task :deploy do
  deploy do
    run :remote do
      invoke :'git:clone'
      invoke :'deploy:cleanup'
    end
    run :local do
      command 'ls .git'
    end
  end
end
kuboon commented 7 years ago

I write run(:local) block outside of deploy block (as in this comment-outed line https://github.com/mina-deploy/mina/blob/master/data/deploy.rb#L66) and it works fine.

d4be4st commented 7 years ago

what @kuboon said.

Also you could do a mina deploy -s to see what exacly is being run

KjellMorgenstern commented 7 years ago

I know that the expected usage is to have the run(:local) block outside of the deploy. But failing to do so is possibly dangerous to the unaware developer. My idea is more aiming at modifying mina to throw an error in case of the described misuse of run(:local). Would it be helpful to directly check wether 'run' calls are nested? Or maybe a semaphore can be added that directly prevents run(:local) calls while in the deploy block.

PS: My original use case for this was to copy over some secrets before the last deploy steps, but after the git clone. Solution was to copy the secrets first (call scp locally), then deploy and create symlinks remotely. This way remote and local steps don't need to be nested.